Set the Java Agent Environment Variables
To set all of the required Java Agent environment variables, you must follow these steps as explained in Best Practices to Configure Agents in Kubernetes.
Use ConfigMaps to Configure the App Server Agent
Use Secrets for the Controller Access Key
Set Application-Specific Configuration in the Deployment Spec
Set the application-specific tier name environment variable APPDYNAMICS_AGENT_TIER_NAME in the deployment spec:
spec:
containers:
- name: java-app
env:
- name: APPDYNAMICS_AGENT_TIER_NAME
value: ecommerce-service
Add the -javaagent Argument to the Deployment Spec
Edit the deployment spec to add the -javaagent argument to the application container startup command as shown in the example:
spec:
containers:
command: ["/bin/sh"]
args: ["-c", "java -javaagent:/opt/appdynamics/javaagent.jar -jar /myapp.jar"]
Note that for some Java frameworks such as Spring Boot, you can leverage the standard JAVA_TOOL_OPTIONS environment variable to include the -javaagent argument.
(OpenShift Only) Set the APPDYNAMICS_AGENT_UNIQUE_HOST_ID Environment Variable
For Java applications running in OpenShift, set the
APPDYNAMICS_AGENT_UNIQUE_HOST_ID
environment variable to enable APM
correlation with the Cluster Agent. Since the
APPDYNAMICS_AGENT_UNIQUE_HOST_ID
value depends on a runtime value, set this
environment variable in the container startup command.
For example, for an OpenShift 3.10 or 3.11 environment, set the environment variable as shown:
spec:
containers:
command: ["/bin/sh"]
args: ["-c", "APPDYNAMICS_AGENT_UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/docker-(.{12}).*/\\1/p' /proc/self/cgroup) && java -javaagent:/opt/appdynamics/javaagent.jar -jar /myapp.jar"]
For your use case, see values documented in Manually Configure App Agents to Correlate with the Cluster Agent.
(On-Premises Controller Only) Copy the Controller Certificates to the Container
If on-premises Controller certificates are required, define a ConfigMap to reference the cert file and use a volume mount
in the deployment spec to mount the ConfigMap contents to the container.
$ kubectl create configmap appd-cert --from-file=cacerts.jks
Add the cert file, in this example, appd-cert
, to the container file system using volumes
and volumeMounts
as shown in the deployment spec snippet:
kind: Deployment
spec:
containers:
image: myrepo/java-app:v1
volumeMounts:
- name: appd-cert
subPath: cacerts.jks
mountPath: /opt/appdynamics/ver4.5.11.26665/conf/cacerts.jks
volumes:
- name: appd-cert
configMap:
name: appd-cert
Example Configuration for Using an Init Container
A complete example of a deployment spec that uses an init container to copy the agent binaries can be found on Github: java-app.yaml.