How do you debug CrashLoopBackOff? (and probes)
A Pod is in CrashLoopBackOff. How do you debug it? How do liveness, readiness and startup probes differ?
TL;DR
CrashLoopBackOff means the container keeps starting and exiting, and the kubelet waits longer between restarts (10 s, 20 s, 40 s, up to 5 minutes). It's a symptom, not a cause. Debug in order: kubectl describe pod (events, exit code, last state), then kubectl logs --previous (the crashed container's logs), then check config, dependencies and probes. The three probes: readiness decides whether the Pod receives traffic, liveness decides whether the container should be restarted, and startup pauses the other probes until a slow-starting app is up.
Key points
Common causes by exit code:
- 1 or other app errors: a bad config, a missing env var or secret, or a dependency that's unreachable at startup. Read the logs.
- 137 (
OOMKilled): the container went over its memory limit. Raise the limit or fix the leak. - 127/126: command not found or not executable (wrong
command, wrong image architecture). - 0 but still restarting: the process finished, but a Deployment expects it to run forever.
- A liveness probe that fails too soon makes Kubernetes kill a healthy-but-slow app over and over.
Probe advice:
- Liveness checks only "is this process stuck?" Never check databases or other dependencies in liveness, or one outage restarts everything.
- Readiness can check dependencies; failing it just removes the Pod from the Service.
- Use a startup probe for apps that take long to boot, instead of a huge
initialDelaySeconds.
Example
kubectl describe pod api-7d9f -n prod # Last State: Terminated, Reason: OOMKilled, Exit Code: 137
kubectl logs api-7d9f -n prod --previous # logs from the crashed run
kubectl get events -n prod --sort-by=.lastTimestampstartupProbe: { httpGet: { path: /healthz, port: 8080 }, failureThreshold: 30, periodSeconds: 5 }
livenessProbe: { httpGet: { path: /healthz, port: 8080 }, periodSeconds: 10 }
readinessProbe: { httpGet: { path: /ready, port: 8080 }, periodSeconds: 5 }Common follow-ups
- How do you get a shell in a crashing container? Override the command to
sleep infinityin a copy (kubectl debug --copy-to), or attach an ephemeral debug container. ImagePullBackOffvsCrashLoopBackOff?ImagePullBackOffmeans the image can't be pulled (wrong tag or registry auth), so the container never started.
What interviewers look for
Tip
A clear debugging sequence (describe, exit code, logs --previous), exit-code meanings, and correct liveness vs readiness use.
- Red flag: liveness probes that check the database.