Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What the Status Means

kubectl get pods
NAME                  READY   STATUS             RESTARTS      AGE
web-7d4b9c6f5-x2k8p   0/1     CrashLoopBackOff   6 (90s ago)   9m

The container ran, ended, and was started again because the pod's restart policy says so; pods of a Deployment always restart. After each failure the kubelet waits before the next start: by default 10 seconds, then 20, then 40, doubling up to a cap of five minutes. The timer resets once the container has run for 10 minutes without problems. Cluster administrators can change these figures in the kubelet settings. During the wait the status reads CrashLoopBackOff; in between you may briefly see Running, Error, or OOMKilled. RESTARTS counts the attempts.

Step 1: Describe the Pod

kubectl describe pod web-7d4b9c6f5-x2k8p

Look at two places. Under the container, Last State shows how the previous run ended:

    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1

At the bottom, Events list what the kubelet did: back-off messages, failed probes, and kills. Add -n NAMESPACE if the pod is not in the default namespace.

Step 2: Read the Logs of the Failed Run

kubectl logs web-7d4b9c6f5-x2k8p --previous
kubectl logs web-7d4b9c6f5-x2k8p -c web --previous

The current container may have started a moment ago. --previous shows the output of the run that crashed, and its last lines usually name the problem. Use -c when the pod has several containers. Empty logs mean the process died before it printed anything; then the exit code is your lead.

Causes by Exit Code

Exit codeUsual cause
1Application or config error
137Killed, often for memory
126Command not executable
127Command not found
0Program finished
  • 1: a missing environment variable, a wrong setting, or a configuration file the application cannot parse. The logs say which.
  • 137 with the reason OOMKilled: the container went over its memory limit. Raise resources.limits.memory or find the leak; kubectl top pod shows current use where a metrics server runs. The details are in exit code 137, and kills by the node's own kernel in OOM killer.
  • 126 and 127: the command or args in the manifest are wrong, a script lacks the execute bit, or its first line asks for a shell the image does not have, such as bash in an Alpine image.
  • 0: a program that finishes its work is restarted too. One-off tasks belong in a Job; a server process must stay in the foreground.

A Failing Liveness Probe

If the liveness probe fails several times in a row, the kubelet kills the container and starts it again, so a healthy but slow application loops as well. The events show the failed probe. Check the path and port, and give slow starters a startup probe:

        startupProbe:
          httpGet:
            path: /healthz
            port: 8080
          failureThreshold: 30
          periodSeconds: 10

A failing readiness probe never restarts anything; it only takes the pod out of the service.

A Dependency That Is Not Reachable

Many applications exit when the database or an API is missing at start. Test name resolution from inside the cluster:

kubectl run nettest --rm -it --image=busybox --restart=Never -- nslookup db

Then make the application retry with a delay, or add an init container that waits for the dependency.

Look Inside the Image

kubectl run debug --rm -it --image=registry.example.com/shop/web:1.4.0 \
  --restart=Never --command -- sh

This starts the same image with a shell instead of its normal command, if it contains one. Run the real command by hand and read its error.

Watch the Fix

kubectl apply -f deployment.yaml
kubectl rollout status deployment/web
kubectl get pods -w

New pods start with a restart count of zero; the fix holds when it stays there. More commands are in the kubectl cheat sheet, and a small cluster to practice on is described in K3s. If the pod never starts because the image cannot be fetched, see ImagePullBackOff.

Was this answer helpful?
Loading...