Gotcha: kubectl logs shows the new container, not the crashed one
On a crash loop, plain kubectl logs often shows a clean startup. The error is in --previous.
Gotcha: kubectl logs shows the new container, not the crashed one · #kubernetes #logs #debugGotcha
The surprise: the pod is in CrashLoopBackOff, but kubectl logs <pod> shows a perfectly normal startup, or nothing at all.
Why: kubectl logs reads the current container instance, which has just been restarted. The stack trace lives in the previous instance’s log.
Fix / do this instead: Kubernetes: Show logs of the previous crashed container
kubectl logs <pod> -n <namespace> --previousFor multi-container pods add -c <container>; otherwise you get the first container, which is often the sidecar.
My DevOps Playbook by Angelo John Calleja