kubernetescrashloopbackoff

Kubernetes CrashLoopBackOff default timing


What are the defaults for the Kubernetes CrashLoopBackOff?

Say, I have a pod:

kubectl run mynginx --image nginx -- echo hello

And I inspect its status:

kubectl get pods -w
NAME      READY   STATUS    RESTARTS   AGE
mynginx   0/1     Pending   0          0s
mynginx   0/1     Pending   0          0s
mynginx   0/1     ContainerCreating   0          0s
mynginx   0/1     Completed           0          2s
mynginx   0/1     Completed           1          4s
mynginx   0/1     CrashLoopBackOff    1          5s
mynginx   0/1     Completed           2          20s
mynginx   0/1     CrashLoopBackOff    2          33s
mynginx   0/1     Completed           3          47s
mynginx   0/1     CrashLoopBackOff    3          59s
mynginx   0/1     Completed           4          97s
mynginx   0/1     CrashLoopBackOff    4          109s

This is "expected". Kubernetes starts a pod, it quits "too fast", Kubernetes schedules it again and then Kubernetes sets the state to CrashLoopBackOff.

Now, if i start a pod slightly differently:

kubectl run mynginx3 --image nginx -- /bin/bash -c "sleep 10; echo hello"

I get the following

kubectl get pods -w
NAME       READY   STATUS    RESTARTS   AGE
mynginx3   0/1     Pending   0          0s
mynginx3   0/1     Pending   0          0s
mynginx3   0/1     ContainerCreating   0          0s
mynginx3   1/1     Running             0          2s
mynginx3   0/1     Completed           0          12s
mynginx3   1/1     Running             1          14s
mynginx3   0/1     Completed           1          24s
mynginx3   0/1     CrashLoopBackOff    1          36s
mynginx3   1/1     Running             2          38s
mynginx3   0/1     Completed           2          48s
mynginx3   0/1     CrashLoopBackOff    2          62s
mynginx3   1/1     Running             3          75s
mynginx3   0/1     Completed           3          85s
mynginx3   0/1     CrashLoopBackOff    3          96s
mynginx3   1/1     Running             4          2m14s
mynginx3   0/1     Completed           4          2m24s
mynginx3   0/1     CrashLoopBackOff    4          2m38s

This is also expected.

But say I set sleep for 24 hours, would I still get the same CrashLoopBackOff after two pod exits initially and then after each next pod exit?


Solution

  • Based on these docs:

    The restartPolicy applies to all containers in the Pod. restartPolicy only refers to restarts of the containers by the kubelet on the same node. After containers in a Pod exit, the kubelet restarts them with an exponential back-off delay (10s, 20s, 40s, …), that is capped at five minutes. Once a container has executed for 10 minutes without any problems, the kubelet resets the restart backoff timer for that container.

    I think that means that anything that executes for longer than 10 minutes before exiting will not trigger a CrashLoopBackOff status.