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

  1. View logs: kubectl logs <pod>.
  2. Stream logs: kubectl logs -f <pod>.
  3. View previous container logs: kubectl logs --previous <pod>.
  4. 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=web to 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 logs fails if the Pod has not started or the container has crashed.
  • Large log output can be truncated; use --tail to limit.
  • Logging to files inside the container instead of stdout makes log collection harder.