Log Aggregation and Streaming
Beginner5 min
Stream and aggregate logs from pods, deployments, and multiple containers using kubectl and label selectors.
Prerequisites
- -kubectl configured
Steps
1
Stream logs from a pod
Follow log output from a specific pod in real time.
$ kubectl logs -f <pod-name>
2
Stream logs from all pods in a deployment
Follow logs from every pod matching a label selector.
$ kubectl logs -f -l app=myapp --all-containers --max-log-requests=10
The --max-log-requests flag limits concurrent log streams. Increase it for deployments with many replicas.
3
View logs from a previous container instance
See logs from a container that crashed and was restarted.
$ kubectl logs <pod-name> --previous
This is essential for debugging CrashLoopBackOff pods since the current container may not have useful output yet.
4
Filter logs by time range
Show logs from a specific time window.
$ kubectl logs <pod-name> --since=1h --timestamps
Full Script
FAQ
Discussion
Loading comments...