Video in progress
A Pod is stuck in CrashLoopBackOff. Which kubectl commands do you use to find the cause?
First I use kubectl describe pod to see the events and the reason for the last exit, then kubectl logs --previous to see the log of the crashed container. Most of the time the answer is in these two.
📖 Answer
CrashLoopBackOff is not a cause, it is a result: the container keeps crashing and the kubelet increases the wait time each time.
kubectl get pod shop-api-7d9f-abcde
kubectl describe pod shop-api-7d9f-abcde
kubectl logs shop-api-7d9f-abcde --previous
kubectl get events --sort-by=.lastTimestamp | tail -20
In the describe output, look at the Last State section:
Reason: OOMKilled,Exit Code: 137: the memory limit was not enough;Exit Code: 1: the app itself exited with an error, and the cause is in the log (often it could not connect to the DB or a property is missing);Liveness probe failedevents: the app starts slowly and the probe kills it before it has finished starting.
The last one is very common with Spring Boot: startup takes 60 seconds, but liveness starts checking after 30. There is no error in the log, the app just never gets to the "Started" line. The fix is a startup probe or a slower liveness.
If the image is not pulled at all, the status is different: ImagePullBackOff, and you check the tag or the registry permissions.
Sign up to mark studied questions and save your progress.