This page describes how to configure APM container correlation with the Cluster Agent when manually instrumenting Kubernetes applications. See Kubernetes.

When you establish APM correlation, the application containers monitored by the Cluster Agent display in the Controller under the Application/Container view. The Cluster Agent Pod Dashboard also provides a link to the APM Node Dashboard in the Pod Details page.

This configuration is required only when you use init containers or Dockerfiles to manually instrument applications in a cluster where the Cluster Agent is running. When you use Cluster Agent auto-instrumentation, APM container correlation is processed automatically. See Auto-Instrument Applications with the Cluster Agent.

APM container correlation uses the UNIQUE_HOST_ID (or APPDYNAMICS_AGENT_UNIQUE_HOST_ID) property of specific language agents. For examples of how to set this property, see the language-specific container installation page:

The table lists the commands required to assign the UNIQUE_HOST_ID  value based on runtime, platform, and App Agent type:

PlatformContainer RuntimeCommand for Container ID
KubernetesDocker
UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/(.{12}).*/\1/p' /proc/self/cgroup)

OpenShift 3.11

Docker
UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/docker-(.{12}).*/\1/p' /proc/self/cgroup)

OpenShift 4.x

CRI-O
UNIQUE_HOST_ID=$(cat /proc/self/cgroup | head -1 | awk -F '/' ' {print $NF}' | awk -F '-' '{print $2}' | cut -c 1-12) ; if [ -z $UNIQUE_HOST_ID]; then UNIQUE_HOST_ID=$(cat /proc/self/cgroup | head -1 | awk -F '/' '{print $NF} ' | cut -c 1-12) ; fi ;

Kubernetes with Docker

Java APM correlation works out-of-the-box because the Agent retrieves the UNIQUE_HOST_ID value automatically. For other Agents with the UNIQUE_HOST_ID property, you must set the property using this command: UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/-(.{12}).*/\1/p' /proc/self/cgroup)

For all language Agents with a uniqueHostId property, set the property using this method when building the App image:

UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/(.{12}).*/\1/p' /proc/self/cgroup)
JAVA_OPTS="$JAVA_OPTS -Dappdynamics.agent.uniqueHostId=$UNIQUE_HOST_ID"
YML

If you cannot change the application image, you can assign the UNIQUE_HOST_ID in the Kubernetes deployment specification by modifying the command attribute:

command: ["/bin/sh"]
args: ["-c", "UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/(.{12}).*/\1/p' /proc/self/cgroup) && java -Dappdynamics.agent.uniqueHostId=$UNIQUE_HOST_ID $JAVA_OPTS -jar /java-services.jar"]
YML

This approach implies that the entry point of the application is known. In the example, the original entry point is:

java $JAVA_OPTS -jar /java-services.jar
YML

OpenShift 3.11 with Docker Runtime

For all language Agents with the UNIQUE_HOST_ID property in OpenShift v3.10 and v3.11 with Docker runtime, set the property using this method when building the App image:

UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/docker-(.{12}).*/\1/p' /proc/self/cgroup)
YML

If you cannot change the application image, you can assign the UNIQUE_HOST_ID in the OpenShift v3.10 or v3.11 deployment specification by modifying the command attribute:

command: ["/bin/sh"]
args: ["-c", "UNIQUE_HOST_ID=$(sed -rn '1s#.*/##; 1s/docker-(.{12}).*/\1/p' /proc/self/cgroup) && java -Dappdynamics.agent.uniqueHostId=$UNIQUE_HOST_ID $JAVA_OPTS -jar /java-services.jar"]
YML

This approach implies that the entry point of the application is known. In the example, the original entry point is:

java $JAVA_OPTS -jar /java-services.jar
YML

OpenShift 4.x with CRI-O Runtime

For all language Agents with the UNIQUE_HOST_ID property in OpenShift v4.x with CRI-O runtime, set the property using this method when building the App image:

UNIQUE_HOST_ID=$(cat /proc/self/cgroup | head -1 | awk -F '/' '
{print $NF}' | awk -F '-' '{print $2}' | cut -c 1-12) ; if [ -z $UNIQUE_HOST_ID ]; then UNIQUE_HOST_ID=$(cat /proc/self/cgroup | head -1 | awk -F '/' '{print $NF}' | cut -c 1-12) ; fi ;
YML

If you cannot change the application image, you can assign the UNIQUE_HOST_ID in the OpenShift v4.x deployment specification by modifying the command attribute:

command: ["/bin/sh"]
args: ["-c", "UNIQUE_HOST_ID=$(cat /proc/self/cgroup | head -1 | awk -F '/' '{print $NF}' | awk -F '-' '{print $2}' | cut -c 1-12) ; if [ -z $UNIQUE_HOST_ID ]; then UNIQUE_HOST_ID=$(cat /proc/self/cgroup | head -1 | awk -F '/' '{print $NF}' | cut -c 1-12) ; fi ;  java -Dappdynamics.agent.uniqueHostId=$UNIQUE_HOST_ID $JAVA_OPTS -jar /java-services.jar"]
YML

This approach implies that the entry point of the application is known. In the example, the original entry point is:

java $JAVA_OPTS -jar /java-services.jar
YML