How To Fix Back-Off Restarting Failed Container [Solved]

Immediate Fix

The “back-off restarting failed container” error, often seen as CrashLoopBackOff, occurs when a container fails and Kubernetes repeatedly tries to restart it. To resolve this quickly, you must identify the root cause using the following diagnostic steps.

First, check the logs of the failing container to see the application-level errors. Use the command below:

kubectl logs [POD_NAME] --previous

Next, examine the pod events to check for resource issues or configuration errors:

kubectl describe pod [POD_NAME]

Below are common exit codes found in the “Describe” output and their immediate fixes:

Exit Code Meaning Immediate Action
1 Application Error Check application logs for bugs or missing files.
137 OOMKilled Increase the memory limit in the deployment YAML.
127 Command Not Found Verify the entrypoint command in the Dockerfile.

Technical Explanation

When a container exits with a non-zero status, the Kubelet service attempts to restart it. Kubernetes applies an exponential back-off delay (10s, 20s, 40s, up to 5 minutes) to prevent overloading the node.

This state is not the error itself, but a symptom of an underlying crash. It signifies that the pod is stuck in a loop: it starts, runs into a problem, terminates, and waits to try again.

Common triggers include incorrect environment variables, port conflicts, or failed liveness probes that trigger a restart before the app is ready.

Kubernetes terminal showing back-off restarting failed container error message.

Alternative Methods

1. Debugging with an Interactive Shell

If the logs are empty, try overriding the entrypoint to keep the container alive so you can inspect the filesystem manually.

# Add this to your YAML temporarily
command: ["sleep", "3600"]

2. Checking Resource Quotas

A container may crash if it exceeds the CPU or memory limits defined in the namespace. Ensure your resources: limits are high enough for the application’s peak demand.

3. Verifying Liveness and Readiness Probes

Incorrectly configured probes can kill a healthy container. If a liveness probe points to a non-existent endpoint, Kubernetes will restart the container indefinitely. Check your YAML for these settings:

livenessProbe:
  httpGet:
    path: /healthz
    port: 8080

Ensure the application is actually listening on the specified port and path.