Dynatrace | Pod Runtime Injection for Application Only Monitoring on Kubernetes
We use this approach when we wish to monitor a specific pod deployed on kubernetes without making any changes in our image.
Here, Dynatrace OneAgent operator is made available to the application container via an initContainer
—your application image remains unaffected.
Pre-requisites
Generate a PaaS token.
Steps to get these tokens:
- Go to your Dynatrace UI, on the left side you have menu bar, Manage →Access tokens
- Click on Generate new token
- Give meaningful token name and choose the scope — PaaS integration — Installer download, PaaS integration — Support alert, then, generate the PaaS token.

Pod Runtime Injection
Now you will need to modify your application yaml file to add init container for Dynatrace OneAgent
create a volume named oneagent before modifying your application deployment yaml file.
# your application containers
containers:
- name: customer-app
image: tomcat
env:
- name: LD_PRELOAD
value: /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so
volumeMounts:
- mountPath: /opt/dynatrace/oneagent
name: oneagent
volumes:
- name: oneagent
emptyDir: {}
# initcontainer to download OneAgent
initContainers:
- name: install-oneagent
image: alpine:latest
command:
- /bin/sh
args:
- -c
- ARCHIVE=$(mktemp) && wget -O $ARCHIVE "$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_PAAS_TOKEN&$DT_ONEAGENT_OPTIONS" && unzip -o -d /opt/dynatrace/oneagent $ARCHIVE && rm -f $ARCHIVE
env:
- name: DT_API_URL
value: https://<Your-environment-ID>.live.dynatrace.com/api
- name: DT_PAAS_TOKEN
value: <paastoken>
- name: DT_ONEAGENT_OPTIONS
value: flavor=<FLAVOR>&include=<TECHNOLOGY>
volumeMounts:
- mountPath: /opt/dynatrace/oneagent
name: oneagent
Now, we have to make a few changes in the application yaml, please follow along
For your application container part of your application deployment yaml file
#here in your environment variables add these lines. env:
- name: LD_PRELOAD
value: /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so# in volumeMounts add these lines below volumeMounts:
- mountPath: /opt/dynatrace/oneagent
name: oneagent# in volumes add the below lines, remember we already created oneagent volume volumes:
- name: oneagent
emptyDir: {}
Now, we have to create an init container, start from the end of your application deployment file
#here in the image alpine:latest is being pulled from docker.io, if you are using private repo then follow the below steps
# docker pull alpine:latest
# docker tag alpine:latest your-repo/alpine:latest
# doker push your-repo/alpine:latest
# Now, replace the value in image key below with your image-> your-repo/alpine:latestinitContainers:
- name: install-oneagent
image: alpine:latest
command:
- /bin/sh# if your dynatrace url certificate is expired or not supported the use --no-check-certificate in wget command below args:
- -c
- ARCHIVE=$(mktemp) && wget -O $ARCHIVE "$DT_API_URL/v1/deployment/installer/agent/unix/paas/latest?Api-Token=$DT_PAAS_TOKEN&$DT_ONEAGENT_OPTIONS" && unzip -o -d /opt/dynatrace/oneagent $ARCHIVE && rm -f $ARCHIVE# here, below give the correct url of your dyntrace portal- DT_API_URL
# give the passtoken you generated in pre-requisite step - DT_PAAS_TOKEN
# for DT_ONEAGENT_OPTIONS, you have to pick correct value depending upon your application# valid values for flavor -> default, musl, multidistro
# default if for glibc, musl is for musl binaries, multidistro is for both, if you don't know what to use go with multidistro, but mostly in corporate environment default option will work.# valid values for technology -> all, java, apache, nginx, nodejs, dotnet, php, go, and sdk
# if you don't know what to use then go ahead with all. The size of the file will be larger though
#If you want to specify several code modules, use the following syntax: &include=technology1&include=technology2 env:
- name: DT_API_URL
value: https://<Your-environment-ID>.live.dynatrace.com/api
- name: DT_PAAS_TOKEN
value: <paastoken>
- name: DT_ONEAGENT_OPTIONS
value: flavor=<FLAVOR>&include=<TECHNOLOGY>
volumeMounts:
- mountPath: /opt/dynatrace/oneagent
name: oneagent
Now, save the modified deployment yaml file and apply.
You will be able to see the pod now in Dynatrace portal under Infrastructure → hosts.
Click here to see the dynatrace URL for implementing the same.
Thank You for checking this out, appreciate your time 😄
You may also checkout automatic injection approach here.