Skip to content
masdzub.com
~/articles/kubernetes — one from the notebook

Debugging Kubernetes CrashLoopBackOff: A Step-by-Step Checklist

A practical checklist for diagnosing Kubernetes CrashLoopBackOff with kubectl commands, logs, exit codes, probes, and real fixes.

masdzub@website:~$ cat ~/articles/debugging-kubernetes-crashloopbackoff-a-step-by-step-checklist.aspx.md
# 1 file · 19 min read · topic: kubernetes · status: published

Introduction

A pod enters CrashLoopBackOff when its container starts, exits, and is restarted by the kubelet with an increasing delay between attempts. The status name describes the restart behavior, not the root cause. To resolve it, you need to work through a fixed sequence: confirm the pod state and recent events, read current and previous container logs, interpret the exit code, then inspect liveness probes, resource limits, and runtime configuration. The commands and checks below follow that sequence so you can move from a failing pod to a specific fix without guessing.

How CrashLoopBackOff Works

CrashLoopBackOff is a waiting state managed by the kubelet. When a container terminates, the kubelet restarts it according to the pod’s restartPolicy. After repeated failures, the kubelet applies an exponential backoff delay before the next restart: 10 seconds, 20 seconds, 40 seconds, 80 seconds, 160 seconds, and then capped at 300 seconds. The backoff timer resets after the container has run successfully for 10 minutes. This means a pod that crashes every few seconds will spend most of its life waiting, while a pod that crashes after several minutes may look healthy for a while before failing again.

The status you see in kubectl get pods combines several signals. READY shows how many containers in the pod are passing readiness checks, STATUS shows the current high-level state, and RESTARTS shows how many times containers have been restarted, including how long ago the last restart happened.

Terminal window
kubectl get pods -n payments -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
payment-api-6b8f9d7c5-kt4mz 0/1 CrashLoopBackOff 7 (2m10s ago) 14m 10.244.3.22 worker-03 <none> <none>

This output tells you the container is not ready, it has restarted seven times, and the last restart happened two minutes ago. It does not tell you why the process exited. That information lives in pod events, container state, and logs. Treat CrashLoopBackOff as a symptom and start collecting evidence from the pod itself.

Step 1: Inspect Pod Status and Events

The first command to run is kubectl describe pod. It combines scheduling information, container state, last termination details, and recent events in one place. In many cases, the event stream points directly at the failing component before you ever open application logs.

Terminal window
kubectl describe pod payment-api-6b8f9d7c5-kt4mz -n payments
Name: payment-api-6b8f9d7c5-kt4mz
Namespace: payments
Node: worker-03/10.0.2.15
Start Time: Sat, 29 Nov 2026 09:41:12 +0000
Status: Running
Containers:
payment-api:
Image: registry.example.com/payments/api:2.4.1
Port: 8080/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Sat, 29 Nov 2026 09:54:03 +0000
Finished: Sat, 29 Nov 2026 09:54:04 +0000
Ready: False
Restart Count: 7
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 14m default-scheduler Successfully assigned payments/payment-api-6b8f9d7c5-kt4mz to worker-03
Normal Pulled 2m10s (x8 over 14m) kubelet Container image "registry.example.com/payments/api:2.4.1" already present on machine
Normal Created 2m10s (x8 over 14m) kubelet Created container payment-api
Normal Started 2m10s (x8 over 14m) kubelet Started container payment-api
Warning BackOff 105s (x42 over 13m) kubelet Back-off restarting failed container payment-api in pod payment-api-6b8f9d7c5-kt4mz_payments(7f3a...)

When reading this output, focus on Last State before anything else. The Reason and Exit Code tell you how the container died. OOMKilled points to memory pressure, Error with exit code 1 points to an application failure, and Completed with exit code 0 often means a short-lived command ran inside a long-running workload. The event section adds context around the restart. If you see probe failures, missing ConfigMaps, mount errors, or container runtime failures, those messages usually narrow the problem faster than application logs.

Namespace events are also useful when multiple pods fail at the same time, or when the pod has been recreated by a Deployment controller and the old pod is gone.

Terminal window
kubectl get events -n payments --sort-by='.lastTimestamp'

One limitation to keep in mind: Kubernetes events are not permanent. Many clusters keep them for one hour by default. If the incident started earlier, the most useful event may have already expired. In that case, rely on describe, container logs, and your cluster’s logging or monitoring system.

Step 2: Read Current and Previous Container Logs

Logs answer the question that pod status cannot: what the process actually did before it exited. For a crashing container, the previous instance is usually more valuable than the current one, because the current container may be in backoff or may have just started again.

Terminal window
kubectl logs payment-api-6b8f9d7c5-kt4mz -n payments
kubectl logs payment-api-6b8f9d7c5-kt4mz -n payments --previous

The --previous flag reads logs from the terminated container instance. If the pod has multiple containers, you must specify the container name. Adding --tail keeps the output manageable when the application is noisy.

Terminal window
kubectl logs payment-api-6b8f9d7c5-kt4mz -n payments -c payment-api --previous --tail=200

The errors you find here usually fall into clear categories. A missing environment variable looks like an application startup failure:

2026-11-29T09:54:03.882Z ERROR Unable to start server
2026-11-29T09:54:03.883Z ERROR required environment variable DATABASE_URL is not set

A runtime panic in a Go service includes the stack trace and signal:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4a2f13]
goroutine 1 [running]:
main.loadConfig(...)
/app/cmd/server/main.go:47
main.main()
/app/cmd/server/main.go:29 +0x6e

An image built for the wrong CPU architecture fails before the application starts:

exec /usr/local/bin/entrypoint.sh: exec format error

There are cases where --previous returns no useful output. The container may have crashed before writing anything to stdout or stderr, the application may log only to a file inside the container, or the node may have been under pressure. When logs are empty, go back to the exit code and events. If the application writes to a file path, a debug copy of the pod with an overridden command can help you inspect that path.

Step 3: Interpret Exit Codes

Exit codes compress the failure mode into a small integer. They are not always enough to diagnose the problem, but they tell you where to look next. On Linux, exit codes above 128 often mean the process was terminated by a signal, where the signal number is exit_code - 128.

Exit CodeMeaningTypical CauseWhere to Look Next
0Successful exitShort-lived command in a Deployment, or app finished intentionallyPod workload type, command, restartPolicy
1General application errorMissing config, unhandled exception, startup validation failureApplication logs, environment variables, mounted files
126Command invoked cannot executePermission problem, binary not executableImage permissions, entrypoint, securityContext
127Command not foundWrong entrypoint, missing binary, bad PATHImage contents, command/args, Dockerfile
137128 + 9 (SIGKILL)OOMKilled, manual kill, node-level killLast State reason, memory limits, node events
139128 + 11 (SIGSEGV)Segmentation faultApplication logs, native dependencies, core dumps
143128 + 15 (SIGTERM)Graceful shutdown signalRolling update timing, preStop hooks, shutdown handling

Exit code 137 deserves extra attention because it is ambiguous. If kubectl describe pod shows Reason: OOMKilled in the last terminated state, the kernel killed the process for exceeding its memory limit. If the reason is Error or another value, the signal may have come from a manual kubectl delete, a node shutdown, or a runtime issue. Always pair the exit code with the termination reason and node events.

Exit code 0 is another common surprise. A container that exits successfully can still trigger CrashLoopBackOff when it runs under a controller that expects a long-running process. A database migration command placed in a Deployment will complete, exit 0, get restarted, and repeat. The fix is to move that work to a Kubernetes Job, an init container, or a Helm hook, depending on when it needs to run.

Step 4: Check Liveness, Readiness, and Startup Probes

Probe misconfiguration can restart a healthy container. This failure mode is frustrating because the application may be working correctly, but the kubelet kills it after repeated probe failures. The event log usually makes this visible.

Warning Unhealthy 2m (x4 over 2m30s) kubelet Liveness probe failed: HTTP probe failed with statuscode: 503
Warning Unhealthy 90s (x3 over 110s) kubelet Liveness probe failed: Get "http://10.244.3.22:8080/healthz": dial tcp 10.244.3.22:8080: connect: connection refused

A liveness probe tells Kubernetes when to restart a container. A readiness probe tells Kubernetes when to stop sending traffic. A startup probe tells Kubernetes to pause liveness and readiness checks until the application has finished starting. Mixing these up, or setting aggressive thresholds, causes unnecessary restarts.

The following configuration is risky for an application that needs 30 seconds to initialize:

livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3

With these values, the kubelet starts probing after five seconds and allows three failures. If the app is still loading dependencies, opening database connections, or warming caches, it can be killed before it ever becomes healthy. A startup probe gives slow applications a dedicated startup window without making the liveness probe too permissive after startup.

startupProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 5
failureThreshold: 30
livenessProbe:
httpGet:
path: /healthz
port: 8080
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 3
readinessProbe:
httpGet:
path: /readyz
port: 8080
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 3

This setup allows up to 150 seconds for startup. After the startup probe succeeds, the liveness probe takes over with tighter settings. The trade-off is clear: aggressive probes catch deadlocks and hung processes quickly, but they also create false restarts during slow starts, garbage collection pauses, or temporary dependency outages. Conservative probes reduce false restarts, but they leave broken processes running longer. Choose thresholds based on observed startup time and failure behavior, not defaults copied from another service.

Step 5: Verify Resource Limits and OOMKills

Memory limits are a frequent cause of CrashLoopBackOff, especially for Java, Node.js, Python workers with large in-memory datasets, and applications that load machine learning models at startup. When a container exceeds its memory limit, the kernel OOM killer terminates it. Kubernetes reports the termination as OOMKilled, and the exit code is usually 137.

resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "512Mi"
cpu: "500m"

If the process needs 700Mi during startup, this container will be killed repeatedly. You can confirm the pattern in kubectl describe pod:

Last State: Terminated
Reason: OOMKilled
Exit Code: 137
Started: Sat, 29 Nov 2026 10:02:11 +0000
Finished: Sat, 29 Nov 2026 10:02:14 +0000

The kubectl top command is useful when metrics-server is installed, but it has limits. It shows current or recent usage, not the peak memory value at the moment of the OOM kill. A container can spike above its limit between scrape intervals and never appear dangerous in top.

Terminal window
kubectl top pod payment-api-6b8f9d7c5-kt4mz -n payments --containers

For Java workloads, container memory limits and JVM heap settings must be considered together. Setting -Xmx too close to the container limit leaves no room for metaspace, thread stacks, direct buffers, and native memory. For example, a container with a 512Mi limit and -Xmx512m is likely to be killed under load. A safer starting point is to leave headroom or use JVM container-aware flags such as -XX:MaxRAMPercentage, then validate with real workload metrics.

Resource configuration also affects scheduling and eviction. Requests influence where the pod is placed. Limits enforce hard runtime caps. Pods with equal requests and limits fall into the Guaranteed QoS class, which gives them lower eviction priority during node pressure. Pods with requests lower than limits are Burstable. The trade-off is operational: higher requests improve stability but consume schedulable capacity, while tight limits protect the node but can kill legitimate workloads during peaks.

Step 6: Validate Configuration, Secrets, and Volumes

Configuration problems sit between Kubernetes and the application. Some prevent the container from starting at all, while others let the container start and then crash. The distinction matters because the debugging path is different.

A missing ConfigMap referenced by envFrom or a required key referenced by valueFrom usually produces CreateContainerConfigError, not CrashLoopBackOff. You can confirm it with describe:

Warning Failed 12s (x7 over 2m) kubelet Error: configmap "payment-config" not found

If the pod is in CrashLoopBackOff, the container did start. In that case, look for configuration that the application reads at runtime: a mounted file with the wrong path, an invalid JSON or YAML config file, a missing secret key read by application code, or a database URL that points to an unreachable service.

Check that the expected objects exist and that the pod references them correctly:

Terminal window
kubectl get configmap -n payments
kubectl get secret -n payments
kubectl get pod payment-api-6b8f9d7c5-kt4mz -n payments -o yaml

The rendered pod YAML is worth reading carefully. Pay attention to command, args, env, envFrom, volumeMounts, and volumes. A common failure after a Dockerfile change is an image whose default entrypoint changed, while the Deployment still assumes the old command. Another common failure is a mounted volume with permissions that do not match the container user.

Error: failed to start container "payment-api": Error response from daemon:
failed to create task for container: failed to create shim task: OCI runtime create failed:
runc create failed: unable to start container process: error during container init:
open /app/config/config.yaml: permission denied

Permission errors like this can appear as container runtime failures or as application-level errors, depending on when they occur. If the application runs as a non-root user through securityContext.runAsUser, confirm that mounted files and directories are readable by that user. For writable volumes, fsGroup or an init container that fixes ownership may be appropriate, but both have trade-offs. fsGroup changes group ownership behavior for supported volume types, and an init container adds startup complexity and another failure point.

Step 7: Debug Interactively with Ephemeral Containers

When logs and events are not enough, you need to inspect the running pod environment. Ephemeral containers are designed for this. They let you attach a temporary debug container to an existing pod without rebuilding the image. Ephemeral containers became generally available in Kubernetes 1.25, so the command below assumes a modern cluster.

Terminal window
kubectl debug -it payment-api-6b8f9d7c5-kt4mz -n payments --image=busybox:1.36 --target=payment-api

The --target flag enables process namespace sharing with the target container, which is useful for inspecting processes. Inside the debug container, you can check DNS resolution, network connectivity, mounted paths, and file contents. For example, you can verify whether a config file exists at the path the application expects.

Terminal window
ls -la /app/config
cat /proc/1/environ | tr '\0' '\n' | grep DATABASE
nslookup postgres.payments.svc.cluster.local

Ephemeral containers have a limitation in crash scenarios: if the target container exits immediately, you may not have a stable process to inspect. In that case, create a debug copy of the pod and override the command so it stays alive.

Terminal window
kubectl debug payment-api-6b8f9d7c5-kt4mz -n payments -it \
--copy-to=payment-api-debug \
--container=payment-api \, /bin/sh

If the production image does not include a shell, you can replace the image in the copied pod with a debug variant that contains troubleshooting tools. This approach is practical, but it changes the runtime environment. A debug image may have different libraries, users, or filesystem contents. Use it to inspect configuration and network behavior, then confirm the fix in the real image.

Common CrashLoopBackOff Scenarios

The patterns below show how the same status can come from different root causes. Each one maps a symptom to a command, an error, and a fix.

Missing Environment Variable

The pod restarts with exit code 1, and the previous logs show a startup validation error.

2026-11-29T09:54:03.883Z ERROR required environment variable DATABASE_URL is not set

The Deployment references a Secret, but the key name is wrong:

env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: payment-db
key: database-url

If the Secret contains DATABASE_URL instead of database-url, the container may fail to start with CreateContainerConfigError. If the key exists but the application expects a different variable name, or the value is empty and the app validates it at startup, you get CrashLoopBackOff. Check both the Kubernetes object and the application contract.

Terminal window
kubectl get secret payment-db -n payments -o jsonpath='{.data}'

JVM OOMKilled in a Tight Container Limit

The container exits with code 137 and Last State shows OOMKilled. Logs may show no clean shutdown message because the kernel killed the process.

State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: OOMKilled
Exit Code: 137

A common cause is a JVM heap configured too close to the container limit:

resources:
limits:
memory: "512Mi"
env:
- name: JAVA_TOOL_OPTIONS
value: "-Xms512m -Xmx512m"

The fix is not just “increase memory.” You can raise the limit, reduce heap usage, or make the JVM container-aware. A more balanced configuration leaves room for non-heap memory:

resources:
requests:
memory: "768Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "1"
env:
- name: JAVA_TOOL_OPTIONS
value: "-XX:MaxRAMPercentage=75.0 -XX:InitialRAMPercentage=50.0"

The trade-off is cost and scheduling pressure. Larger limits reduce OOM risk but require more node capacity. Lower heap percentages reduce crashes but may increase garbage collection activity.

Wrong Image Architecture

After a CI pipeline change, a pod starts crashing immediately with an execution format error.

exec /app/server: exec format error

This usually means the image was built for a different CPU architecture than the node running it. An amd64 image on an arm64 node, or the reverse, fails before the application can produce meaningful logs. Confirm the node and image architecture:

Terminal window
kubectl get pod payment-api-6b8f9d7c5-kt4mz -n payments -o jsonpath='{.spec.nodeName}'
kubectl get node worker-03 -o jsonpath='{.status.nodeInfo.architecture}'
docker buildx imagetools inspect registry.example.com/payments/api:2.4.1

The long-term fix is to publish multi-architecture images with docker buildx build --platform linux/amd64,linux/arm64. A node selector or node affinity rule can work as a temporary constraint, but it reduces scheduling flexibility and hides the packaging problem.

Troubleshooting Edge Cases

Some CrashLoopBackOff incidents do not fit the standard application-failure pattern. These cases are worth checking when the obvious signals are missing or misleading.

Init Container Failures

If the pod status shows Init:CrashLoopBackOff, the main container never started. The failure is in an init container. You need to target that container explicitly when reading logs and describing state.

Terminal window
kubectl describe pod payment-api-6b8f9d7c5-kt4mz -n payments
kubectl logs payment-api-6b8f9d7c5-kt4mz -n payments -c init-migrations --previous

A failing init container blocks the entire pod. This is useful for dependency checks and migrations, but it also means a bad migration script can prevent every new pod from starting during a rollout.

No Logs and Immediate Exit

When kubectl logs --previous returns nothing and the exit code is 127 or 126, inspect the image command and filesystem. A missing binary, broken shebang, or missing shared library can kill the process before logging is initialized. You can check the configured command and run the image locally or in a debug pod:

Terminal window
kubectl get pod payment-api-6b8f9d7c5-kt4mz -n payments -o jsonpath='{.spec.containers[0].command}{"\n"}{.spec.containers[0].args}{"\n"}'
kubectl run debug-image --rm -it --image=registry.example.com/payments/api:2.4.1 --restart=Never, /bin/sh

If the container image has no shell, use an ephemeral debug container or a copy with a different image. The error standard_init_linux.go:228: exec user process caused: no such file or directory often means the entrypoint script references a missing interpreter, such as #!/bin/bash in a minimal image that only ships /bin/sh.

CrashLoopBackOff Versus Similar Pod States

Not every failing pod is in CrashLoopBackOff, and treating all failure states the same wastes time. ImagePullBackOff points to image registry, authentication, or tag problems. CreateContainerConfigError points to missing ConfigMaps, Secrets, or invalid key references. RunContainerError and container runtime messages can point to OCI, mount, or security context problems. CrashLoopBackOff specifically means the container started and then exited repeatedly.

This distinction helps you choose the right tool. For image pull failures, inspect image names, pull secrets, and registry access. For config creation failures, inspect referenced ConfigMaps and Secrets. For CrashLoopBackOff, start with logs and exit codes.

A Practical Debugging Checklist

The sequence below is the same one used throughout this guide. It works best when you follow it in order and record what you observe at each step, especially during an incident where multiple people are looking at the same pod.

  1. Confirm the pod status, restart count, and node placement with kubectl get pods -o wide.
  2. Run kubectl describe pod and read Last State, Exit Code, and the Events section.
  3. Pull logs from the current and previous container with kubectl logs and --previous.
  4. Map the exit code to a failure class: application error, OOMKilled, bad command, signal, or clean exit.
  5. Inspect liveness, readiness, and startup probes for aggressive thresholds or wrong endpoints.
  6. Check memory and CPU requests and limits, then confirm whether the termination reason is OOMKilled.
  7. Validate ConfigMaps, Secrets, volume mounts, file permissions, command, and args in the rendered pod spec.
  8. Use kubectl debug or a copied pod with an overridden command when logs do not explain the crash.
  9. After applying a fix, watch the rollout and confirm the restart count stops increasing.
Terminal window
kubectl rollout status deployment/payment-api -n payments
kubectl get pods -n payments -w

A fix is complete only when the pod stays ready under normal startup conditions and the restart counter stops climbing. If the pod becomes ready but restarts hours later, the cause may be a probe timeout under load, a memory leak, or a dependency failure that only appears at runtime. In that case, keep the same checklist, but add metrics, node events, and application-level telemetry to catch the failure at the moment it happens.

filed under → KubernetesDebuggingDevOps
found this useful? share it →
Written by

Dzubayyan Ahmad

System Administrator, SRE & Technical Support Engineer specialising in web hosting infrastructure — Linux servers, automation, and monitoring. Writing these notes since 2015 so future-me can find the fix again.