cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Abhi.Bajaj
AppDynamics Team

AppDynamics Cluster Agent allows you to auto-instrument your Applications running on Kubernetes. The auto-instrumentation injects APM agents on runtime, modifying your deployment spec with an init-container of AppDynamics APM agent.

You can use different strategies to target Kubernetes deployments, StatefulSet, or DeploymentConfigs.

In this article, we will cover instrumenting one deployment by using a label defined on the Deployment level (it will be the same for DeploymentConfig and StatefulSet)

Let's take this forward with two sample deployments running in namespace abhi-java-apps-second.

My first deployment:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-app-abhi
  labels:
    app: tomcat-app-abhi-second
  namespace: abhi-java-apps-second
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat-app-abhi
  template:
    metadata:
      labels:
        app: tomcat-app-abhi
    spec:
      containers:
      - name: tomcat-app-abhi
        #image: docker.io/abhimanyubajaj98/java-tomcat-sample-app-buildx:latest
        image: docker.io/abhimanyubajaj98/java-application:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        env:
        - name: JAVA_TOOL_OPTIONS
          value: -Xmx512m
        #- name: APPDYNAMICS_AGENT_UNIQUE_HOST_ID
        #  value: $(cat /proc/self/cgroup | head -1 | awk -F '/' '{print $NF}' | cut -c 16-27)
---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-app-service
  labels:
    app: tomcat-app-abhi
  namespace: abhi-java-apps-second
spec:
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    app: tomcat-app-abhi

My Second deployment:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-app-abhi-labelmatch
  labels:
    app: tomcat-app-abhi-second-labelmatch
  namespace: abhi-java-apps-second
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat-app-abhi-labelmatch
  template:
    metadata:
      labels:
        app: tomcat-app-abhi-labelmatch
    spec:
      containers:
      - name: tomcat-app-abhi
        #image: docker.io/abhimanyubajaj98/java-tomcat-sample-app-buildx:latest
        image: docker.io/abhimanyubajaj98/java-application:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        env:
        - name: JAVA_TOOL_OPTIONS
          value: -Xmx512m
        #- name: APPDYNAMICS_AGENT_UNIQUE_HOST_ID
        #  value: $(cat /proc/self/cgroup | head -1 | awk -F '/' '{print $NF}' | cut -c 16-27)
---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-app-service-labelmatch
  labels:
    app: tomcat-app-abhi-labelmatch
  namespace: abhi-java-apps-second
spec:
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    app: tomcat-app-abhi-labelmatch

Now, my use case is only for instrument deployment tomcat-app-abhi-labelmatch. To do this, I would need to edit my cluster-agent.yaml and add the below specs:

instrumentationRules:
    - namespaceRegex: abhi-java-apps-second
      labelMatch:
      - app: tomcat-app-abhi-second-labelmatch
      tierName: abhiapps
      language: java
      imageInfo:
        image: "docker.io/appdynamics/java-agent:latest"
        agentMountPath: /opt/appdynamics
        imagePullPolicy: Always

Now, after the deployment is done, only the deployment tomcat-app-abhi-labelmatch will have AppDynamics Java Agent.

Version history
Last update:
‎09-09-2024 05:15 PM
Updated by:
On-Demand Webinar
Discover new Splunk integrations and AI innovations for Cisco AppDynamics.


Register Now!

Observe and Explore
Dive into our Community Blog for the Latest Insights and Updates!


Read the blog here