Logging architecture
Where container logs go on a node, how kubelet rotation loses them, node-level agents like Fluent Bit versus sidecars, and logs from the control plane.
Debugging Pods: describe, logs, events and ephemeral containersDaemonSetsMetrics and monitoring
Logging architecture
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Containers should log to stdout and stderr. The runtime writes each stream to a file under /var/log/pods/<namespace>_<pod>_<uid>/<container>/<restart>.log, and kubectl logs reads it through the kubelet.
- Kubernetes has no log storage. The kubelet rotates files at 10 MiB and keeps 5 by default, and a deleted Pod's logs go with its directory, so anything you need later must be shipped off the node.
- The standard pattern is a node-level agent: a DaemonSet (Fluent Bit, Vector, the OpenTelemetry Collector) tailing those files, adding Pod metadata from the API, buffering, and sending to a backend.
- Sidecars are for apps that can only log to files, or for per-app routing. They cost a container per Pod, so use them as the exception.
- Control-plane components log too, in klog's structured text or JSON. On managed clusters, API server and audit logs come through the provider's logging service.
- Index on a few bounded labels (namespace, app, container, level) and search the message text. Unbounded labels make log stores like Loki as expensive as high-cardinality metrics.
The logs vanish when you need them
During an incident, the Pod that crashed is replaced, the node it ran on gets drained, and by the time someone opens a terminal, kubectl logs says the Pod doesn’t exist. Kubernetes doesn’t store logs. It keeps the most recent output of running containers on each node, briefly, and that’s all. Anything durable is an architecture you add: how logs get off the nodes, where they go, and how you find the right lines later.
Where container logs live
The convention is simple: write to stdout and stderr. The container runtime captures both streams and writes them, one line per record, to files laid out by the kubelet. From the kubelet source (kuberuntime/helpers.go, defaults.go):
/var/log/pods/<namespace>_<pod-name>_<pod-uid>/<container>/<restart-count>.log
/var/log/containers/<pod>_<namespace>_<container>-<container-id>.log -> symlink to the above
Each line is in the CRI log format, a timestamp, the stream, a full-or-partial flag, and the message:
2026-11-29T00:31:41.512Z stdout F {"level":"info","msg":"order created","order":"8812"}
kubectl logs doesn’t read these files directly. The API server proxies the request to the node’s kubelet, which serves the current file. That’s why, as the debugging lesson showed on the lab cluster, logs fails when the node is unreachable even though get works.
Rotation and retention
The kubelet rotates these files itself. Its configuration defaults, from pkg/kubelet/apis/config/v1beta1/defaults.go in v1.37.3:
containerLogMaxSize: 10Mi
containerLogMaxFiles: 5
containerLogMaxWorkers: 1
containerLogMonitorInterval: 10s
So each container keeps at most about 50 MiB of history on the node, often much less in time for a busy service, and kubectl logs reads only the current file. --previous reads the previous container instance, not older rotated files. When a Pod is deleted, its log directory goes too. A node that’s replaced takes everything with it.
That’s the core argument for shipping logs: the node is a buffer, not a store.
Pattern one: a node-level agent
The standard design runs one log agent per node as a DaemonSet:
apiVersion: apps/v1
kind: DaemonSet
metadata: {name: fluent-bit, namespace: logging}
spec:
selector: {matchLabels: {app: fluent-bit}}
template:
metadata: {labels: {app: fluent-bit}}
spec:
serviceAccountName: fluent-bit # get/list/watch pods, namespaces
tolerations: [{operator: Exists}] # run on every node, tainted or not
containers:
- name: fluent-bit
image: cr.fluentbit.io/fluent/fluent-bit:5.2.1
volumeMounts:
- {name: varlog, mountPath: /var/log, readOnly: true}
volumes:
- name: varlog
hostPath: {path: /var/log}
(Trimmed from the shape of the Fluent Bit Helm chart, and not run here.) The agent tails /var/log/containers/*.log, parses the CRI format and any JSON in the message, and enriches each record with the Pod’s namespace, labels and annotations, either from the API server or the kubelet. It buffers in memory or on disk when the backend is slow, then sends to one or more destinations: Loki, Elasticsearch or OpenSearch, a cloud logging service, or S3. Fluent Bit, Vector and the OpenTelemetry Collector are the common choices. One agent per node keeps the cost fixed whatever the number of Pods, and apps need no changes.
Its tolerations matter. An agent that doesn’t run on tainted nodes leaves exactly those nodes (GPU pools, system nodes) unlogged. The agent also needs a memory limit and a sensible buffer, or a backend outage turns into an OOM-killed agent and lost logs.
Pattern two: sidecars
Some apps can only write to files: several logs at once, or a legacy app with fixed paths. Two options:
- A streaming sidecar that tails the file from a shared
emptyDirand prints it to its own stdout, so the node agent picks it up like any other container. - A sidecar agent that ships the files directly, useful when one app needs its own parsing or destination.
Both cost a container per Pod. Native sidecars (restartable init containers, in the sidecar lesson) at least start before and stop after the app, so shutdown logs aren’t lost.
Logs from Kubernetes itself
Control-plane components and the kubelet log through klog, now mostly structured: a message plus key-value pairs. Two lines from the lab’s controller manager:
I1129 00:16:43.926398 13340 node_lifecycle_controller.go:1133] "Controller detected that zone is now in new state" zone=":\x00:a" newState="Normal"
I1129 00:38:29.133250 13340 node_lifecycle_controller.go:1133] "Controller detected that zone is now in new state" zone="" newState="Normal"
The prefix is severity (I, W, E), timestamp, process ID and source line. Components accept --logging-format=json for machine parsing and -v for verbosity. On self-managed nodes the kubelet and runtime log to journald (journalctl -u kubelet). Static control-plane Pods log like any container. On managed clusters you don’t see these hosts, so API server, scheduler and audit logs are opt-in exports to the provider’s logging service. Events are not logs. They expire after an hour unless an exporter ships them.
Making logs findable
- Structured app logs (JSON with
level,msg, a request or trace ID) turn searching into filtering, and a trace ID links logs to traces. - Index few, bounded labels. In Loki, labels like namespace, app, container and level are indexed and everything else is searched. Pod names, user IDs and request paths as labels create millions of streams, the same cardinality problem as metrics.
- Redact at the edge. Agents can drop or mask fields, such as tokens and emails, before logs leave the node.
- Set retention by value. Debug logs for days, audit logs for months or years.
About the video
The embed is Deploy Masters’ “Kubernetes Logs ➡️ FluentBit ➡️ Grafana Loki (The Easy Way!)”, May 2026, 26 minutes. Going by its detailed chapters, it explains Fluent Bit’s pipeline (inputs, processors for masking, parsers, filters, buffers and routing), the move from classic .conf files to YAML, then deploys Fluent Bit as a DaemonSet with Helm, sends logs to Loki, adds the Kubernetes filter for metadata, and shows why label indexing matters. The first minute recaps an earlier Loki episode. I judged it from chapters and description only, since transcripts couldn’t be fetched. English was judged from its “English (US) original” audio track. Aditya Joshi’s 2022 video in deeper builds the Elasticsearch and Kibana version.
What was run: the log path layout and rotation defaults were read from the kubelet source in the v1.37.3 checkout, and the klog lines are real output from the lab’s kube-controller-manager. No container ran, so no container log file existed. The CRI log line is the documented format with an illustrative message, and the DaemonSet and agent behaviour are from the Kubernetes logging docs and Fluent Bit docs, checked 2026-11-29.
Where this fits
All of this has to survive the cluster changing underneath it. Next: upgrading a cluster.
Check yourself
A Pod was deleted during an incident, and now kubectl logs says it isn't found. Where did the logs go?
They lived only in the Pod's directory on its node, which the kubelet removes with the Pod. Without an agent shipping them elsewhere, they're gone. That's why cluster-level logging is an add-on you have to run.
kubectl logs only shows the last few minutes of a chatty service. Why?
The kubelet rotates container log files at containerLogMaxSize (10 MiB by default) and kubectl logs reads only the current file. Older rotated files are left to the node agent, which is where history should come from.
When would you choose a sidecar over a node-level DaemonSet agent?
When the app can't write to stdout, for example a legacy app writing several log files, or when one app needs different parsing or a different destination. A sidecar can tail the files and print them to its own stdout, or ship them directly.
Why does a Fluent Bit DaemonSet need RBAC permissions on Pods?
Its Kubernetes filter enriches each record with Pod labels, annotations and namespace by looking them up in the API (or from the kubelet). It needs get, list and watch on pods and namespaces to do that.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.