I broke five Deployments on purpose in a lab cluster. A missing env var, a command that doesn't exist in the image, a memory limit that's too low, a migration written as a Deployment, and a liveness probe on the wrong port.
Then I asked Kubernetes how they were doing.
$ kubectl get pods -n breakfix -o 'custom-columns=NAME:.metadata.name,PHASE:.status.phase,LAST:.status.containerStatuses[0].lastState.terminated.reason,EXIT:.status.containerStatuses[0].lastState.terminated.exitCode,RESTARTS:.status.containerStatuses[0].restartCount' NAME PHASE LAST EXIT RESTARTS cache-warmer-676bdc54f6-b2w97 Running OOMKilled 137 5 db-migrate-657dcb95cd-s45rc Running Completed 0 5 orders-api-5c9f9944f9-tbghc Running Error 1 5 report-worker-66cc4877f7-jpbrt Running StartError 128 5 web-dc8fdcb94-26gqv Running Completed 0 6 PHASE says Running for all five. Every single one was in a crash loop.
The plain kubectl get pods isn't much better. The STATUS word keeps changing between CrashLoopBackOff, Error, RunContainerError and Running, depending on which second you look. The problem underneath doesn't change at all.
Read Last State, not STATUS
That long command above is the first thing I run now. It prints how each pod last died, which is the only part that matters. Keep the single quotes. On a Mac, zsh reads [0] as a file pattern and stops with no matches found.
For one pod, kubectl describe pod <pod> and look for Last State. In the lab I got four different answers.
Reason: Error, Exit Code: 1. The app exited on its own, so ask the app. kubectl logs said FATAL: DATABASE_URL is not set. A missing env var, a missing Secret key, a config file that isn't there.
Reason: StartError, Exit Code: 128. The command in the YAML doesn't exist in the image. Mine said exec: "node": executable file not found in $PATH. Nothing of mine ever ran, so the logs are empty and you can stare at them all day. Check the image itself:
docker run --rm --entrypoint sh <image> -c 'which node' Reason: OOMKilled, Exit Code: 137. The kernel killed it for memory. That's a different problem with a different fix, the limit against what the app really uses.
Reason: Completed, Exit Code: 0. This one confused me. A clean exit, restarting forever. Two causes, and only Events at the bottom of describe tell them apart:
- Only
Back-off restarting failed container: the task really finished. A one-off job, like a migration, written as a Deployment. Kubernetes keeps restarting it because Deployments are supposed to run forever. Make it a Job. -
Container nginx failed liveness probe, will be restarted: Kubernetes is killing a healthy app. The probe was on port 8080 and nginx listens on 80. nginx shuts down cleanly when it gets SIGTERM, so the kill shows up as Completed, exit 0, like nothing happened.
The logs trap
Right after a crash I ran kubectl logs --previous and got this:
unable to retrieve container logs for containerd://d655270519f4302d1bef5757568e3169a73335b068b434af0d55b84cef14658d Plain kubectl logs, same pod, same moment, worked fine. About 20 seconds later, once the pod had moved into back-off, --previous worked too. So if one of them comes back empty, run the other one before deciding there are no logs.
What I check now, in order
- Last State reason and exit code, before opening any logs
- Exit 1:
kubectl logs, then--previousif empty - Exit 128: compare
commandandargswith the image - Exit 0: Events, liveness kill or a job that finished
- Exit 137: memory
- After the fix, watch RESTARTS. When it stops climbing, it's fixed
The two charts behind this, with the full describe output for each case, are in my free Kubernetes sampler. It has the 14 kubectl commands I actually use too. Pay nothing, or what you like.

