Deploy OneAgent on Kubernetes for application-only monitoring by automatic injection using OneAgent Operator (deprecated)

This procedure is deprecated.

Dynatrace 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.

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.

Prerequisites

This deployment strategy requires extra ephemeral storage:

  • ~325 MB for glibc
  • ~290 MB for musl
  • ~650 MB for glibc and musl combined

Deploy OneAgent

  1. Create a Dynatrace namespace.

    kubectl create namespace dynatrace
  2. Install OneAgent Operator.

    OneAgent Operator acts on its dynatrace 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
  3. 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"
  4. Save the OneAgent custom resource definition. The rollout of Dynatrace OneAgent for application-only installations is governed by the custom resource type OneAgentAPM. Retrieve the cr-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
  5. 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 to true to pull a OneAgent Docker image from your Dynatrace environment. Use this parameter together with the agentVersion 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.

  6. Label your namespaces.

    OneAgent Operator injects into all pods that belong to namespaces labeled oneagent.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
  7. Configure the injection.

    You can configure the injection through Kubernetes annotations.

    These settings apply to all containers running on the corresponding pods.

  8. Create the custom resource

    kubectl apply -f cr-apm.yaml
  9. Deploy your applications.

    All deployed pods will then be monitored.

  10. For troubleshooting purposes, you can view OneAgent logs, which by default are on /opt/dynatrace/oneagent-paas/log inside the instrumented containers.

Uninstall OneAgent

  1. Uninstall OneAgent Operator.

    kubectl delete -f https://github.com/Dynatrace/dynatrace-oneagent-operator/releases/latest/download/kubernetes.yaml
  2. Delete the dynatrace namespace. This will also delete OneAgentAPM objects.

  3. optional Remove the corresponding labels and annotations from namespaces/pods.

  4. Redeploy your pods.