Kubernetes Log Pipeline: From OpenTelemetry Collector to Loki
Log sources and collection boundaries
Section titled āLog sources and collection boundariesāBy default, Kubernetes container logs go to stdout/stderr, and kubelet writes them to files on the node under /var/log/pods/<namespace>_<pod>_<uid>/<container>/*.log. This environment collects directly from that path.
Because logs are generated independently per node, collection has to happen per node too. Regardless of which node an application pod lands on, a log agent must already be running there to tail without gaps, which is why otel-loki is deployed as a DaemonSet.
otel-loki DaemonSet configuration
Section titled āotel-loki DaemonSet configurationāfilelog receiver
Section titled āfilelog receiverāreceivers: filelog: include: - /var/log/pods/*/*/*.log exclude: - /var/log/pods/*/otel-collector*/*.log start_at: end include_file_path: true include_file_name: false operators: - type: container id: container-parserinclude targets every pod log, but workloads that could create a collection loop, such as the Collectorās own logs, are excluded at a category level. The container operator parses the CRI log format (logtag, timestamp, stream) into normalized fields.
Processor order and Kubernetes attributes
Section titled āProcessor order and Kubernetes attributesāprocessors: k8sattributes: auth_type: serviceAccount extract: metadata: - k8s.namespace.name - k8s.pod.name - k8s.container.name - k8s.node.name resource: attributes: - key: loki.resource.labels value: "k8s.namespace.name,k8s.pod.name,k8s.container.name" action: insert memory_limiter: check_interval: 5s limit_percentage: 80 batch: send_batch_size: 1024 timeout: 5sk8sattributes attaches pod metadata via the kubelet API, and the resource processor selects a subset of it as Loki label candidates. Which attributes get promoted to labels is the key decision covered next.
Loki label design: why high-cardinality labels are avoided
Section titled āLoki label design: why high-cardinality labels are avoidedāLoki creates a separate stream for every label combination. Putting a field with unbounded value variety (request IDs, timestamps) into a label triggers cardinality explosion, blowing up ingester memory and index size together.
So this pipeline only promotes namespace, pod, and container to loki.resource.labels, leaving everything else (request path, trace ID, etc.) in the log line body to be queried with LogQL line filters like |= and | json. Itās a trade-off: keep label count low, pay the filtering cost at query time instead.
- Promoted to labels:
namespace,pod,container,node - Not promoted: request ID, user ID, arbitrary dynamic values
The full log pipeline
Section titled āThe full log pipelineāfilelog ā k8sattributes ā resource ā memory_limiter ā batch ā OTLP HTTP exporter ā Loki
Loki Distributed configuration
Section titled āLoki Distributed configurationā- distributor, ingester, querier, query-frontend, query-scheduler, index-gateway, and gateway are each deployed as separate workloads, mostly at 1 replica.
- The schema is TSDB v13, backed by Azure Blob object storage.
- In this snapshot, authentication is disabled, and the ruler/canary/extra cache layers are not used, a simplification choice for the development environment.
# Loki storage/schema configuration (generalized)storage_config: azure: account_name: <redacted> container_name: <redacted> tsdb_shipper: active_index_directory: /var/loki/tsdb-index cache_location: /var/loki/tsdb-cache
schema_config: configs: - from: "2024-01-01" store: tsdb object_store: azure schema: v13 index: prefix: loki_index_ period: 24h
limits_config: retention_period: 24hRetention and cost
Section titled āRetention and costāThe 24h retention reflects a judgment call for this development environment: ābeing able to quickly debug a recent issue is enough.ā Workloads that need long-term retention or auditing would require a separate retention policy (e.g., per-namespace overrides), and this pipeline deliberately kept the label scheme simple to leave room for that extension later.
Failure and operational perspective
Section titled āFailure and operational perspectiveā- Node collector failure: if a nodeās
otel-lokipod dies, only that nodeās logs are lost. Other nodes are unaffected, the benefit of the DaemonSet layout. - Backend transient failure: the batch processorās buffer is finite, so if the Loki gateway stops responding beyond some threshold, the oldest batches can be dropped. This environment doesnāt configure separate disk buffering.
- Label explosion: carelessly promoting a dynamic attribute to a label when adding a new workload can spike ingester memory almost instantly. Adding a new label should always go through review.
Verification approach
Section titled āVerification approachā- Log arrival: confirm the target namespace/podās logs are queryable via the Loki datasource in Grafana Explore.
- Labels: confirm streams split as expected in the form
{namespace="...", pod="..."}. - Query: confirm LogQL line filters (
|= "error") work correctly after the label-based query. - Pod metadata: confirm fields like
k8s.pod.nameattached by k8sattributes actually appear in the log line.
Next post
Section titled āNext postāThe metric pipeline continues in Kubernetes Metrics Pipeline: From Exporters and OTel Collector to Mimir.