Kubernetes Tag Extraction
Security Monitoring is now available Security Monitoring is now available

Kubernetes Tag Extraction

The Agent can create and assign tags to all metrics, traces, and logs emitted by a Pod, based on its labels or annotations.

If you are running the Agent as a binary on a host, configure your tag extractions with the Agent tab instructions. If you are running the Agent as a container in your Kubernetes cluster, configure your tag extraction with the Containerized Agent tab instructions.

Tag Autodiscovery

Starting with Agent v6.10+, the Agent can autodiscover tags from Pod annotations. It allows the Agent to associate tags to all data emitted by the entire pods or an individual container within this pod.

To apply a <TAG_KEY>:<TAG_VALUE> tag to all data emitted by a given pod and collected by the Agent use the following annotation on your pod:

annotations:
  ad.datadoghq.com/tags: '{"<TAG_KEY>": "<TAG_VALUE>","<TAG_KEY_1>": "<TAG_VALUE_1>"}'

If you want to apply a <TAG_KEY>":<TAG_VALUE> tag to an individual container <CONTAINER_IDENTIFIER> within a pod, use the following annotation on your pod:

annotations:
  ad.datadoghq.com/<CONTAINER_IDENTIFIER>.tags: '{"<TAG_KEY>": "<TAG_VALUE>","<TAG_KEY_1>": "<TAG_VALUE_1>"}'

Node labels as tags

Starting with Agent v6.0+, the Agent can collect labels for a given node and use them as tags to attach to all metrics emitted by all pods on this node:

To extract a given node label <NODE_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_KUBERNETES_NODE_LABELS_AS_TAGS='{"<NODE_LABEL>": "<TAG_KEY>"}'

For example, you could set up:

DD_KUBERNETES_NODE_LABELS_AS_TAGS='{"app":"kube_app"}'

To extract a given node label <NODE_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

kubernetes_node_labels_as_tags:
  <NODE_LABEL>: <TAG_KEY>

For example, you could set up:

kubernetes_node_labels_as_tags:
  app: kube_app

Pod labels as tags

Starting with Agent v6.0+, the Agent can collect labels for a given pod and use them as tags to attach to all metrics emitted by this pod:

To extract a given pod label <POD_LABEL> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_KUBERNETES_POD_LABELS_AS_TAGS='{"<POD_LABEL>": "<TAG_KEY>"}'

For example, you could set up:

DD_KUBERNETES_POD_LABELS_AS_TAGS='{"app":"kube_app"}'

For Agent v6.8.0+, use the following environment variable configuration to add all pod labels as tags to your metrics. In this example, the tags names are prefixed by <PREFIX>_:

DD_KUBERNETES_POD_LABELS_AS_TAGS='{"*":"<PREFIX>_%%label%%"}'

Note: Using this method may increase the number of custom metrics for your organization and impact your billing.

To extract a given pod label <POD_LABEL> and transform it as a Tag Key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

kubernetes_pod_labels_as_tags:
  <POD_LABEL>: <TAG_KEY>

For example, you could set up:

kubernetes_pod_labels_as_tags:
  app: kube_app

For Agent v6.8.0+, use the following environment variable configuration to add all pod labels as tags to your metrics. In this example, the tag names are prefixed by <PREFIX>_:

kubernetes_pod_labels_as_tags:
  *: <PREFIX>_%%label%%

Note: Using this method may increase the number of metrics for your organization and impact your billing.

Pod annotations as tags

Starting with Agent v6.0+, the Agent can collect annotations for a given pod and use them as tags to attach to all metrics emitted by this pod:

To extract a given pod label <POD_ANNOTATION> and transform it as a tag key <TAG_KEY> within Datadog, add the following environment variable to the Datadog Agent:

DD_KUBERNETES_POD_ANNOTATIONS_AS_TAGS='{"<POD_ANNOTATION>": "<TAG_KEY>"}'

For example, you could set up:

DD_KUBERNETES_POD_ANNOTATIONS_AS_TAGS='{"app":"kube_app"}'

To extract a given pod annotation <POD_ANNOTATION> and transform it as a tag key <TAG_KEY> within Datadog, add the following configuration block in the Agent datadog.yaml configuration file:

kubernetes_pod_annotations_as_tags:
  <POD_ANNOTATION>: <TAG_KEY>

For example, you could set up:

kubernetes_pod_annotations_as_tags:
  app: kube_app

Further Reading