How to check Pod logs?
· Category: Kubernetes
Short answer
Use kubectl logs to view container logs in a Pod. Add -f to stream, --previous to see logs from a crashed container, and --all-containers for multi-container Pods.
Steps
- View logs:
kubectl logs <pod>. - Stream logs:
kubectl logs -f <pod>. - View previous container logs:
kubectl logs --previous <pod>. - View logs from all containers:
kubectl logs --all-containers <pod>.
Example
kubectl logs mypod
kubectl logs mypod -c mycontainer
kubectl logs -f mypod
kubectl logs --previous mypod
Tips
- Use
kubectl logs -l app=webto stream logs from all Pods matching a label. - Export logs with
kubectl logs mypod > app.log. - Use tools like Stern for multi-pod log aggregation.
Common issues
kubectl logsfails if the Pod has not started or the container has crashed.- Large log output can be truncated; use
--tailto limit. - Logging to files inside the container instead of stdout makes log collection harder.