Adding Kubernetes metadata with the k8sattributes processor

The k8sattributes processor adds namespace, pod, deployment and node context to telemetry so teams can filter and correlate signals. This page covers association rules, RBAC, and where to run it.

On this page

Adding Kubernetes metadata with the k8sattributes processor: when teams need it

A platform team receives traces, metrics and logs from dozens of services, but the records arrive with only a host name or an IP address. Nobody can tell which namespace, deployment or pod produced a slow span or a burst of errors. The k8sattributes processor fixes this by adding Kubernetes metadata, such as namespace, pod name, deployment, node and labels, to telemetry as it passes through the OpenTelemetry Collector. That metadata lets teams filter by workload, correlate traces with metrics and logs from the same pod, and assign ownership of a signal to the team that runs the service.

The processor runs inside the Collector, not in the observability backend. OpenTelemetry is vendor-agnostic, so the same enrichment works regardless of which storage or visualization tool receives the data. The Collector can run as an agent alongside workloads, typically one per node, where the processor sees the pods on that node and their IP addresses directly. It can also run as a gateway that receives data from many sources. The placement decision affects which pods can be matched and how much cluster state each Collector must watch, so the team should map where each signal leaves the cluster before enabling the processor.

Before enabling it, confirm three things with your own cluster: which signals need enrichment (traces, metrics, logs or all three), which attributes your dashboards and ownership rules require, and whether your current Collector build includes the processor. Check the processor's documentation for its current stability level, since the Collector's core components have mixed stability levels. The OpenTelemetry Collector documentation is the natural next read for the component list and configuration options.

How metadata flows from the Kubernetes API into telemetry

The k8sattributes processor starts at the Kubernetes API, where the Collector's service account reads pod, namespace and node objects through RBAC. The processor then matches each incoming span, metric or log record to a pod using the association rules you configure, typically the pod IP or a resource attribute, and copies the matched labels onto the record. Check two things before you go live: that the service account can list and watch the objects it needs, and that the association key is unique for the pods that send telemetry through this Collector.

Metadata is read from the API under RBAC and attached to telemetry inside the Collector.

Running k8sattributes in agents versus gateways

When the processor runs in a DaemonSet agent on each node, it sits closest to the workloads that emit telemetry. Data usually arrives from pods on the same node, so the connection IP the agent sees is normally the pod IP itself. That makes association by connection IP the simplest path, and the agent can attach pod, namespace, deployment and node attributes before data leaves the node.

  • Pod IPs are visible: Telemetry from application SDKs or local log readers arrives directly from the pod, so the source address matches the pod IP that the Kubernetes API reports.
  • Association is local: Each agent only needs to match data from its own node, which keeps the association logic close to the source.
  • API load scales with nodes: Every agent opens its own watches on pods and related objects, so API server load grows with the number of nodes.
  • Node attributes are straightforward: The agent already runs on the node it describes, so node identity is accurate without extra forwarding.
  • Forwarding is a separate step: Agents usually send data to a gateway, so you must check whether enrichment survives that hop.

Confirm the number of nodes your watches will cover, the RBAC scope granted to the agent service account, and whether your workloads send telemetry directly to the local agent.

Association rules and configuration options compared

This table compares the main k8sattributes choices: how the processor matches telemetry to pods, which metadata it copies, how it narrows its scope, and where it runs. Read each row for when it fits and what it costs in accuracy, coverage or load. The main takeaway is that association source and placement decide whether tags are correct, so settle those before tuning extracted fields.

OptionWhen it fitsTrade-off to weigh
Resource attributes association (for example pod name or pod IP set by the SDK or resource detector)Applications already set pod identity on telemetry, or the Collector receives data that carries these attributesAccuracy depends on what the sender sets; mismatched or missing values leave telemetry untagged
Connection IP associationAgents run on the same node as the workloads and receive direct connections from podsBehind NAT, a proxy or a gateway, the source address points at the wrong pod, so tags can be wrong
Pod UID associationTelemetry carries the pod UID, for example from a sender that reads its own downward API dataRequires the sender to supply the UID; it is unhelpful for data that only carries a name
Extracted metadata fields (namespace, pod name, node name, deployment, workload)Teams need to filter and group by the usual Kubernetes identity fields in dashboards and queriesEach extra field adds attributes to every record, which increases cardinality and back-end storage
Labels and annotations extractionSpecific team, service or cost-center labels must appear on telemetry for routing or chargebackBroad extraction copies many values; extract only the keys you will query and confirm they are stable
Filtering by namespace, node or labelOnly some namespaces or nodes should be enriched, or the processor must watch fewer objects to limit loadNarrow filters can leave some telemetry untagged; check coverage after each change
Pod exclusionSpecific pods, such as noisy or out-of-scope workloads, should not be matched or enrichedExcluded pods lose metadata entirely, so downstream queries for them return no identity
Agent placement (DaemonSet next to workloads)Connection IP association is used and each node's pods send telemetry to a local CollectorEach agent watches the Kubernetes API, so API load and RBAC scope grow with the number of nodes
Gateway placement (central Deployment)Telemetry arrives from many senders through a central endpoint and metadata must come from resource attributesConnection IP is not reliable behind a gateway, and the gateway needs wider RBAC to read pod metadata

RBAC the processor needs and why it should stay narrow

The k8sattributes processor needs to watch cluster objects to map telemetry to pods, and that access is the main security decision in this setup. Each card below covers one part of the permission set, the choice between cluster-wide and namespace-scoped watching, and how to verify the result before the Collector runs.

Read access to pods

The processor watches pods so it can match an incoming span, metric or log record to the pod that produced it, using the IP address or pod UID rules you configure. The role needs get, list and watch on pods, and nothing that allows changes. Confirm the verbs in the ClusterRole or Role manifest before deployment, because a wildcard verb here grants far more than the processor uses.

Read access to namespaces

Namespace labels and annotations are copied onto telemetry when you extract them, so the service account needs read access to namespace objects. Keep the rule to get, list and watch on namespaces only. If your extraction rules do not read namespace labels, leave this rule out and document why it is absent.

Read access to nodes and ReplicaSets

Node names come from pod specs, but node labels need node objects, and Deployment names are derived from ReplicaSet owner references. Grant read access to nodes and replicasets only if your rules extract those fields. Ask the team to justify each resource in writing, since every extra resource is another object the Collector can read across the cluster.

Cluster-wide versus namespace-scoped watching

A ClusterRole with a ClusterRoleBinding lets the processor watch every namespace, which suits a gateway covering the whole cluster. A set of namespace-scoped Roles limits reads to the namespaces you name, which fits a single-tenant team collector. Choose the narrower model when your Collector only handles some namespaces, and confirm with the chart or Operator documentation how each mode is configured.

Cost of broad ClusterRoles

A broad ClusterRole is a standing read path to pod specs, environment references and annotations across all tenants. Any pod that can reach the Collector's credentials, or any compromise of the Collector pod, inherits that reach. Keep the Collector in its own namespace, avoid bundling the role with unrelated permissions, and review the role after every chart upgrade because defaults can change.

Keep secrets out of the role

Do not grant access to secrets for this purpose. The processor reads metadata about workloads, and it has no need for credential material. A role that can list secrets in a namespace exposes database passwords and tokens to anyone who runs the Collector, so treat any secrets rule in this role as a finding to remove.

Check permissions with kubectl auth can-i

Run kubectl auth can-i list pods --as=system:serviceaccount:<namespace>:<name> and similar checks for each verb and resource in the role. Confirm that delete, patch, update and create return no, and that list secrets returns no in every namespace. Record the output with the manifest so the next upgrade can be checked against the same expected results.

Setting up k8sattributes in a Collector on Kubernetes

This sequence takes a Collector from a distribution check to a running k8sattributes processor that stamps namespace, pod, deployment and node onto telemetry. Each step ends with a check so the team knows whether enrichment and the Kubernetes API watch are working before the pipeline goes into regular use.

  1. Confirm the distribution includes the processor

    The platform team checks which Collector build is in use and whether it includes the k8sattributes processor. The processor is part of the contrib distribution, so a core-only or custom build made with the Collector Builder must include it explicitly. Pin the exact Collector version you plan to run and read that version's README for the processor, because component stability varies and the configuration keys can change between releases. Done when the team can run the Collector binary or image with the processor listed among its components and has recorded the version in the change ticket. Confirm the current release notes with the Collector releases page before choosing a version.

  2. Create the service account and RBAC rules

    The cluster administrator creates a dedicated service account for the Collector and binds a ClusterRole that lets it read and watch pods, namespaces, and nodes, plus the ReplicaSet and deployment objects needed to resolve deployment names. Keep the role to read-only verbs and avoid granting write access or secret access. Where the Collector runs in a single namespace with namespace-scoped filtering, confirm whether a narrower Role is enough. Done when kubectl auth can-i, run with the service account, returns yes for list and watch on the required resources and no for create or delete. Record the exact resource list, since the processor documentation and your Collector version determine which objects it reads.

  3. Configure association rules and extracted fields

    The engineer adds a k8sattributes block to the processor configuration and chooses how incoming telemetry is matched to pods. Association rules typically use the pod IP or a resource attribute such as the pod name sent by the SDK, and the choice determines whether data from a gateway can be matched correctly. Next, list the metadata to extract, such as namespace, pod name, deployment name, node name and selected labels or annotations, and keep the list short because each attribute adds cardinality to metrics and storage to logs. Done when the configuration validates with the Collector's config validate command and the team has written down which attributes each signal should carry.

  4. Place the processor in each pipeline

    The engineer adds the processor to the traces, metrics and logs pipelines in the Collector configuration. Place it early, usually after the memory limiter and before batching and exporters, so that enrichment runs before data is sent out but after protective processors have bounded memory use. Confirm that each pipeline lists the processor in the same relative position and that no pipeline sends data to an exporter without enrichment when attributes are required downstream. Done when the rendered configuration shows the processor in all three pipelines in the intended order and the Collector starts without errors in the logs.

  5. Choose agent or gateway placement

    The platform team decides where the processor runs. In agent mode, a DaemonSet Collector on each node sees traffic from local pods and can use the pod IP association, and it usually needs fewer cross-node API calls. In gateway mode, a central Collector receives data from many sources, so association must rely on attributes the sender includes, and the gateway cannot infer pod identity from its own network address. Agree on this choice with the Helm or Operator deployment plan, because the RBAC and association rules depend on it. Done when the team has documented which mode each signal path uses and confirmed that the chosen association method works for every sender.

  6. Deploy and confirm the Collector starts cleanly

    The engineer rolls out the Collector with the service account attached and the new configuration applied. Watch the rollout status and the Collector's own logs for errors about API authentication, forbidden responses or watch failures. Confirm that the pod has mounted the service account token and that the Collector is not running with a default account. Done when every replica reports ready, the logs show no permission errors on startup, and the Collector's internal telemetry shows the processor as active. Confirm the exact health and metrics endpoints in the Collector configuration documentation for your version.

  7. Verify enriched attributes on sample telemetry

    The team sends test traces, metrics and logs from a known pod, then inspects the exported data in the debug exporter or the back end. Each record should carry the namespace, pod name, deployment and node attributes that were configured, with values that match kubectl output for that pod. Test from a pod that is part of a deployment, and from a pod without a deployment owner, to confirm the fallback behavior. Done when all three signals show the expected attributes on samples from at least two nodes and the values match the cluster state.

  8. Confirm the API watch stays healthy

    The team checks that the processor keeps its view of pods current after rollouts and scaling. Create a short-lived test pod, confirm its attributes appear within the expected window, then delete it and check that the Collector logs no repeated watch errors. Review API server audit or request metrics for unusual list volume from the Collector service account, since heavy list calls on large clusters are a common cause of load. Done when the test pod is enriched, the watch recovers after a pod restart in the test namespace, and the team has recorded the baseline API request rate for future comparison.

Security and operational considerations for pod metadata

The k8sattributes processor reads cluster state and copies what it finds into every span, metric and log record it touches. The cards below cover the access it needs, the data it can carry out of the cluster, the controls that limit that data, and the signals that show the processor is failing.

Grant read-only, scoped RBAC

The processor queries the Kubernetes API for pods, namespaces and, depending on configuration, deployments, replica sets and nodes. Bind a ClusterRole that grants only get, list and watch on those resources to the Collector's service account, and avoid wildcard verbs or resources. Check the bound role with a permission query before rollout, because a missing verb usually shows up as silent missing attributes rather than a clear failure.

Collector configuration docs

Review pod labels before they flow out

Pod labels and annotations are copied into telemetry when you extract them, and teams sometimes put owner emails, tenant identifiers or customer names into them. Audit labels and annotations across the namespaces you collect from, and extract only the keys your queries need. Treat any label that encodes personal or regulated data as a field to exclude at the source.

Redact sensitive attributes in the pipeline

OpenTelemetry's security guidance recommends the redaction processor to remove sensitive attributes before export. Place it after the k8sattributes processor so that any metadata copied in is also covered. Test the rules with sample payloads from each namespace, since a redaction rule that matches only the expected key name will miss variants.

Collector security best practices

Confirm localhost binding defaults

Since Collector v0.110.0, server components bind to localhost by default rather than to all interfaces. If your deployment predates that version, or you override the endpoint setting, the receivers may accept connections from other pods or nodes. Check the bound addresses after rollout and restrict any exposed receiver with network policy and authentication.

Verify signed release artifacts

Collector releases ship the contrib distribution with signed artifacts, SHA256 checksums and SBOM files. Before deploying an image or binary, verify its checksum against the release page, confirm the signature, and record the SBOM in your asset inventory. Pin the exact version in your Helm values or Operator manifest so that every cluster runs the same verified build.

Collector release artifacts

Alert on Kubernetes API errors

When the processor cannot reach the API or lacks permission, telemetry continues to flow but loses its Kubernetes attributes. Monitor the Collector's own metrics and logs for failed list and watch calls, and alert when the rate of records missing k8s.* attributes rises. Without this check, dashboards that filter by namespace or deployment will quietly return incomplete results.

Questions teams ask before adding k8sattributes

Can the k8sattributes processor run in agents and gateways at the same time?

Yes, but each placement has different consequences, so most teams choose one role per signal path. In an agent deployment, the Collector runs on each node, usually as a DaemonSet, and can associate telemetry with the pod it came from using the node-local view of the cluster. In a gateway deployment, a central Collector receives data from many sources and must resolve pod identity from the telemetry it receives, which depends on the association rules your senders provide. Running both is common when agents enrich data first and a gateway applies cluster-wide attributes. Confirm the exact behavior of your Collector version in the component README before you rely on a mixed layout, and test each path with real telemetry samples.

How much effort does adding Kubernetes metadata take, and what drives it?

The work is usually small in code and larger in decisions. The main drivers are the number of clusters, the number of signal types (traces, metrics and logs), whether agents, gateways or both are in use, how your applications identify themselves, and how many attributes the team needs. Each additional attribute source, custom label or association rule adds testing. Multi-cluster setups add the need for a cluster identity attribute so data from different clusters can be told apart. Ask any partner for a quote built from a written scope that lists the clusters, signals, placement and verification steps. No duration figure is supplied for this work, so confirm timing against your own environment.

What does our team need to provide before the work starts?

Three inputs matter most. First, read access to the target clusters and the namespaces where telemetry is produced, including a way to inspect the Collector's current configuration. Second, an RBAC approval from the people who own cluster security, because the processor needs permission to read pod, namespace and node metadata through the Kubernetes API, and the scope of that permission should be reviewed before it is granted. Third, telemetry samples from each signal, taken from representative workloads, so the team can confirm which attributes arrive and which association keys are present. Also provide the list of back ends that will receive the enriched data, since their attribute naming and cardinality limits shape the rules.

Can our own platform team implement this without a partner?

Yes, a platform team with Kubernetes and Collector experience can add the processor, but the work is easier to get right with a clear checklist. The team needs to write the RBAC rules carefully, choose association rules that match how their applications export data, and verify that attributes appear on traces, metrics and logs after each change. Teams that lack Collector experience often find the hardest part is confirming that data from agents and gateways carries the same keys. A partner is most useful for a fixed-scope review, a multi-cluster rollout, or an independent check of the security settings before production. Whichever route you choose, record the decisions so future upgrades can be reviewed.

How do Collector upgrades affect the k8sattributes processor?

Upgrades can change component behavior, configuration keys, stability levels and the RBAC the processor needs, so each upgrade should be treated as a change to the telemetry path. Collector releases ship on a regular cadence, and the most recent releases are listed on the OpenTelemetry Collector releases page, which is the right place to track versions and read release notes. Check the component README for stability changes before moving a version, and rerun your verification samples after each upgrade. Also keep the Collector's Kubernetes version support in mind, since the Kubernetes version skew policy and the cluster's own upgrade schedule affect which API versions the processor can rely on.

Does adding pod metadata create security or compliance risk?

It can, mainly through the RBAC grant and the attributes you add. The processor reads object metadata from the Kubernetes API, so grant only the list and watch permissions it needs, scope them as narrowly as your cluster policy allows, and review them with the cluster security owner. Also review which labels and annotations get copied into telemetry, because some values may contain customer or personal identifiers. The OpenTelemetry security guidance recommends using the redaction processor to remove sensitive attributes, and it recommends securing Collector configuration with encryption and authentication. Confirm with your compliance team which attributes are permitted before they flow to back ends.

Which attributes should we expect to see after the processor is in place?

The processor can add namespace, pod, deployment and node attributes, and it can copy selected labels when your rules ask for them. Exact attribute names depend on the Collector version and your configuration, so confirm them against the component documentation and your own samples rather than assuming a standard set. Decide early which attributes you need for filtering and correlation, because each extra attribute increases the number of distinct values a back end must store. Start with the few attributes your investigations require, check that they appear on every signal, and extend the list only when a specific question needs it.

Where to confirm component details and releases

Before you write a k8sattributes configuration, confirm the options against the component itself rather than relying on examples copied from older guides. The component README for the k8sattributes processor in the OpenTelemetry Collector contrib repository is the authority for its current settings, including which metadata fields can be extracted, how pod association rules are evaluated, and which fields carry a stability label. Stability differs between components, so a processor option that works in one release may be marked as changing in another. Record the exact processor name and the Collector version you tested with, because the processor's behavior and defaults can move between releases. Ask your platform team to pin that version in the build or Helm values so that a routine upgrade does not silently change how pod metadata is attached.

The Collector configuration documentation explains how processors fit into pipelines and how the authenticator and extension settings interact with receivers and exporters, which matters once the processor runs in a gateway. For version and artifact checks, use the Collector releases page. Each release lists the contrib distribution, and its assets include signed artifacts, SHA256 checksums and SBOM files. Verify those checksums and retain the SBOM in your change record, since your security team will likely ask which components are in the image. The main Collector repository is the place to review open issues and changelog entries that touch Kubernetes metadata before you schedule an upgrade.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.