Kubernetes CrashLoopBackOff 默认计时

Mak*_*kin 0 kubernetes crashloopbackoff

Kubernetes 的默认设置是什么CrashLoopBackOff

假设我有一个 pod:

kubectl run mynginx --image nginx -- echo hello
Run Code Online (Sandbox Code Playgroud)

我检查它的状态:

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
Run Code Online (Sandbox Code Playgroud)

这是“预期”的。Kubernetes 启动一个 pod,它“太快”退出,Kubernetes 再次调度它,然后 Kubernetes 将状态设置为CrashLoopBackOff

现在,如果我启动一个稍微不同的 Pod:

kubectl run mynginx3 --image nginx -- /bin/bash -c "sleep 10; echo hello"
Run Code Online (Sandbox Code Playgroud)

我得到以下内容

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
Run Code Online (Sandbox Code Playgroud)

这也是预料之中的。

但是假设我设置为 24 小时,那么在最初两次 Pod 退出以及每次下一个 Pod 退出后,sleep我还会得到相同的结果吗?CrashLoopBackOff

lar*_*sks 5

基于这些文档

\n
\n

restartPolicy 适用于 Pod 中的所有容器。restartPolicy仅指同一节点上的kubelet重新启动容器。Pod 中的容器退出后,kubelet 以指数退避延迟(10 秒、20 秒、40 秒、\xe2\x80\xa6)重新启动它们,上限为五分钟。一旦容器执行 10 分钟且没有任何问题,kubelet 就会重置该容器的重启退避计时器。

\n
\n

我认为这意味着退出前执行时间超过 10 分钟的任何内容都不会触发状态CrashLoopBackOff

\n