Middle
How to diagnose a crashing container in a pod (CrashLoopBackOff)?
sobes.tech AI
Answer from AI
To diagnose a container in CrashLoopBackOff state, follow these steps:
- Get the list of pods and their statuses:
kubectl get pods
- Check the logs of the crashing container:
kubectl logs <pod-name> --previous
The --previous flag allows you to see the logs of the previous container run if it is restarting.
- Describe the pod for errors and events:
kubectl describe pod <pod-name>
Pay attention to the Events section — it may contain reasons for restarts.
-
If the container crashes due to an application error, logs will help identify the cause (e.g., exception, configuration error).
-
If the container crashes due to resource issues (e.g., OOMKilled), this will be visible in the pod description.
-
If necessary, connect to the container (if it starts but crashes later) for additional diagnostics:
kubectl exec -it <pod-name> -- /bin/sh
- Check readiness and liveness probes, as they might be misconfigured and cause restarts.
Thus, the main diagnostics involve viewing logs, describing the pod, and analyzing events.