Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Same pod, restart count keeps climbing
Your pod, orders-api-x2k8p, shows zero of one ready, and the restart count has reached five. That's CrashLoopBackOff. The container keeps crashing, and Kubernetes keeps starting it again, but it waits a little longer each time. It's not a fix; it's a retry loop.
kubectl get podsNAME READY STATUS RESTARTS orders-api-x2k8p 0/1 CrashLoopBackOff 5 (40s ago)
The loop behind the status
The kubelet, the agent on each node, starts the orders-api container. The app crashes and exits with code 1, an exit code being the number a program returns, where anything other than zero means failure. The kubelet schedules a retry, waits, and restarts it. Then the cycle repeats.
Each wait doubles, capped at 5 minutes
Kubernetes doesn't restart immediately each time. The wait starts at 10 seconds, then 20, 40, 80, and 160, doubling until it caps at 300 seconds. By default, it resets after the container runs fine for ten minutes. That growing wait is what the status is describing.
Chart values
| Restart | Wait (seconds) |
|---|---|
| 1st | 10 |
| 2nd | 20 |
| 3rd | 40 |
| 4th | 80 |
| 5th | 160 |
| 6th+ | 300 |
The status is the wait, not the error
CrashLoopBackOff isn't the error. It's the kubelet, the agent on the node that restarts containers, simply waiting before it tries again. The orders-api container already crashed, and the reason it crashed is in what it left behind: the previous logs. That's where the real answer lives.
Read the crashed container's output
Run kubectl logs on the pod, with the --previous flag. That flag matters, because the current container has just restarted and may have printed nothing yet. It shows the last crashed run instead. And there's the cause: DATABASE_URL is not set, then the process exits with code 1.
kubectl logs orders-api-x2k8p --previousStarting orders-api v1.2 Error: DATABASE_URL is not set Process exiting with code 1
Confirm how it died
Describe confirms it. State Waiting is the back-off, the kubelet pausing before the next restart. Last State Terminated is the real crash, with Exit Code 1, which means the app itself exited with an error. A code of 137 would instead point to the container being killed, often for memory.
kubectl describe pod orders-api-x2k8pState: Waiting Reason: CrashLoopBackOff Last State: Terminated Reason: Error Exit Code: 1 Restart Count: 5
Add DATABASE_URL and roll out
The fix is to add DATABASE_URL to the Deployment's env and run kubectl apply. The Deployment rolls out a replacement pod with a new name, because the spec changed. It starts, stays up, and is now Running. Zero restarts. The old orders-api-x2k8p is gone.
CrashLoopBackOff is Kubernetes waiting; the previous container's logs say why.
CrashLoopBackOff is Kubernetes waiting; the previous container's logs say why. It isn't the error itself, just the pause between restarts. So on any CrashLoopBackOff, run kubectl logs with the previous flag first, then use describe pod to confirm the exit details before you fix and apply.
