Kubernetes Logging Architecture
What you'll learn: How Kubernetes collects, routes, and manages logs from containers and cluster components.
The Kubernetes Logging Model
Kubernetes doesn't provide a built-in logging solution, but instead offers logging architecture patterns you implement yourself. Think of it like plumbing: Kubernetes provides the pipes and outlets (stdout/stderr streams), but you choose the collection and storage system.
Application Logs: stdout and stderr
Containers should write logs to stdout (standard output) and stderr (standard error). Kubernetes automatically captures these streams. When you run kubectl logs <pod-name>, you're reading what the container wrote to stdout/stderr.
# View logs from a specific container
kubectl logs my-pod -c my-container
# Follow logs in real-time
kubectl logs -f my-pod
This works because the container runtime (like containerd or CRI-O) redirects these streams to files on the node.
Node-Level Logging
On each node, container logs are stored as files (typically in /var/log/containers/). The kubelet and container runtime manage log rotation to prevent disk overflow. However, when a pod is deleted, these logs disappear—they're ephemeral.
Cluster-Level Logging Patterns
For persistent logs, you need cluster-level logging:
- Node-level agent: Deploy a DaemonSet (like Fluent Bit) that reads container logs from each node and ships them to a central system
- Sidecar container: Add a logging container to pods that processes and forwards logs
- Direct application export: Applications send logs directly to a logging backend
Most production clusters use the node-level agent pattern—it's resource-efficient and doesn't require modifying pod definitions.
Key Takeaway: Kubernetes captures container stdout/stderr automatically at the node level, but you must implement cluster-level logging (typically via DaemonSets like Fluent Bit) to aggregate, persist, and search logs centrally.