Deploy OneAgent on Kubernetes for application-only monitoring
Dynatrace supports full-stack monitoring for Kubernetes, from the application down to the infrastructure layer. However, if you don't have access to the infrastructure layer, Dynatrace also provides the option of application-only monitoring. See below for instructions on how to set up Dynatrace to monitor your applications running on Kubernetes.
Prerequisites
- Create a PaaS Token.
- Review the list of supported applications and versions.
Note: When deployed in application-only mode, OneAgent monitors the memory, disk, CPU, and networking of processes within the container only. Host metrics aren't monitored.
Integrate OneAgent into your application
The following options explain how you can integrate OneAgent with Kubernetes applications.
Dynatrace also offers the option to inject OneAgent into Kubernetes pods. OneAgent Operator runs an admission controller that can modify pods to inject OneAgent by adding an init container. This init container will download the OneAgent package and configure the other containers to be monitored.
- Kubernetes version 1.14+
- OneAgent Operator v0.8.0+
- Create a Dynatrace namespace.
$ kubectl create namespace dynatrace
- Install OneAgent Operator.
OneAgent Operator acts on itsdynatrace
namespace. You can also observe the logs of OneAgent Operator.
$ kubectl apply -f https://github.com/Dynatrace/dynatrace-oneagent-operator/releases/latest/download/kubernetes.yaml
$ kubectl -n dynatrace logs -f deployment/dynatrace-oneagent-operator
- Create the secret holding the PaaS token for authentication to the Dynatrace cluster.
$ kubectl -n dynatrace create secret generic oneagent --from-literal="paasToken=PAAS_TOKEN"
- Save the OneAgent custom resource definition. The rollout of Dynatrace OneAgent for application-only installations is governed by the custom resource type
OneAgentAPM
. Retrieve thecr-apm.yaml
file from the GitHub repository.
curl -o cr-apm.yaml https://raw.githubusercontent.com/Dynatrace/dynatrace-oneagent-operator/master/deploy/cr-apm.yaml
- Adapt the values of the custom resource as follows:
-
Required Specify the
spec.apiUrl
parameter, which is the URL of your Dynatrace environment, for your SaaS, Managed, or ActiveGate instance. -
Optional Configure
spec.useImmutableImage
totrue
to pull a OneAgent docker image from your Dynatrace environment. Use this parameter together with theagentVersion
parameter to control the version of OneAgent. -
Optional Configure
spec.agentVersion
using semantic versioning (major.minor.patch
- example:1.203.0
). If no version is specified, the OneAgent defaults to the latest version available. -
Optional Configure network zones by setting the
spec.networkZone
parameter to your network zone.
spec:
networkZone: <your_network_zone>
See network zones for more information.
- Label your namespaces.
OneAgent Operator injects into all pods that belong to namespaces labeledoneagent.dynatrace.com/instance
. The value for this label must be the name of the OneAgentAPM instance that you want to use to configure the corresponding namespaces. You must label all namespaces you want to monitor. Note that the namespaces can point to different OneAgentAPM instances.
$ kubectl label namespace default oneagent.dynatrace.com/instance=oneagentapm
- Configure the injection.
You can configure the injection through Kubernetes annotations.
Note: These settings apply to all containers running on the corresponding pods.
oneagent.dynatrace.com/inject
:<"true">
or<"false">
. Sets the default injection for pods on the namespace. Can be overridden by adding the annotation to the pods themselves. It defaults totrue
.
Example
$ kubectl annotate namespace default oneagent.dynatrace.com/inject=false
namespace/default annotated
oneagent.dynatrace.com/inject
:<"true">
or<"false">
. If set tofalse
, no modifications will be applied to the pod. If not set, the default on the namespace is used.oneagent.dynatrace.com/flavor
:<"default">
or<"musl">
. If set, it indicates whether binaries for glibc or musl are to be downloaded. It defaults toglibc
.
Note: If your container uses musl (for example, Alpine base image), you must add the flavor annotation in order to monitor it.oneagent.dynatrace.com/technologies
:<"comma-separated technologies list">
. If set, it filters which code modules are to be downloaded. It defaults to"all"
.oneagent.dynatrace.com/install-path
:<"path">
. If set, it indicates the path where the unpacked OneAgent directory will be mounted. It defaults to"/opt/dynatrace/oneagent-paas"
.oneagent.dynatrace.com/installer-url
:<"url">
. If set, it indicates the URL from where the OneAgent app-only package will be downloaded. It defaults to the Dynatrace environment API configured on the API URL of OneAgentAPM.
Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app
spec:
selector:
matchLabels:
app: sample-app
strategy:
type: Recreate
template:
metadata:
annotations:
# The configuration for app-only injection should be set here.
oneagent.dynatrace.com/technologies: "java,nginx"
oneagent.dynatrace.com/flavor: "musl"
oneagent.dynatrace.com/inject: "true"
oneagent.dynatrace.com/install-path: "/dynatrace"
oneagent.dynatrace.com/installer-url: "https://my-custom-url/route/file.zip"
labels:
app: sample-app
spec:
containers:
- command: [ "java", "-jar", "/app/app.jar" ]
image: "my-image"
# ...
- Create the custom resource
kubectl apply -f cr-apm.yaml
-
Deploy your applications.
All deployed pods will then be monitored. -
For troubleshooting purposes, you can view OneAgent logs, which by default are on
/opt/dynatrace/oneagent-paas/log
inside the instrumented containers.
- Docker version 17.05+
- OneAgent version 1.155+
Follow the steps below to integrate OneAgent into the application image.
-
Sign in to Docker with your Dynatrace environment ID as username and PaaS token as password.
docker login -u <environmentID> <ACTIVEGATE-ADDRESS>
-
Add the following lines of code to the application image, after the last
FROM
command:COPY --from=<ADDRESS>/linux/oneagent-codemodules:<TECHNOLOGY> / / ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so
where:
<ADDRESS>
is:- EnvironmentActiveGate:
<ActiveGateaddress:9999>
- SAAS:
{yourenvid}.live.dynatrace.com
- Managed:
{ManagedAddress}
- EnvironmentActiveGate:
<TECHNOLOGY>
is: The OneAgent code module required for your application. Valid options areall
,java
,apache
,nginx
,nodejs
,dotnet
,php
,go
, andsdk
. You can specify several code modules, separated by hyphen (-
), for examplejava-go
. Including specific technology-support options, rather than support for all technology options, results in a smaller OneAgent package.
What if my Docker image is based on Alpine Linux?
Dynatrace OneAgent supports Alpine Linux based environments.
Use this syntax:
COPY --from=<ACTIVEGATE-ADDRESS>/linux/oneagent-codemodules-musl:<TECHNOLOGY> / /
ENV LD_PRELOAD /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so
Valid options here are all
, php
, java
, apache
, nginx
, nodejs
, and go
.
- Build your application image.
Build the Docker image from your Dockerfile to use it in your Kubernetes environment.
$ docker build -t yourapp .
You can monitor your application containers with a different Dynatrace environment.
For OneAgent version 1.139 or higher, if you have an existing application image where you have already added the OneAgent code modules for a specific Dynatrace environment, you can have the OneAgent report to another Dynatrace environment without rebuilding your application image.
For this, you need to make a call to the REST endpoint of your second Dynatrace environment. Don't forget to adapt the respective placeholders <environmentID>
and <token>
.
$ curl "https://<environmentID>.live.dynatrace.com/api/v1/deployment/installer/agent/connectioninfo?Api-Token=<token>"
In return, you get a JSON object that covers the required information that needs to be passed as an environment variable to the application container.
Make sure you set the environment variables of the application container as described below:
DT_TENANT
: equalstenantUUID
DT_TENANTTOKEN
: equalstenantToken
DT_CONNECTION_POINT
: semi-colon separated list ofcommunicationEndpoints
-
Optional
Configure network zones
You can configure network zones as an environment variable:
DT_NETWORK_ZONE
: equalsyour.network.zone
See network zones for more information.
-
Optional
Configure a proxy address
In case you run an environment with proxy, you need to set the
DT_PROXY
environment variable in the application container to pass the proxy credentials to OneAgent.Note: For Alpine Linux-based containers, you might need to update the
wget
shipped with the Alpine image to allow for proxy authentication for the download of OneAgent.
OneAgent version 1.149+
With the container runtime integration, OneAgent is made available to the application container via an initContainer
—your application image remains unaffected.
To integrate OneAgent into your application at runtime, extend your deployment template as follows.
# your application containers
containers:
- name: customer-app
image: tomcat
env:
- name: LD_PRELOAD
value: /opt/dynatrace/oneagent/agent/lib64/liboneagentproc.so
- name: DT_NETWORK_ZONE
value: <your_network_zone>
volumeMounts:
- mountPath: /opt/dynatrace/oneagent
name: oneagent
# initcontainer to download OneAgent
initContainers:
- name: install-oneagent
image: alpine:3.8
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
# Make OneAgent available as a volume
volumes:
- name: oneagent
emptyDir: {}
-
In the
# initContainer to download OneAgent
and# Make OneAgent available as a volume
sections, add theinitContainer
, which will download OneAgent and make it available as a volume. -
In the
DT_ONEAGENT_OPTIONS
section, set the OneAgent code module required for your compiler flavor (FLAVOR
) and application (TECHNOLOGY
).- Valid options for
flavor
aredefault
,musl
. - Valid options for
technology
areall
,java
,apache
,nginx
,nodejs
,dotnet
,php
,go
, andsdk
. - For ARM, use the following value:
flavor=<FLAVOR>&include=<TECHNOLOGY>&arch=arm
. For other architectures, see the list of valid values (scroll down to thearch
parameter). - If you want to specify several code modules, use the following syntax:
&include=technology1&include=technology2
.
- Valid options for
Note: If you include specific technology-support options rather than 'support for all technologies' options, you'll get a smaller OneAgent package.
What if my Docker image is based on Alpine Linux?
Dynatrace OneAgent supports the flavor musl
for Alpine Linux based environments.
Valid options for flavor=musl
are all
, go
, php
, java
, apache
, nginx
, and nodejs
.
-
In the
# your application containers
section, add the newly created volume to the container of your application. Also add theLD_PRELOAD
environment variable. -
Optional In the
# your application containers
section, configure network zones:
containers:
env:
- name: DT_NETWORK_ZONE
value: <your_network_zone>
See network zones for more information.
-
Optional
Configure a proxy address.
In case you run an environment with proxy, you need to set the
DT_PROXY
environment variable in the application container to pass the proxy credentials to OneAgent.Note: For Alpine Linux-based containers, you might need to update the
wget
shipped with the Alpine image to allow for proxy authentication for the download of OneAgent.