How do I monitor Kubernetes?

Based on Docker, Kubernetes is a next generation platform for deploying and running containerized applications at scale.

To monitor applications running within a Kubernetes cluster, install Dynatrace OneAgent on each cluster node, as described below.

Locate your Dynatrace OneAgent installer URL

The first step is to obtain the location for ONEAGENT_INSTALLER_SCRIPT_URL. This information is presented to you during Dynatrace OneAgent installation.

To get your ONEAGENT_INSTALLER_SCRIPT_URL

  1. Select Deploy Dynatrace from the navigation menu.
  2. Click Start installation and select Linux.
  3. Locate your ONEAGENT_INSTALLER_SCRIPT_URL, as shown below.

Installation

The following DaemonSet installs Dynatrace OneAgent for full-stack monitoring on each node of a Kubernetes cluster.

$ cat <<- EOF > dynatrace-oneagent.yml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: dynatrace-oneagent
spec:
  template:
    metadata:
      labels:
        name: dynatrace-oneagent
    spec:
      hostPID: true
      hostIPC: true
      hostNetwork: true
      nodeSelector:
        beta.kubernetes.io/os: linux
      volumes:
      - name: host-root
        hostPath:
          path: /
      containers:
      - name: dynatrace-oneagent
        image: dynatrace/oneagent
        env:
        - name: ONEAGENT_INSTALLER_SCRIPT_URL
          value: "REPLACE_WITH_YOUR_URL"
        - name: ONEAGENT_INSTALLER_SKIP_CERT_CHECK
          value: "false"
        volumeMounts:
        - name: host-root
          mountPath: /mnt/root
        securityContext:
          privileged: true
EOF

Deploy Dynatrace OneAgent using the above dynatrace-oneagent.yml file. Be sure to replace REPLACE_WITH_YOUR_URL with the Dynatrace OneAgent installer URL as explained above:

$ kubectl create -f dynatrace-oneagent.yml --namespace=kube-system
daemonset "dynatrace-oneagent" created

Verify that the dynatrace-oneagent daemon set has been created successfully:

$ kubectl get pods --namespace=kube-system
NAME                       READY     STATUS              RESTARTS   AGE
dynatrace-oneagent-abcde   1/1       Running             0          1m
$ kubectl logs -f dynatrace-oneagent-abcde
09:46:18 Deploying agent to /tmp/Dynatrace-OneAgent-Linux.sh via https://EnvironmentID.live.dynatrace.com/installer/oneagent/unix/latest/AbCdEfGhIjKlMnOp
...
09:46:24 Validating agent installer in /tmp/Dynatrace-OneAgent-Linux.sh
Verification successful
09:46:24 Started agent deployment as docker image, PID 1234.
09:46:24 Container version: 1.x
09:46:24 Checking root privileges...
09:46:24 OK
09:46:27 Installation started, version 1.x, build date: 01.01.2017, PID 1234.
...

Updating

Whenever a new version of Dynatrace OneAgent becomes available in Dynatrace, you can re-deploy Dynatrace OneAgent as explained in the steps below. Your dynatrace/oneagent image will automatically fetch the latest version of Dynatrace OneAgent. If you've specified a default OneAgent install version for new hosts and applications in your OneAgent updates settings, the dynatrace/oneagent image will automatically fetch the defined default version of Dynatrace OneAgent:

Delete the dynatrace-oneagent daemon set:

$ kubectl delete ds/dynatrace-oneagent

Deploy Dynatrace OneAgent using the above dynatrace-oneagent.yml file. Be sure to replace REPLACE_WITH_YOUR_URL with the Dynatrace OneAgent installer URL as explained above:

$ kubectl create -f dynatrace-oneagent.yml --namespace=kube-system
daemonset "dynatrace-oneagent" created

Troubleshooting

In case you encounter problems when deploying OneAgent on Kubernetes, please visit How can I troubleshoot OneAgent deployment on Kubernetes? for troubleshooting information.