diff --git a/src/content/docs/kubernetes-pixie/kubernetes-integration/advanced-configuration/java-extensions-k8s-auto-attach.mdx b/src/content/docs/kubernetes-pixie/kubernetes-integration/advanced-configuration/java-extensions-k8s-auto-attach.mdx new file mode 100644 index 00000000000..e47f42640b3 --- /dev/null +++ b/src/content/docs/kubernetes-pixie/kubernetes-integration/advanced-configuration/java-extensions-k8s-auto-attach.mdx @@ -0,0 +1,181 @@ +--- +title: 'Add Java extensions to Kubernetes APM auto-attach' +tags: + - Integrations + - Kubernetes integration + - APM auto-attach + - Java agent + - Java extensions +metaDescription: 'Learn how to add Java extension modules when using Kubernetes APM auto-attach for enhanced Java application monitoring.' +freshnessValidatedDate: 2024-11-06 +--- + +When using [Kubernetes APM auto-attach](/docs/kubernetes-pixie/kubernetes-integration/installation/k8s-agent-operator/), you may want to add Java extension modules to enhance monitoring capabilities for specific libraries or frameworks not covered by the default Java agent instrumentation. + +This guide shows you how to create a custom Docker image with Java extensions and integrate it with Kubernetes APM auto-attach. + +## Before you begin [#before-begin] + +Before adding Java extensions, ensure you have: + +* [Kubernetes APM auto-attach](/docs/kubernetes-pixie/kubernetes-integration/installation/k8s-agent-operator/) installed and configured +* Docker installed for building custom images +* Access to a container registry (Docker Hub, ECR, GCR, etc.) +* Permission to push images to the registry +* Knowledge of which [Java extension modules](/docs/apm/agents/java-agent/instrumentation/extension-additional-instrumentation-modules/) you need + +## Overview [#overview] + +The process involves three main steps: + +1. Create a custom Docker image based on `newrelic/newrelic-java-init:latest` with your desired extensions +2. Build and push the image to your container registry +3. Update your Kubernetes instrumentation to use the new image + +## Create custom Docker image with extensions [#create-docker-image] + + + + + +### Create a Dockerfile + +Create a new `Dockerfile` that extends the original New Relic Java init image and adds your desired extensions. Here's an example using the Kotlin coroutines extension: + +```dockerfile +# Start from the original New Relic Java init image +FROM newrelic/newrelic-java-init:latest + +# Create the extensions directory in the root +RUN mkdir -p /extensions + +# Example: Add Kotlin coroutines instrumentation +# Download the latest version and extract to extensions directory +RUN VERSION=$(wget -q -O - https://api.github.com/repos/newrelic/newrelic-java-kotlin-coroutines/releases/latest | \ + awk '/tag_name/{gsub(/,|"/,"",$2);print$2}') && \ + wget -qO /tmp/kotlin-coroutines-instrumentation.zip \ + "https://github.com/newrelic/newrelic-java-kotlin-coroutines/releases/download/$VERSION/kotlin-coroutines-instrumentation-$VERSION.zip" && \ + unzip -j /tmp/kotlin-coroutines-instrumentation.zip "*.jar" -d /extensions && \ + rm /tmp/kotlin-coroutines-instrumentation.zip +``` + + + Replace the Kotlin coroutines example with the specific extensions you need. You can find available extensions in the [Java extension modules documentation](/docs/apm/agents/java-agent/instrumentation/extension-additional-instrumentation-modules/). + + + + + + +### Build the Docker image + +Build your custom image locally: + +```bash +docker build -t your-registry/{Your-Image-Name} +``` + +Replace `your-registry/{Your-Image-Name}` with your actual container registry path and image name, for example, `mycompany/newrelic-java-init-custom`. + + + + + +### Push to container registry + +Push the image to your container registry: + +```bash + docker push your-registry/{Your-Image-Name} +``` + + + + + + +## Update Kubernetes instrumentation [#update-instrumentation] + + + + + +### Modify the instrumentation resource + +Update your existing instrumentation Custom Resource (CR) to use the new image. Here's an example `instrumentation-java.yaml`: + +```yaml +apiVersion: newrelic.com/v1beta2 +kind: Instrumentation +metadata: + name: newrelic-instrumentation-java + namespace: newrelic +spec: + agent: + language: java + image: your-registry/{Your-Image-Name} + +``` + + + + + +### Apply the updated instrumentation + +Apply the updated instrumentation to your cluster: + +```bash + kubectl apply -f instrumentation-java.yaml +``` + + + + + + +### Restart affected workloads + +Restart your Java applications to pick up the new init container with extensions: + +* To restart a specific deployment: + + ```bash + # Restart a specific deployment + kubectl rollout restart deployment/my-java-deployment + ``` + +* To restart all deployments in a namespace: + + ```bash + # Or restart all deployments in a namespace + kubectl rollout restart deployments -n my-namespace + ``` + + + + + +## Troubleshooting [#troubleshooting] + +### Extensions not loading + +If extensions aren't loading: + +1. Verify the extensions directory exists in your custom image: + + ```bash + docker run --rm your-registry/{Your-Image-Name} ls -la /extensions + ``` + +2. Check file permissions ensure extension JAR files are readable. + +3. Review init container logs for any error messages during agent initialization. + + +## Additional resources [#additional-resources] + +* [Java extension modules documentation](/docs/apm/agents/java-agent/instrumentation/extension-additional-instrumentation-modules/) +* [Kubernetes APM auto-attach](/docs/kubernetes-pixie/kubernetes-integration/installation/k8s-agent-operator/) +* [Java agent configuration](/docs/apm/agents/java-agent/configuration/java-agent-configuration-config-file/) +* [Custom instrumentation for Java](/docs/apm/agents/java-agent/custom-instrumentation/java-custom-instrumentation/) \ No newline at end of file diff --git a/src/nav/kubernetes-pixie.yml b/src/nav/kubernetes-pixie.yml index b3e560e06be..a06e890db83 100644 --- a/src/nav/kubernetes-pixie.yml +++ b/src/nav/kubernetes-pixie.yml @@ -35,6 +35,8 @@ pages: path: /docs/kubernetes-pixie/kubernetes-integration/advanced-configuration/link-otel-applications-kubernetes - title: Advanced configuration pages: + - title: Add Java extensions to Kubernetes APM auto-attach + path: /docs/kubernetes-pixie/kubernetes-integration/advanced-configuration/java-extensions-k8s-auto-attach - title: Configure control plane monitoring path: /docs/kubernetes-pixie/kubernetes-integration/advanced-configuration/configure-control-plane-monitoring - title: Configure Kubernetes with a proxy