Skip to content

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.

GotchaCreated Updated

Also:CrashLoopBackOff · kubectl logs empty · --previous · k8s · logs look fine but pod restarts

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

Terminal window
kubectl logs <pod> -n <namespace> --previous

For multi-container pods add -c <container>; otherwise you get the first container, which is often the sidecar.

Seen in: Runbook: Fix pod stuck in CrashLoopBackOff

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…