Kubernetes Curriculum
On this page
- Logging Architecture
- Docker Container Logs
- Three-Layer Logging Architecture
- What Gets Logged?
- Node-Level Logging
- Log Retention
- Cluster-Level Logging (Centralized)
- Common Logging Patterns
- Pattern 1: Sidecar Container
- Common Mistakes
- Mistake 1: Log to File Only
- Mistake 2: No Structured Logging
- Log Levels
- Kubectl Logs Command
- Logging Best Practices So Far
- Summary
Logging Architecture
You just deployed an application to Kubernetes. A customer reports a bug. You need logs.
Kubernetes logs are temporary. A pod crashes, logs disappear. A node dies, all logs gone.
Centralized logging solves this:
This chapter covers how logs flow through Kubernetes and how to capture them before they disappear.
The Problem With Default Logging
Docker Container Logs
What happens:
- Container writes to stdout/stderr
- Docker runtime captures it
- Stored in
/var/lib/docker/containers/... - Pod deleted? Logs deleted.
Real scenario:
Three-Layer Logging Architecture
What Gets Logged?
Example application logs:
All of this goes to kubectl logs.
Node-Level Logging
Each node runs kubelet. Kubelet captures container stdout/stderr.
Log Retention
By default, logs are kept for a limited time:
Problem:
Cluster-Level Logging (Centralized)
Solution: Aggregate logs from all nodes to central storage.
Log aggregator:
- Runs on each node (DaemonSet)
- Reads container logs
- Parses and enriches
- Sends to central storage
- Permanently stored
Common Logging Patterns
Pattern 1: Sidecar Container
App writes to file, sidecar reads file and ships to Elasticsearch.
Common Mistakes
Mistake 1: Log to File Only
Fix: Write to stdout/stderr.
Mistake 2: No Structured Logging
Structured logs can be parsed and filtered.
Log Levels
Example:
Kubectl Logs Command
Logging Best Practices So Far
- Log to stdout/stderr (not files)
- Use structured logging (JSON format)
- Set appropriate log level (avoid DEBUG in prod)
- Add context (request ID, user ID)
- Avoid logging sensitive data (passwords, tokens)
Summary
Kubernetes logging has three layers:
Layer 1 - Pod:
- App writes to stdout/stderr
- Short-term only
Layer 2 - Node:
- kubelet captures logs
- Stores temporarily (/var/log)
- Gets deleted after rotation
Layer 3 - Cluster:
- Log aggregator collects from all nodes
- Sends to central storage
- Permanent retention
Next: File 02 covers node-level logging in detail.