-
Notifications
You must be signed in to change notification settings - Fork 8
k8s operator example and dev docs. #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
k8s operator example and dev docs.
Ensuring our container for our autoinstrumentation distribution loads correctly using the OpenTelemetry k8s Operator
- Loading branch information
commit 9c7e653ca85d6b9f885cbf0990033013cb28c851
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | ||
| USER $APP_UID | ||
| WORKDIR /app | ||
| EXPOSE 8080 | ||
| EXPOSE 8081 | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
| ARG BUILD_CONFIGURATION=Release | ||
| WORKDIR /src | ||
| COPY ["examples/Example.AspNetCore.Mvc/Example.AspNetCore.Mvc.csproj", "examples/Example.AspNetCore.Mvc/"] | ||
| COPY ["src/Elastic.OpenTelemetry/Elastic.OpenTelemetry.csproj", "src/Elastic.OpenTelemetry/"] | ||
| COPY ["examples/ServiceDefaults/ServiceDefaults.csproj", "examples/ServiceDefaults/"] | ||
| RUN dotnet restore "examples/Example.AspNetCore.Mvc/Example.AspNetCore.Mvc.csproj" | ||
| COPY . . | ||
| WORKDIR "/src/examples/Example.AspNetCore.Mvc" | ||
| RUN dotnet build "Example.AspNetCore.Mvc.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
|
||
| FROM build AS publish | ||
| ARG BUILD_CONFIGURATION=Release | ||
| RUN dotnet publish "Example.AspNetCore.Mvc.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
|
||
| FROM base AS final | ||
| WORKDIR /app | ||
| COPY --from=publish /app/publish . | ||
| ENTRYPOINT ["dotnet", "Example.AspNetCore.Mvc.dll"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # Run Elastic Distribution of OpenTelemetry .NET on k8s | ||
|
|
||
| The following documents how to auto instrument using the OpenTelemetry k8s Operator. | ||
|
|
||
| First create a namespace for your k8s deployment: | ||
|
|
||
| ```bash | ||
| kubectl create namespace my-dotnet-ns | ||
| ``` | ||
|
|
||
| Next up we'll set our Elastic Cloud endpoint and key as k8s secrets. | ||
|
|
||
| ```bash | ||
| kubectl create secret generic elastic-otel -my-dotnet-ns \ | ||
| "--from-literal=endpoint=<cloud_endpoint>" \ | ||
| "--from-literal=apiKey=Authorization=Bearer <api_key>" | ||
| ``` | ||
|
|
||
| next create an `Instrumentation` resource by creating an [`elastic-otel-dotnet.yml`](elastic-otel-dotnet.yml) file. | ||
|
|
||
| Then apply it to create it in our namespace | ||
|
|
||
| ```bash | ||
| kubectl apply -f elastic-otel-dotnet.yml -n my-dotnet-ns | ||
| ``` | ||
|
|
||
| We then edit the namespace to make sure our Instrumentation annotations get applied always: | ||
|
|
||
| ```bash | ||
| kubectl edit namespace my-dotnet-ns | ||
| ``` | ||
| ensure the following `instrumentation` gets added under `metadata>annotations` | ||
|
|
||
| ```yml | ||
| apiVersion: v1 | ||
| kind: Namespace | ||
| metadata: | ||
| annotations: | ||
| instrumentation.opentelemetry.io/inject-dotnet: elastic-otel-dotnet | ||
| ``` | ||
|
|
||
| we can now create our pod containing our dotnet image. | ||
Mpdreamz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To add your containerized image create a new `my-dotnet-application.yml` file | ||
|
|
||
| ```yml | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: my-dotnet-application | ||
| namespace: my-dotnet-application | ||
| labels: | ||
| app: my-dotnet-application | ||
| spec: | ||
| containers: | ||
| - image: _YOUR_APPLICATIONS_DOCKER_URL_ | ||
| imagePullPolicy: Always | ||
| name: my-dotnet-application | ||
| ``` | ||
|
|
||
| We can then spin up this pod by applying the template | ||
|
|
||
| ```bash | ||
| kubectl apply -f my-dotnet-application.yml -n my-dotnet-ns | ||
| ``` | ||
|
|
||
| Once spun up we can query the logs with | ||
|
|
||
| ```bash | ||
| kubectl logs my-dotnet-application -n my-dotnet-ns | ||
| ``` | ||
|
|
||
| It should print the Elastic Distribution of OpenTelemetry .NET preamble | ||
|
|
||
| ```log | ||
| [2024-09-06 18:49:36.011][00001][------][Information] Elastic Distribution of OpenTelemetry .NET: 1.0.0-alpha.6.1 | ||
| ``` | ||
|
|
||
| TIP: you can expose this pod locally to your host using: | ||
Mpdreamz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| kubectl port-forward -n my-dotnet-ns pods/my-dotnet-application 8081:8080 | ||
| ``` | ||
|
|
||
| Here we forward the container port `8080` to your local port `8081` allowing you to browse your application. | ||
|
|
||
|
|
||
|
|
||
|
|
||
| ### Use a local image as pod image | ||
|
|
||
| Useful when developing. | ||
|
|
||
| ```bash | ||
| docker build . -t asp-net-example -f examples/Example.AspNetCore.Mvc/Dockerfile | ||
| minikube image load asp-net-example:latest --daemon | ||
| ``` | ||
|
|
||
| This ensures minikube can resolve `asp-net-example:latest`, you can now update your | ||
| application spec section to: | ||
|
|
||
| ```yml | ||
| spec: | ||
| containers: | ||
| - image: asp-net-example:latest | ||
| imagePullPolicy: Never | ||
| name: asp-net-example | ||
| ``` | ||
|
|
||
| NOTE: make sure `imagePullPolicy` is set to `Never` | ||
Mpdreamz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ### Debug deployments | ||
|
|
||
| The `describe` command is great to validate the init-container ran and exposed | ||
| all the necessary environment variables. | ||
|
|
||
| ```bash | ||
| kubectl describe pod my-dotnet-application -n my-dotnet-ns | ||
| ``` | ||
|
|
||
| You can use `exec` to inspect the container to see if it matches your expectations. | ||
| ```log | ||
| kubectl exec my-dotnet-application -n my-dotnet-ns -- ls -la /otel-auto-instrumentation-dotnet | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| apiVersion: opentelemetry.io/v1alpha1 | ||
| kind: Instrumentation | ||
| metadata: | ||
| name: elastic-otel-dotnet | ||
| namespace: my-dotnet-application | ||
| spec: | ||
| env: | ||
| - name: OTEL_EXPORTER_OTLP_ENDPOINT | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: elastic-otel | ||
| key: endpoint | ||
| exporter: | ||
| endpoint: $OTEL_EXPORTER_OTLP_ENDPOINT | ||
| propagators: | ||
| - tracecontext | ||
| - baggage | ||
| - b3 | ||
| sampler: | ||
| type: parentbased_traceidratio | ||
| argument: "1.0" | ||
| dotnet: | ||
| image: docker.elastic.co/observability/elastic-otel-dotnet:edge | ||
| env: | ||
| - name: OTEL_EXPORTER_OTLP_HEADERS | ||
| valueFrom: | ||
| secretKeyRef: | ||
| name: elastic-otel | ||
| key: apiKey | ||
| - name: OTEL_LOG_LEVEL | ||
| value: "info" | ||
| - name: ELASTIC_OTEL_LOG_TARGETS | ||
| value: "file;stdout" | ||
| - name: OTEL_DOTNET_AUTO_LOG_DIRECTORY | ||
| value: "/otel-auto-instrumentation-dotnet" | ||
| - name: OTEL_DOTNET_AUTO_RULE_ENGINE_ENABLED | ||
| value: "false" | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| apiVersion: v1 | ||
| kind: Pod | ||
| metadata: | ||
| name: my-dotnet-application | ||
| namespace: my-dotnet-application | ||
| labels: | ||
| app: my-dotnet-application | ||
| spec: | ||
| containers: | ||
| - image: asp-net-example:latest | ||
| imagePullPolicy: Never | ||
| name: asp-net-example |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.