Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Agent and Integrations

Monitoring Containers and Kubernetes with Datadog: Autodiscovery and Tags

Monitor Docker and Kubernetes with Datadog: container metrics, Live Containers, Autodiscovery annotations, label-based tags, Cluster Agent, and unified service tagging on pods.

Containers change the monitoring problem: a service no longer lives on a named host. Pods start, move and die in seconds, IP addresses are reused, and one node runs dozens of workloads. Datadog handles this with Autodiscovery (finding what runs and configuring checks automatically) and automatic tagging from container and Kubernetes metadata.

You need a real cluster for the real thing. Manifests below are shown read-only, and the TryIt stand-ins model the label-to-tag logic.

What the Agent sees

Run the Agent as a container or a Kubernetes DaemonSet (see installing the Agent). It then reports:

  • Container metrics: docker.cpu.usage, container.cpu.usage, container.memory.usage, network and I/O per container.
  • Kubernetes metrics: from the kubelet (kubernetes.cpu.usage.total, kubernetes.memory.usage), and with the Cluster Agent the state of objects through the kubernetes_state_core check (kubernetes_state.deployment.replicas_available, kubernetes_state.pod.status_phase).
  • Live Containers and Live Processes: near real-time lists with CPU, memory and tags, under Infrastructure > Containers.
  • Orchestrator Explorer: a view of pods, deployments, nodes and other resources, with misconfiguration hints.

Automatic tags

The Agent attaches tags from the platform without any configuration. Typical ones: kube_namespace, kube_deployment, pod_name, kube_service, container_name, image_name, image_tag, kube_node, kube_cluster_name (set via DD_CLUSTER_NAME). You can map more Kubernetes labels and annotations to tags in the Helm chart:

YAML
datadog:
  clusterName: shop-prod
  podLabelsAsTags:
    app: kube_app
    team: team
  namespaceLabelsAsTags:
    env: env

This copies a pod label team=payments into a tag team:payments. Prefer this over editing every application.

Unified service tagging on Kubernetes

env, service and version tie metrics, logs and traces together. In Kubernetes you set them as labels and as environment variables on the pod:

YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: checkout
  labels:
    tags.datadoghq.com/env: prod
    tags.datadoghq.com/service: checkout
    tags.datadoghq.com/version: "2026.11.3"
spec:
  template:
    metadata:
      labels:
        tags.datadoghq.com/env: prod
        tags.datadoghq.com/service: checkout
        tags.datadoghq.com/version: "2026.11.3"
    spec:
      containers:
        - name: app
          image: registry.example.com/checkout:2026.11.3
          env:
            - name: DD_ENV
              valueFrom: { fieldRef: { fieldPath: "metadata.labels['tags.datadoghq.com/env']" } }
            - name: DD_SERVICE
              valueFrom: { fieldRef: { fieldPath: "metadata.labels['tags.datadoghq.com/service']" } }
            - name: DD_VERSION
              valueFrom: { fieldRef: { fieldPath: "metadata.labels['tags.datadoghq.com/version']" } }

The labels let the Agent tag container metrics and logs; the DD_* variables let tracing libraries tag traces. Read more in tags and unified service tagging.

Autodiscovery

Instead of listing nginx servers in a file, you describe how to monitor any container that matches an image or annotation. The Agent watches the orchestrator, notices new containers, and starts or stops checks. In Kubernetes you put annotations on the pod, keyed by the container name:

YAML
metadata:
  annotations:
    ad.datadoghq.com/nginx.checks: |
      {
        "nginx": {
          "init_config": {},
          "instances": [{ "nginx_status_url": "http://%%host%%:81/nginx_status/" }]
        }
      }
    ad.datadoghq.com/nginx.logs: '[{"source": "nginx", "service": "storefront"}]'
  • %%host%% is a template variable the Agent replaces with the pod IP. Others include %%port%%, %%env_NAME%%.
  • The same pattern works with Docker labels (com.datadoghq.ad.checks).
  • Many integrations auto-detect common images with built-in auto_conf.yaml files (Redis, nginx, Postgres), so a pod using the standard image may need no annotation at all.

Pitfalls specific to containers

  1. Cardinality. Tags like pod_name and container_id change with every restart, creating new time series continually. Aggregate by kube_deployment or service in dashboards and monitors rather than by pod.
  2. Short-lived pods. Jobs that finish in seconds may not run a full check interval; use logs or DogStatsD events.
  3. Socket permissions. The Agent needs access to the container runtime socket (Docker or containerd) and the kubelet. RBAC is created by the Helm chart.
  4. Log collection. Set containerCollectAll or per-pod ad.datadoghq.com/<container>.logs; logs are read from the node's container log files.
  5. Resource limits. Give the Agent pod requests and limits, and watch its memory on busy nodes.
Python Stand-in: derive tags from Kubernetes labels

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: Autodiscovery matches containers to checks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Autodiscovery do?

    The Agent watches the orchestrator and applies check templates to matching containers.
  2. 2. Which tag is risky to group by in long-lived monitors because it changes on every restart?

    pod_name is high-churn; use kube_deployment or service for stable grouping.
  3. 3. What is %%host%% in an Autodiscovery annotation?

    Template variables are filled in by the Agent when it applies the check.
  4. 4. Where do you set env, service and version for unified service tagging on Kubernetes?

    Labels tag containers and logs; environment variables tag traces.

Summary

  • The Agent collects container and Kubernetes metrics and tags them automatically.
  • Map pod labels to tags with the Helm chart; use tags.datadoghq.com/* labels and DD_* variables for unified service tagging.
  • Autodiscovery uses annotations, labels and templates so checks follow containers.
  • Avoid grouping by churning tags such as pod_name.

Next: Cloud Integrations: AWS, Azure and Google Cloud