CrashLoopBackOff
- Docker & Kubernetes course
- Intermediate
- Lesson 75/82
- 4 min
Learn to identify the CrashLoopBackOff error.
CrashLoopBackOff
CrashLoopBackOff shows that the container starts and crashes immediately, and that the kubelet restarts it with an increasing wait each time (10 s, 20 s, 40 s ... at most 5 min). It's a symptom, not a cause; the cause is in the container's last log:
$ kubectl get pod api-xyz
NAME READY STATUS RESTARTS AGE
api-xyz 0/1 CrashLoopBackOff 6 (90s ago) 8m
$ kubectl logs api-xyz --previous
Error: DATABASE_URL tanımlı değil
$ kubectl describe pod api-xyz | grep -A2 "Last State"
Last State: Terminated
Reason: Error
Exit Code: 1Exit codes
The exit code narrows down the cause:
1: an application error (look at the log)126/127: the command couldn't run / wasn't found (a wrongcommand)137: SIGKILL; usually OOMKilled or a liveness failure143: shut down cleanly with SIGTERM
kubectl get pod api-xyz -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}'
137Practice The cause of the crash
Write three commands: show the previous container log of api-xyz; print the last exit code with jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}'; set the memory limit of the api container of the api deployment to 512Mi with kubectl set resources.
Starter code
# buraya yazSample solution
kubectl logs api-xyz --previous
kubectl get pod api-xyz -o jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}'
kubectl set resources deployment/api -c api --limits=memory=512MiExpected output
INFO önbellek dolduruluyor (1.2M kayıt) Killed 137 deployment.apps/api resource requirements updated
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 If you see Reason: OOMKilled and Exit Code: 137 in Last State, what is the cause?
- A wrong command
- A network error
- The container exceeded its memory limit Correct answer
- The image wasn't found
Explanation: 137 = 128 + 9 (SIGKILL); the fix is raising limits.memory or finding the leak.
2 Look at the crashed container's output.
kubectl logs api-xyz ____
kubectl logs api-xyz --previous
Explanation: The log of the previous instance of the restarted container.
3 Match the exit codes.
| Term | Meaning |
|---|---|
1 |
Application error |
127 |
Command not found |
137 |
SIGKILL / OOMKilled |
143 |
Closed with SIGTERM |