Set the Java Agent Environment Variables

Use ConfigMaps to Configure the App Server Agent

To use ConfigMaps to configure the App Server Agent:
  1. Use a ConfigMap to set the Java Agent environment variables that are shared across applications in a namespace:
    apiVersion: v1
                            data:
                            APPDYNAMICS_AGENT_APPLICATION_NAME: "eCommerce"
                            APPDYNAMICS_AGENT_ACCOUNT_NAME: "<value>"
                            APPDYNAMICS_CONTROLLER_HOST_NAME: "<value>"
                            APPDYNAMICS_CONTROLLER_PORT: "<value>"
                            APPDYNAMICS_CONTROLLER_SSL_ENABLED: "<value>"
                            APPDYNAMICS_JAVA_AGENT_REUSE_NODE_NAME: "true"
                            APPDYNAMICS_JAVA_AGENT_REUSE_NODE_NAME_PREFIX: "<value>"
                            kind: ConfigMap
                            metadata:
                            name: ecommerce-java-config
  2. Apply the ConfigMap to the namespace:
    kubectl -n ecommerce apply -f ecommerce-java-config.yaml
  3. Update the deployment spec to reference the ConfigMap:
    spec:
                            containers:
                            - name: java-app
                            envFrom:
                            - configMapRef:
                            name: ecommerce-java-config
                            ...

Use Secrets for the Controller Access Key

To use secrets for the Controller Access key:
  1. Create a Secret using kubectl:
    kubectl -n ecommerce create secret generic appd-agent-secret --from-literal=access-key=<access-key>
  2. Update the deployment spec to reference the Secret:
    spec:
                            containers:
                            - name: java-app
                            env:
                            - name: APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY
                            valueFrom:
                            secretKeyRef:
                            name: appd-agent-secret
                            key: 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.