Collecting Kubernetes container logs with OpenTelemetry

A planning guide to collecting container stdout and stderr from Kubernetes nodes with the OpenTelemetry Collector filelog receiver, including parsing, metadata enrichment and migration off Fluent Bit or Fluentd.

On this page

How Kubernetes container log collection with OpenTelemetry works

The OpenTelemetry Collector can run as a DaemonSet, read container log files on each node with the filelog receiver, and export them to a log backend. The container runtime writes each container's stdout and stderr to files on the node, so one agent per node is the usual placement: the agent reads those files, adds structure to each record, and forwards it. The Collector is licensed under Apache-2.0, and it can also run as a gateway that receives data from many agents, which is useful when logs need central processing or routing before storage.

OpenTelemetry does not store or visualize logs. It defines how logs are collected, processed and exported, so the backend must be chosen separately. Grafana Loki, which stores compressed chunks and an index in object storage, and OpenSearch, which Apache-2.0 licenses and which offers search and dashboards, are two options covered elsewhere in this group. Confirm the backend's license, query needs and retention requirements before you change the agent, because those choices decide what the Collector must send and in which format.

Teams usually replace Fluent Bit or Fluentd when they want one agent for logs, metrics and traces, or when they need OpenTelemetry semantic attributes on every record. The work includes inventorying existing parsers and multiline rules, mapping each to filelog operators, verifying that pod and namespace fields survive the move, and running both agents side by side until volumes and drop counts match. Component stability varies, so check the status of each receiver, parser and exporter in its README before you commit to a production configuration.

How container logs move from node files to a backend

Container stdout and stderr are written to log files on each node, and a Collector agent running as a DaemonSet reads them with the filelog receiver. The agent parses the container runtime format, then calls the Kubernetes API to attach pod metadata for each log line. Logs leave the node through an exporter to a gateway or back end. Check which parts of this path run inside the node trust boundary, which credentials the agent uses for metadata lookups, and whether the export path is encrypted and authenticated.

Log flow from container output through the node agent to an export target.

Which log collection options fit which environment

This table compares four ways to collect container logs from Kubernetes nodes: a filelog DaemonSet agent, a central gateway, keeping Fluent Bit or Fluentd, and Grafana Alloy or Loki-native paths. Read each row against your backend, your parsing needs and who will own the pipeline after go-live. The main takeaway is that the collection point decides where parsing and pod metadata are applied, and that changing shippers is a cutover you plan, not a config tweak.

OptionParsing and metadataBackend fitOperational ownership
filelog DaemonSet agentReads node log files directly, so runtime format parsing and pod metadata can be applied on each node before exportAny OTLP-capable backend, including Loki over HTTP and other log storesYour team owns one agent per node, its RBAC, and upgrades across every node pool
Central gateway receiving logsNodes still need a local reader for files, so parsing usually stays in the agent; the gateway adds routing and batchingSuits multiple backends or a fan-out to several destinations from one placeTwo tiers to run and size; the gateway becomes a shared dependency for log delivery
Keep Fluent Bit or FluentdExisting parsers and filters continue to work, but pod metadata enrichment and OpenTelemetry correlation need separate designMature output plugins; Loki accepts both shippers directlyLowest change now, but two telemetry stacks to maintain and upgrade side by side
Grafana Alloy or Loki-native pathsAlloy is a vendor-neutral OpenTelemetry Collector distribution that Grafana supports for Loki; confirm which components cover your runtime formatsBest fit when Loki is the store and Grafana is the query front endSingle vendor-supported path for Loki users; confirm the component set and support terms before committing
Migration from Fluent Bit or FluentdMap each existing parser and filter to a Collector operator or processor and compare output field namesRun old and new shippers in parallel to compare record counts before cutoverPlan a dated cutover and a rollback path; retire the old DaemonSet only after the comparison passes

Parsing container runtime log formats on each node

The filelog receiver only produces useful records if its operators match the format each node writes to disk, and that format depends on the container runtime. Container log files under /var/log/pods carry a runtime-specific line layout, so a parser written for one runtime can silently misread lines from another. Before writing any operators, confirm the runtime on every node pool in every cluster. Node pools often differ because of upgrades, custom images or managed-service defaults, and a single cluster can contain more than one runtime during a migration. Record the runtime version and the log path layout per pool, then test a parser against a sample file from each pool rather than assuming one configuration fits all nodes.

Two line-level conditions make parsing harder than the header format suggests. Partial lines appear when the runtime splits a long write into several records and marks the continuation, so the pipeline must reassemble them before a log body is complete. Multiline stack traces span many physical lines that belong to one event, and they need a rule that decides where each event starts, usually based on a timestamp or leading token in the application's output. Both behaviors depend on how the runtime and the application write output, so test them with real traces from your workloads, including Java and Python exceptions if those are in use. Confirm the exact operator names, configuration keys and multiline handling in the README of the filelog receiver in your Collector distribution, because support and defaults vary by component version.

Plan this check as a repeatable step, not a one-time setup. Ask the platform team to document the runtime and log layout for each node pool, and add a test that feeds sample lines through the parser before each Collector upgrade or node image change. Keep the samples, including the partial and multiline cases, in version control next to the Collector configuration. Your distribution's documentation is the authority on runtime defaults, so confirm them with the vendor or distribution maintainer before you rely on any default in production.

Enriching logs with pod metadata safely

Container log lines carry little context on their own, so the pipeline adds Kubernetes metadata such as namespace, pod, deployment and node before logs leave the cluster. The cards below cover the decisions that make that enrichment accurate, least privileged and affordable to query.

Scope the RBAC grant

The k8sattributes processor reads pod and related object state from the Kubernetes API, so the Collector's service account needs get, watch and list permissions on the resources it enriches from. Grant these through a ClusterRole only where the processor truly needs cluster-wide reads, and bind it to the Collector's own service account. Check the exact resource list in the component's README against your Collector version before you apply it.

Collector configuration docs

Design pod association rules

The processor must match each log record to a pod, and it does so with association rules that read resource attributes such as the pod IP or the container's source metadata. Choose the rule that your log path actually populates, because a log pipeline that sends no pod IP or pod UID will leave most records unenriched without raising an error. Test with logs from several nodes and confirm the attributes on the stored records.

Pick agents or gateways

Running enrichment in the node agent keeps the pod lookup close to the logs and lets the agent tag records before they cross the network. Running it in a gateway centralizes configuration but sends raw records to a shared tier that must also watch the Kubernetes API. Decide where the lookup runs first, then size the Kubernetes API load, since every agent or gateway replica caches pod state.

Limit label cardinality

Every attribute you copy onto a log record becomes a label candidate in the backend, so pod names, replica hashes and per-deploy annotations can multiply stream counts quickly. Restrict the metadata to fields you will filter by, such as namespace, workload name, container name and node, and leave free-form annotations out. Ask your backend team which attributes it indexes and how it prices or limits them.

Stability of the component

The k8sattributes processor is part of the contrib distribution, and component stability differs by component and signal, as the status page documents in each README. Confirm the stability level for the logs signal in your release before you rely on it for compliance-relevant filtering. Record the Collector version in your change records so that enrichment behavior can be traced after upgrades.

OpenTelemetry status page

Cluster identity and namespace tags

When logs from several clusters land in one backend, add a cluster identity attribute at the agent so that a namespace named payments in one cluster cannot be confused with the same name elsewhere. Also review who can change namespace labels, because teams that use labels for routing or retention decisions can alter what the pipeline records. Document the owner of the cluster name value and where it is set.

Setting up the DaemonSet collector for container logs

This sequence takes a cluster from an undecided log path to a DaemonSet Collector that reads node container logs, enriches them with pod metadata, redacts sensitive fields, and replaces the Fluent Bit or Fluentd agents. Each step ends with a check so the team knows when it can move on.

  1. Confirm the backend and retention plan

    Before any collector config is written, the platform owner and the log backend owner agree on where logs land, how long they are kept, and who can query them. If the destination is Loki, confirm whether retention is enabled, since the compactor keeps logs indefinitely until retention is set, and confirm the tenant model if auth is enabled. Record the destination endpoint, the retention period per stream or tenant, and the authentication method for exporters. Done when the agreed plan is written down and the backend team has confirmed the endpoint accepts test writes from a non-production namespace.

  2. Choose the Collector distribution and build

    Decide between the core distribution, the contrib distribution, or a custom build made with the Collector Builder that contains only the receivers, processors and exporters the pipeline needs. The contrib distribution includes the filelog receiver and the k8sattributes processor used here, so a custom build is the usual choice for hardened environments. Confirm that the chosen release ships signed artifacts, SHA256 checksums and SBOM files, and verify those before the image enters your registry. Done when the image digest, its checksum and the component list are recorded in your change ticket.

  3. Mount node log paths read-only

    The DaemonSet needs read access to the node's container log directory, usually under /var/log/pods and the symlinks under /var/log/containers, plus the container runtime log path where your distribution places them. Mount these hostPath volumes with readOnly set to true, and restrict the pod with a security context that drops unneeded privileges. Confirm the paths with your Kubernetes distribution's documentation, because runtime layouts differ. Done when a debug pod on one node can list the expected log files and the collector pod cannot write to the host path.

  4. Configure the filelog receiver and parsers

    In the collector configuration, set the filelog receiver to include the container log glob, exclude the collector's own logs to avoid feedback loops, and select a parser for the runtime's log format. Container runtimes write lines in formats that differ by runtime, so confirm which format your nodes produce and test the parser against a sample line from each node pool. Set start_at to beginning only for the first backfill and to end for steady state. Done when a test run prints parsed records with timestamp, stream and log body fields populated and no parse errors in the collector log.

  5. Add metadata enrichment and redaction

    Add the k8sattributes processor so each record carries namespace, pod, container and node attributes, and confirm the service account has the read RBAC it needs to look up pods. Then add the redaction processor, or a transform rule, to remove or mask fields that carry credentials, tokens or regulated identifiers before export. Review the security guidance on storing configuration securely and encrypting exporter connections. Done when a sample pod's log lines show the expected Kubernetes attributes and a seeded test secret string no longer appears in the exported output.

  6. Deploy the DaemonSet with Helm or the Operator

    Deploy the collector in DaemonSet mode using the OpenTelemetry Collector Helm chart or the OpenTelemetry Operator, placing the reviewed configuration, the RBAC objects and the mounts from the earlier steps into one release. Pin the chart and image versions, roll out to a single node pool first, and watch for restarts and memory pressure. Done when every targeted node runs one collector pod in the Ready state and the collector metrics show exports succeeding without queue overflow.

  7. Validate logs arrive with correct attributes

    Generate known log lines from a test workload in a non-production namespace, then query the backend for them by namespace, pod and node. Check that timestamps are close to the emit time, that no lines are duplicated after a collector restart, and that each record carries the attributes set in the earlier steps. Repeat the check on at least one node from each pool and one restart of a collector pod. Done when the test lines appear once each, with correct attributes, in the backend.

  8. Cut over from Fluent Bit or Fluentd

    Run the new collector and the existing agent side by side for a short overlap, comparing record counts per namespace between the old and new destinations. Once counts match and the query team confirms that dashboards and alerts work on the new fields, disable the old agent's DaemonSet in one node pool at a time. Keep the old configuration available for rollback until the new pipeline has run through normal traffic. Done when the old agent is removed, no node is missing logs, and the team has signed off on the cutover.

Security controls for node-level log collection

A filelog DaemonSet reads host log paths, talks to the Kubernetes API and holds exporter credentials, which makes it one of the more privileged workloads in the cluster. The controls below cover the permissions it gets, the host access it needs, how its configuration and secrets are stored, and what sensitive content leaves the node.

Least-privilege RBAC for metadata lookups

The k8sattributes enrichment needs read access to pods, namespaces and sometimes replicasets. Grant only the verbs and resources the chosen association rules require, bind them through a dedicated ServiceAccount, and avoid cluster-wide secret or node-proxy permissions. Review the ClusterRole after each Collector upgrade, because newer components can request additional resources. Confirm the role with a test that lists what the service account can actually do.

Kubernetes authentication

Read-only host log mounts

The filelog receiver reads /var/log/pods and related paths on the node, so the DaemonSet mounts host directories. Mount them read-only, limit the mount to the log directories rather than the whole filesystem, and keep the Collector's own storage directory on a separate writable volume. Check that no other host path, such as the container runtime socket, is mounted unless a named component needs it.

Pod Security Standards for the DaemonSet

Log agents often run as root and need host paths, which places them outside the restricted profile. Decide which Pod Security Standards level the collector namespace enforces and document each exception, such as host path volumes. Disable privilege escalation where possible, drop unused Linux capabilities and set a read-only root filesystem. Record the exceptions so a reviewer can see exactly what the agent is allowed to do on the node.

Pod Security Standards

Secrets for exporter credentials

Exporter tokens and client certificates for the log backend should not sit in plain ConfigMaps or Helm values committed to Git. Kubernetes stores Secrets unencrypted in etcd by default, so enable encryption at rest and restrict list and watch access with RBAC. For stricter control, load credentials from an external store through the Secrets Store CSI Driver. Ask who can read the Secret in each namespace before go-live.

Secrets good practices

Collector configuration storage and listeners

The Collector configuration describes what is read and where it is sent, so treat it as sensitive. Store it in version control with restricted write access and keep credentials out of it. Confirm that receiver and extension endpoints bind to localhost by default in current releases, and only expose a port when a named client needs it. Add an authenticator extension if any incoming connection reaches the agent.

Collector security practices

Redaction of sensitive log content

Container logs often contain tokens, email addresses, card numbers or patient identifiers that application teams did not intend to ship. Apply the redaction processor in the pipeline so sensitive attributes and matched patterns are removed before export, and test rules against sample log lines from each workload. Redaction at the node protects the backend, but it does not replace fixing the application that wrote the value.

Replacing Fluent Bit or Fluentd without losing logs

The safe way to replace a Fluent Bit or Fluentd agent is to run the OpenTelemetry Collector beside it for a period, prove that both paths deliver the same records, and only then remove the old agent. Start with an inventory: every DaemonSet and node-level log path, every parser and multiline rule, every field the old agent adds or renames, every destination and index or label scheme, and every alert, dashboard and saved query that depends on those names. Most log loss during migrations comes from a field or label that changed silently, not from the new agent failing, so the inventory should list the exact keys downstream systems read. Also record the container runtime log format on each node pool, since parser rules written for one format often need adjusting for another.

Next, pick the backend before you pick the agent. Loki accepts OpenTelemetry logs over HTTP and also accepts Fluent Bit, Fluentd and the Docker logging driver, according to the Loki send data documentation, but the label mapping, stream cardinality and tenant header behavior should be confirmed for your chosen store and version before you switch. Run both agents in parallel with separate destinations or a distinct tenant or stream label, so duplicate ingestion is visible and cannot be mistaken for real traffic. Compare record counts per namespace and per container over a fixed window, check that parsed timestamps match, and confirm that the old agent's offsets and buffers are not lost when you stop it. Keep the old agent's configuration in version control until the comparison has passed.

Questions teams ask before collecting container logs with OpenTelemetry

What drives the cost of collecting Kubernetes container logs with OpenTelemetry?

The cost comes from the people doing the work, the infrastructure that runs the pipeline and the log storage you pay for afterward. The engineering effort depends on how many clusters, node pools and log formats are in scope, how much parsing and enrichment you need, and how many destinations the logs go to. Infrastructure cost follows log volume, because the Collector agents, any gateway tier and the backend all scale with it. Ongoing costs include Collector upgrades, configuration changes and storage growth. Ask any partner for a quote that separates one-time build work from recurring operations, names each backend and retention assumption, and states which log volumes the sizing is based on.

How long does a container log collection project take?

Duration depends on scope more than on the Collector itself. The main variables are the number of clusters, the number of distinct log formats, whether you need pod metadata enrichment, how many backends receive the data, and whether existing Fluent Bit or Fluentd agents must be replaced in phases rather than in one change. Pilot validation on a single non-production cluster usually comes first, followed by a staged rollout with parallel running. A written scope should give phases, deliverables and acceptance checks, so ask for a timeline tied to those items rather than a generic estimate.

What does the work need from our platform and security teams?

Platform teams usually provide cluster access, a place to run the DaemonSet, RBAC approval for the service account, and a change process for rolling out the agent on every node pool. Security teams should review what the agent can read on the host, because the filelog receiver reads container log files from node paths, and whether logs contain secrets or personal data that need redaction before export. The OpenTelemetry security guidance recommends storing Collector configuration securely, using encryption and authentication, and using the redaction processor to remove sensitive attributes. Agree on these reviews at the start so they do not hold up the rollout.

Can our in-house team build and run this without a partner?

Many platform teams can, provided they already operate Kubernetes and have someone comfortable with Collector configuration. The skills that usually take the longest to build are knowledge of container runtime log formats on your nodes, tuning of the filelog receiver for high volume, handling of multiline logs such as stack traces, and testing that no data is lost during a cutover from an existing agent. Confirm whether your team has time to own the pipeline after handover, including Collector upgrades. A partner can cover the build, the parallel run and the documentation, while your team keeps ownership of day-to-day operations.

How do we choose a backend for the container logs?

Start from how the logs will be queried, retained and access controlled, then match the backend to those needs. Grafana Loki stores compressed log chunks and an index in object storage, so it suits label-based queries and Grafana access, and its licensing is AGPLv3, which your legal team should review. OpenSearch is Apache-2.0 licensed and suits full-text search and log analytics, with role-based access control and audit logs in its Security plugin. Because OpenTelemetry is vendor-agnostic, the Collector pipeline can export to either, but confirm the retention period, storage sizing and authentication design for whichever you pick.

What happens to our existing Fluent Bit or Fluentd configurations?

Existing configurations are usually translated rather than copied, and they are retired only after the new pipeline matches them. The main steps are inventorying each input path, parser, filter and output, mapping them to filelog receiver settings, processors and exporters, and running both agents in parallel so you can compare record counts and field values. Loki accepts logs from Fluent Bit, Fluentd and the Docker logging driver, so you can move the destination first and the agent later. Plan a cutover window for each cluster, and keep the old agent available for rollback until the comparison is clean.

Which parts of the work come after the pipeline goes live?

After go-live, the recurring work includes monitoring the Collector itself, watching for dropped records and memory pressure, upgrading Collector releases, and reviewing retention and storage growth. Collector releases ship signed artifacts, SHA256 checksums and SBOM files, which helps with verifying what you deploy during upgrades. Kubernetes minor versions also change the APIs the agent depends on, so the Collector and cluster upgrade plans should be reviewed together. Ask any provider whether support is delivered as a fixed-scope handover or as a retainer, and what is covered for upgrades and incident response.

Does DeployOpen install and run the log pipeline in our own clusters?

DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside the client's own infrastructure, including their cloud accounts, data centers or air-gapped networks. For container log collection, that means designing the DaemonSet and Collector configuration, the enrichment and redaction steps, the backend connection and the cutover from existing agents, within a fixed scope agreed in writing before work starts. Ongoing upgrades and support can be handled under a retainer. DeployOpen does not publish a price list, so a quote follows from the written scope.

Limits and what to confirm in your environment

The facts in this topic describe the open-source projects at a point in time, but your distribution, container runtime and backend settings decide what actually works. The cards below list the items to verify with the component documentation, your vendor or your own test cluster before you size the design or write a quote.

Filelog and k8sattributes stability

Each Collector component carries its own stability level, documented in its README, and the log collection and Kubernetes metadata components may not sit at the same level. Check the stability level of each component in your exact Collector build before you rely on it for production log paths. Record the level in your design review so that a later upgrade does not change a component you depend on without notice.

OpenTelemetry status

Runtime and log format support

Parsing depends on which container runtime writes the log files on your nodes and how your distribution configures it. Confirm the log format each node actually writes and test the parsing operators against lines from your own workloads, including multi-line stack traces and very long lines. Do not assume that a format works on one node pool because it works on another.

Backend retention and tenancy settings

Log backends set retention and tenant isolation in their own configuration, and the Collector cannot enforce either. Confirm whether retention is enabled in your backend and at what scope it applies, and whether tenant identifiers are required on each request. A log pipeline that works in a test cluster can still store data indefinitely or mix tenants if these settings were left at defaults.

Loki retention docs

Kubernetes version support

The Kubernetes project maintains only its three most recent minor releases, so the cluster version sets how long your log pipeline and its RBAC rules remain supported without a cluster upgrade. Confirm the end-of-life date for your cluster version against the release policy and plan the Collector upgrade alongside the cluster upgrade. Check version skew rules too, because the kubelet and API server versions decide which node log paths you can rely on during a rolling upgrade.

Minor releases maintained
3
Kubernetes releases

Collector release cadence

Collector releases arrive every few weeks, and each release can change component behavior, configuration keys or defaults. Set a named owner and a fixed review window for each new release, and pin the image version in your deployment so that upgrades are deliberate. Ask your team to confirm how their chosen distribution packages signed artifacts, checksums and SBOM files before they enter your registry.

Latest release cited
v0.163.0
Collector releases

Where to read the official documentation

Start with the Collector configuration reference before you write the filelog receiver block, because the receiver's operators, the k8sattributes processor and the exporter settings all depend on the exact keys in your Collector version. The Collector configuration page explains how receivers, processors and exporters chain into a pipeline, and it is the reference your team will return to when a config change fails validation. Check the component README for each receiver and processor you plan to use, since stability levels differ between components and a container log parser may be less mature than a basic exporter. Pin the Collector version you test against, and confirm which distribution (core or contrib) contains the filelog receiver in that release.

Read the security best practices page before the DaemonSet reaches a cluster that carries regulated data. The Collector configuration best practices guidance covers storing configuration securely, encrypting and authenticating endpoints, building only the components you need and using the redaction processor. For container logs, the practical question is what ends up in stdout: application secrets, tokens and personal data can all be written to logs, and the redaction processor is the control that removes them before export. Decide who may read the Collector's configuration and mounted host paths, because a DaemonSet that reads /var/log/pods has access to every pod's logs on its node.

Use the Loki send data page to confirm backend fit before you commit to an export format. The Loki send data documentation lists the ingestion paths Loki accepts, including OpenTelemetry logs over HTTP, and it notes that Grafana Alloy is Grafana's supported log shipper. Compare those paths with your current Fluent Bit or Fluentd output, and confirm which Loki tenant and label conventions your existing dashboards expect. If your target is OpenSearch or another store, check its documented ingestion path in the same way, since the Collector exporter you need may differ from the Loki one.

How DeployOpen works on this

DeployOpen scopes container log collection as a written, fixed-scope engagement covering the DaemonSet agents, parsing rules, metadata enrichment and the back end they feed, all inside your clusters and infrastructure. We build and test the pipeline in a non-production cluster first, then hand over configuration, runbooks and a support path.

How we scope

  • Inventory every cluster, node pool and container runtime that will produce logs, plus the log formats each workload emits.
  • Confirm which existing agent, such as Fluent Bit or Fluentd, is being replaced and which destinations must keep receiving logs during cutover.
  • Agree in writing the parsing rules, metadata fields, retention expectations and access model before any build work starts.

How we build

  • Deploy the Collector as a DaemonSet with the filelog receiver reading node log paths, using the Collector builder to include only the components you need.
  • Configure parsing for your container runtime format, enrich entries with pod metadata, and apply redaction to sensitive attributes before export.
  • Test volume, dropped records, multiline stack traces and restart behavior in a staging cluster before any production rollout.

How we hand over

  • Deliver versioned Collector configuration, Helm values or Operator manifests, and the RBAC definitions that the pipeline requires.
  • Document the parsing rules, field mappings, back-end settings and the verification steps your team can repeat after each change.
  • Walk your platform and security teams through the runbook, including how to confirm that logs from every node reach the back end.

How we support

  • Ongoing support, Collector upgrades and continuous testing are available as retainers after the initial handover.
  • Upgrades are planned against the Collector release notes, with the configuration retested before each change reaches production.
  • Ask any provider to confirm response expectations, upgrade responsibilities and who owns the back-end storage in writing.

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.