1

我有一个简单的 spring boot 应用程序,带有以下 liveness probe:

        livenessProbe:
          httpGet:
            path: /health
            port: 56017
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 1
          failureThreshold: 3

在 health 端点中,我只是抛出了一个异常,导致它返回 500。这是一个新的 Pod 在观看多次重启后的统计数据:

PS C:\Users\xxx\yyy\Desktop> k get pods -n xyz  -w

NAME                                         READY   STATUS             RESTARTS   AGE
springapi-577c6f94b9-9r4lm                   1/1     Running            0          15s
springapi-577c6f94b9-9r4lm                   1/1     Running            1          69s
springapi-577c6f94b9-9r4lm                   1/1     Running            2          2m10s
springapi-577c6f94b9-9r4lm                   1/1     Running            3          3m10s
springapi-577c6f94b9-9r4lm                   1/1     Running            4          4m10s
springapi-577c6f94b9-9r4lm                   1/1     Running            5          5m10s
springapi-577c6f94b9-9r4lm                   0/1     CrashLoopBackOff   5          6m8s
springapi-577c6f94b9-9r4lm                   1/1     Running            6          7m33s
springapi-577c6f94b9-9r4lm                   0/1     CrashLoopBackOff   6          8m28s
springapi-577c6f94b9-9r4lm                   1/1     Running            7          11m
springapi-577c6f94b9-9r4lm                   0/1     CrashLoopBackOff   7          12m
springapi-577c6f94b9-9r4lm                   1/1     Running            8          17m
springapi-577c6f94b9-9r4lm                   1/1     Running            9          18m
springapi-577c6f94b9-9r4lm                   0/1     CrashLoopBackOff   9          19m
springapi-577c6f94b9-9r4lm                   1/1     Running            10         24m
springapi-577c6f94b9-9r4lm                   1/1     Running            11         25m
springapi-577c6f94b9-9r4lm                   0/1     CrashLoopBackOff   11         26m

我注意到前几次重新启动就像预期的那样快。然后#3、#4、#5 相隔 1 分钟。到目前为止有点道理。之后,我开始看到 CrashLoopBackOff 并且两次重新启动之间的时间间隔长达 5 分钟。为什么 CrashLoopBackOff?为什么在几次重启后重启相差如此之大?

我看到了吊舱的日志。没有什么不寻常的。日志输出是这样的(这些日志是在多次重启后):

2021-04-04 00:46:49.172 DEBUG 1 --- Spring boot startup stuff ...
...
2021-04-04 00:47:23.121  INFO 1 --- Spring boot startup stuff ...
2021-04-04 00:47:23.178 ERROR 1 --- exception stack trace
2021-04-04 00:47:33.010 ERROR 1 --- exception stack trace
2021-04-04 00:47:43.005 ERROR 1 --- exception stack trace
2021-04-04 00:47:43.092  INFO 1 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

当我运行 describe 命令时,我看到类似

Container springapi failed liveness probe, will be restarted
Liveness probe failed: HTTP probe failed with statuscode: 500
Back-off restarting failed container

顺便说一句,在这 5 分钟内,pod 保持在CrashLoopBackOff状态。我已经多次重新启动 pod。我每次都看到相同的行为。

4

1 回答 1

3

我在一篇文章中找到了这个解释:

Failed containers that are restarted by the kubelet are restarted with an exponential back-off delay (10s, 20s, 40s …) capped at five minutes, and is reset after ten minutes of successful execution. 

看起来它是一种预期的行为。

于 2021-04-04T01:26:42.233 回答