Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Terminal
Our orders-api pod is stuck at zero of one ready, with status CrashLoopBackOff and five restarts. That status sounds like the problem, but it isn't the actual error. It only tells us something is going wrong. The real cause is hiding somewhere else.
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
orders-api-7d9f8b6c5-x2k4p 0/1 CrashLoopBackOff 5 (40s ago) 6mThe kubelet's restart loop
The kubelet is the agent on each node that actually runs your containers. It starts the container, and our app exits with code 1. The kubelet then waits, a back-off pause, and restarts it. Then the same loop repeats. That waiting is what the status is describing.
Each wait doubles, capped at 5 minutes
By default, the kubelet waits ten seconds before the first restart, then twenty, forty, eighty, and a hundred and sixty. After that, the wait stays capped at three hundred seconds, which is five minutes. Each crash earns a longer pause, so the pod looks stuck even though it keeps retrying.
Chart values
| Restart | Wait (seconds) |
|---|---|
| 1st | 10 |
| 2nd | 20 |
| 3rd | 40 |
| 4th | 80 |
| 5th | 160 |
| 6th+ | 300 |
The status is the wait, not the crash
CrashLoopBackOff isn't the bug. It's the kubelet, our mechanic here, waiting between restart attempts. The real failure happened inside the orders-api container, before each wait, and that's the exit 1 on the sign. So the status tells you when Kubernetes is pausing, not why the app crashed.
Logs from the crashed container
Now we read the evidence. The dash dash previous flag asks for logs from the last crashed run, because the current container may be waiting or just starting, with nothing useful printed yet. Here the app tells us directly: DATABASE_URL is not set. That's the cause.
$ kubectl logs orders-api-7d9f8b6c5-x2k4p --previous
> orders-api@1.0.0 start
> node server.js
Error: DATABASE_URL is not set
at loadConfig (/app/config.js:12:11)Exit code and last state
Describe shows two different states. State Waiting with CrashLoopBackOff is just the kubelet pausing between restarts. Last State Terminated with Exit Code 1 is the app's own failure, which fits the missing variable. The BackOff warning event confirms the kubelet keeps retrying a container that fails.
$ kubectl describe pod orders-api-7d9f8b6c5-x2k4p
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Restart Count: 5
Events:
Warning BackOff kubelet Back-off restarting failed containerFix: add the missing variable
The fix belongs on the Deployment, not the pod. Running kubectl set env adds DATABASE_URL to the orders-api Deployment, which rolls out a new pod. That pod starts as Pending, then becomes Running. Now get pods shows 1 of 1 ready, with 0 restarts.
The status says it keeps crashing; previous logs say why.
The status says it keeps crashing; previous logs say why. CrashLoopBackOff just means the container keeps exiting while the kubelet waits between restarts. So on any CrashLoopBackOff, run kubectl logs with the previous flag first. The reason the last container died is usually sitting right there.
