Skip to content
Commitpedia
Log in Join & edit

Fix: CrashLoopBackOff in Kubernetes

The container starts, exits, and Kubernetes waits longer before each restart. Read the previous container's logs and its exit code to find out why it keeps dying.

Not checked by a trusted editor yet Last edited Outdated?

Edit history of Fix: CrashLoopBackOff in Kubernetes: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

kubectl get pods shows a growing restart count and this status:

NAME                   READY   STATUS             RESTARTS      AGE
api-5d8f7c6b9d-qm4tz   0/1     CrashLoopBackOff   6 (82s ago)   9m

and kubectl describe pod lists events like:

Warning  BackOff  kubelet  Back-off restarting failed container api in pod api-5d8f7c6b9d-qm4tz_shop(...)

CrashLoopBackOff is not an error by itself. It means the container keeps exiting, and the kubelet is waiting before restarting it again. The delay doubles each time (10s, 20s, 40s and so on) up to five minutes, and resets after the container has run for ten minutes without problems. The real cause is whatever makes the process exit.

Step 1: read the logs of the crashed instance

kubectl logs api-5d8f7c6b9d-qm4tz -n shop --previous
kubectl logs api-5d8f7c6b9d-qm4tz -n shop -c api --previous

--previous shows the output of the container that just died. Without it you often see an empty log from the new container that has not started yet. Look at the last lines: a stack trace, “missing environment variable”, “connection refused” or “permission denied” usually names the cause.

Step 2: read the exit code and reason

kubectl describe pod api-5d8f7c6b9d-qm4tz -n shop

Under Last State: Terminated, check Reason and Exit Code:

  • Reason: Error with exit code 1 (or another small number): the application exited on its own. The logs explain why.
  • Reason: OOMKilled, exit code 137: the container went over its memory limit. See the OOMKilled fix.
  • Exit code 137 without OOMKilled: the process was killed with SIGKILL, often after a failed liveness probe.
  • Exit code 0 with Reason: Completed: the process finished normally, but a Deployment expects it to run forever. The command is wrong, or the work belongs in a Job.
  • Exit code 127 or 126: the command was not found or not executable. Check command/args and the image’s entrypoint.

Common causes and fixes

  1. Bad configuration: a missing environment variable, a wrong ConfigMap key, a wrong database URL. Fix the ConfigMap or Secret, then kubectl rollout restart deployment/api -n shop, because environment variables are only read at start.
  2. A dependency is not reachable: the app exits when the database is down. Make it retry instead of exiting, or check the dependency with a readiness probe.
  3. Liveness probe too strict: the event list shows Liveness probe failed and then Killing. The app needs more time to start. Add a startupProbe or raise failureThreshold and periodSeconds; do not make liveness depend on other services.
  4. Out of memory: raise the memory limit or fix the leak.
  5. Permissions: the image expects to run as root or write to a read-only filesystem, but the Pod’s securityContext forbids it. The log typically says “permission denied”.
  6. Wrong command: command in the manifest overrides the image ENTRYPOINT and args overrides CMD; a typo there exits immediately.

Step 3: inspect the container interactively

If the container dies too fast to look inside, start a copy of the pod with a shell instead of the normal command, investigate, then delete the copy:

kubectl debug api-5d8f7c6b9d-qm4tz -n shop -it --copy-to=api-debug --container=api -- sh
kubectl delete pod api-debug -n shop

This works only if the image contains a shell. For a minimal image, use kubectl debug with a separate --image=busybox:1.36 and --share-processes on the copy.

Step 4: confirm the fix

kubectl rollout status deployment/api -n shop
kubectl get pods -n shop -l app=api -w

The restart count stops growing and the pod stays Running with READY 1/1. If a new release introduced the crash, kubectl rollout undo deployment/api -n shop restores the previous version while you investigate.

Official documentation

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

  • 0139 Collect describe, events and logs of a failing Kubernetes pod A bash script that saves a pod's status, describe output, events, YAML, current and previous logs of every container and its node… Intermediate · Step by step · Linux, macOS Script Troubleshooting 15 Oct 2026
  • 0140 kubectl cheat sheet: the commands you use every day A compact reference of everyday kubectl commands: contexts and namespaces, listing and inspecting objects, logs and exec, applying changes, rollouts, scaling and… Beginner · Cheat sheet · Any system Article Concepts · Troubleshooting 15 Oct 2026
  • 0141 List Kubernetes pods that are not Running and Ready A bash script that lists every pod across namespaces that is Pending, failing or running but not ready, with the waiting reason,… Intermediate · Cheat sheet · Linux, macOS Script Troubleshooting 15 Oct 2026
  • 0142 Fix: ImagePullBackOff and ErrImagePull in Kubernetes The pod cannot start because the node failed to pull the container image. Read the "Failed to pull image" event to see… Intermediate · Fixes an error · Linux Article Troubleshooting 15 Oct 2026
  • 0144 Fix: Pod stuck in Pending with “0/3 nodes are available: Insufficient cpu” The scheduler cannot find a node with enough unreserved CPU for the pod's request. Compare the request with node allocatable resources, then… Advanced · Fixes an error · Linux Article Troubleshooting · Workloads & services 15 Oct 2026
  • 0145 Fix: OOMKilled (exit code 137) in Kubernetes A container used more memory than its limit and the kernel killed it. Confirm the reason, measure real usage, then raise the… Advanced · Fixes an error · Linux Article Troubleshooting · Workloads & services 15 Oct 2026

Repos in the wild

  • derailed/k9s derailed/k9s K9s is a terminal UI for Kubernetes that lets you browse resources, read logs, open shells and follow cluster changes from the keyboard. GitHub

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Commitpedia +3,838 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?