Your deployment is up, but one pod keeps restarting. The status says CrashLoopBackOff. What now?
Start with one important distinction: CrashLoopBackOff is a retry delay, not the root cause. The container has repeatedly failed, and Kubernetes is waiting before trying again. Your job is to find out why it exited.
This playbook walks through the evidence in a useful order, with a small lab you can reproduce locally.
The five commands I start with
Replace the namespace, pod and container names with yours:
kubectl get pods -n demo
kubectl describe pod <pod-name> -n demo
kubectl logs <pod-name> -n demo -c <container-name> --previous
kubectl logs <pod-name> -n demo -c <container-name>
kubectl get events -n demo --sort-by=.lastTimestamp
For a single-container pod, you can omit -c <container-name>. If the container has never restarted, previous logs may not exist. If an init container is failing, select its name with -c too.
What to look for:
-
Last State and Reason: Did the process exit with an error? Does Kubernetes report
OOMKilled? - Events: Are probes failing? Is there a mount or configuration error?
- Previous logs: What did the application say just before it exited?
- Restart count: Is it still climbing after your change?
A safe lab: make a container fail
Use a disposable local cluster such as kind or minikube. This creates a separate namespace and a pod that exits deliberately:
kubectl create namespace crashlab
kubectl run crash-demo -n crashlab --image=busybox:1.36 --restart=Always -- \
sh -c 'echo "Starting application"; echo "ERROR: DATABASE_URL is missing"; exit 1'
kubectl get pod crash-demo -n crashlab -w
After a few restarts, stop the watch with Ctrl+C. Then inspect the failure:
kubectl describe pod crash-demo -n crashlab
kubectl logs crash-demo -n crashlab --previous
The log message is simulated: the command intentionally prints it before exiting. In a real application, you would use that message to investigate the app’s configuration and deployment, then make the appropriate change in its source manifest or deployment pipeline.
Clean up the lab when you are done:
kubectl delete namespace crashlab
Four common causes—and what to check
1. Application or configuration error
A process may exit because an environment variable is missing, an argument is invalid, or a dependency cannot be reached. Read the previous logs first, then compare the workload configuration with what the application expects. Avoid printing secret values into shared logs or tickets.
A missing required Kubernetes Secret or ConfigMap can prevent the container from being created at all, often resulting in CreateContainerConfigError instead of a crash loop. Check events before assuming the app started.
2. Memory limit exceeded
If the container’s last termination reason is OOMKilled, investigate memory consumption and its configured limit. Exit code 137 alone does not prove an out-of-memory kill; it indicates termination by SIGKILL and needs context.
kubectl describe pod <pod-name> -n demo
kubectl top pod <pod-name> -n demo --containers
kubectl top requires a working metrics pipeline and shows current usage, so it may miss a short spike before a restart. Check your monitoring history and application behavior, then adjust the limit or fix the underlying memory use based on evidence.
3. A liveness probe that is too aggressive
A liveness probe can restart an otherwise healthy application if it targets the wrong port or path, or starts checking before the app is ready. Inspect events for probe failures and compare the probe against the app’s actual health endpoint.
For slow-starting services, consider a startup probe. Once it succeeds, liveness and readiness probes take over. A readiness probe removes an unready pod from service traffic; a failed liveness probe can trigger a restart.
4. A dependency fails during startup
A database or external API might not yet be available. Application logs often show connection timeouts, DNS errors or refused connections. Verify the service name, port and network path. Where appropriate, implement bounded retries and backoff in the application rather than relying on restarts as a retry strategy.
Verify the fix
After updating the source manifest and deploying through your normal workflow:
kubectl rollout status deployment/<deployment-name> -n demo
kubectl get pods -n demo -w
kubectl describe pod <new-pod-name> -n demo
kubectl logs <new-pod-name> -n demo -c <container-name>
Confirm that the new container stays running, passes readiness checks and serves a real request. Watch the restart count over a meaningful period; one green snapshot is not proof that the problem is gone.
A useful habit: preserve the error and relevant events before restarting or deleting anything. A restart may temporarily change the symptom while removing evidence you needed.
Want to practice further?
I create paid study resources for developers learning DevOps. If you want a structured companion for your Kubernetes practice, check out my CKA Complete Study Guide. For broader practice across tools, there is also my DevOps Complete Pack. These are my own products; the troubleshooting steps above are free to use.
Over to you: What is the most surprising reason you have seen a Kubernetes container restart? Share the clue that helped you find it.
Top comments (0)