Adding APM Insight Java agent in Kubernetes via InitContainers
Step 1:
Create a secret for the Site24x7 license key in your application namespace.
- You can obtain the license key from your site24x7 account by navigating to Admin > Developer > Device Key.
Example:
- kubectl create secret generic app-secret --from-literal=s247licensekey='your_s247_license_key' -n petclinic
Replace app-secret, your_s247_license_key, and namespace (petclinic) with the appropriate values.
Step 2:
Create an empty volume that will be used to copy the agent files during the InitContainers process.
Example:
- volumes:
- - name: s247agent
Step 3:
Include the following InitContainers command in your helm chart/deployment YAML file.
- initContainers:
- - name: agent-copy
- image: site24x7/apminsight-javaagent:latest
- imagePullPolicy: IfNotPresent
- command: ['cp', '-r', '/opt/site24x7/.', '/home/apm']
- volumeMounts:
- - name: s247agent
- mountPath: /home/apm
Step 4:
Mount the volume created in step 2 into your application container.
Example:
- containers:
- - name: petclinic
- image: petclinic:latest
- imagePullPolicy: IfNotPresent
- ports:
- - containerPort: 8080
- volumeMounts:
- - name: s247agent
- mountPath: /home/apm
Step 5:
Add the following environment variables to application containers.
Environment variable 1:
Name: S247_LICENSE_KEY
Value: s247licensekey from the secret added in step 1
Environment variable 2:
Name: JAVA_TOOL_OPTIONS
Value: "-javaagent:[mount/path]/apminsight-javaagent.jar -Dapminsight.application.name=[DesiredMonitorName]"
In this step, we configure the arguments that the application (Java process) will use during startup and the agent to report data to the specified monitor name.
Example:
- env:
- - name: JAVA_TOOL_OPTIONS
- value: -javaagent:/home/apm/apminsight-javaagent.jar -Dapminsight.application.name=petclinic-k8s
- - name: S247_LICENSE_KEY
- valueFrom:
- secretKeyRef:
- name: petclinic-secrets
- key: s247_license_key
Example YAML deployment file for your reference:
- apiVersion: v1
- kind: Namespace
- metadata:
- name: petclinic
- ---
- apiVersion: v1
- kind: Secret
- metadata:
- name: petclinic-secrets
- namespace: petclinic
- type: Opaque
- data:
- s247_license_key: OGQ3NTg0YmIxNWE1YTIzYjhmN35rfed2M1M2U3N2ExOTVhNzM1YWYyMg==
- ---
- apiVersion: apps/v1
- kind: Deployment
- metadata:
- namespace: petclinic
- name: petclinic-deployment
- labels:
- app: petclinic
- spec:
- replicas: 2
- selector:
- matchLabels:
- app: petclinic
- template:
- metadata:
- labels:
- app: petclinic
- spec:
- containers:
- - name: petclinic
- image: petclinic:latest
- imagePullPolicy: IfNotPresent
- ports:
- - containerPort: 8080
- env:
- - name: JAVA_TOOL_OPTIONS
- value: -javaagent:/home/apm/apminsight-javaagent.jar -Dapminsight.application.name=petclinic-k8s
- - name: S247_LICENSE_KEY
- valueFrom:
- secretKeyRef:
- name: petclinic-secrets
- key: s247_license_key
- volumeMounts:
- - name: s247agent
- mountPath: /home/apm
- initContainers:
- - name: agent-copy-init
- image: site24x7/apminsight-javaagent:latest
- imagePullPolicy: IfNotPresent
- command: ['cp', '-r', '/opt/site24x7/.', '/home/apm']
- volumeMounts:
- - name: s247agent
- mountPath: /home/apm
- volumes:
- - name: s247agent
- ---
- apiVersion: v1
- kind: Service
- metadata:
- namespace: petclinic
- name: petclinic-service
- spec:
- type: NodePort
- selector:
- app: petclinic
- ports:
- - protocol: TCP
- port: 8080
- targetPort: 8080
- nodePort: 30200
Related Articles
How to add APM Insight Java agent without application restart?
In general, after installing the APM Insight Java agent, you have to restart your application for the agent to capture monitoring data. But in case of critical issues in the app, like sudden application slowness, where you haven't installed APM ...
How to upgrade the APM Insight Java agent to the latest version that supports Java 6 and 7?
Java agent version 5.7.0 and above deprecates support for Java applications running on Java 6 and 7. Please see this community post for more details. If you don't want to upgrade to Java 8, you can stick with Java 6 or 7. Since Java agent version ...
Steps to troubleshoot when you get NO DATA message for Java applications.
After adding APM Insight Java agent, if you get NO DATA message, it could be because of probable reasons like network issues or zero traffic in your application. Kindly read through the below given instructions to troubleshoot. Reason Cause Solution ...
DC migration steps for APM Insight agents
For Server based installations 1. Obtain the new device key. 2. Update the license.key value in the APM Insight configuration file (or the environment variable mentioned) with the new device key. The location varies for each agent, as listed below: ...
How to rename an APM Insight application?
Site24x7 APM Insight doesn't support renaming applications/monitors from the web client. However, the application name of an existing application instance can be renamed in the apminsight.conf file and the agent associated with that instance will ...