failureThreshold 在活动和就绪探针中如何工作?一定要连续失败吗?

Rag*_*ghu 4 probe kubernetes livenessprobe

除了此链接之外,我找不到任何参考资料来确认失败必须是连续的。https://github.com/kubernetes/website/issues/37414

背景:由于活性探测失败,我们的 Java 应用程序每天都会重新启动。应用程序的访问日志未显示连续 3 次失败。所以想了解探针的行为。

小智 5

活性检查是在 Kubernetes 创建 Pod 时创建的,并在每次 Pod 重新启动时重新创建。在您的配置中,您设置了initialDelaySeconds:20,因此在创建pod后,Kubernetes将等待20秒,然后它将调用liveness探针3次(默认值failureThreshold:3)。3次失败后,Kubernetes将根据RestartPolicy重新启动此Pod。此外,您还可以在日志中找到日志。

当您使用时, kubectl get events您只能获取过去一小时的事件。

Kubectl get events

LAST SEEN           TYPE      REASON                    OBJECT             
47m             Normal    Starting                  node/kubeadm      
43m                 Normal    Scheduled                 pod/liveness-http   
43m             Normal    Pulling                   pod/liveness-http   
43m                 Normal    Pulled                    pod/liveness-http 
43m                 Normal    Created                   pod/liveness-http   
43m             Normal    Started                   pod/liveness-http   
4m41s           Warning   Unhealthy                 pod/liveness-http 
40m                 Warning   Unhealthy                 pod/liveness-http   
12m20s              Warning   BackOff                   pod/liveness-http   
Run Code Online (Sandbox Code Playgroud)

约 1 小时后执行相同命令:

LAST SEEN       TYPE         REASON         OBJECT            
43s             Normal      Pulling          pod/liveness-http   
8m40s               Warning     Unhealthy       pod/liveness-http  
20m                 Warning     BackOff         pod/liveness-http 
Run Code Online (Sandbox Code Playgroud)

因此,这可能就是您只看到一次失败的原因。

可以使用以下字段配置活动探针:

  • initialDelaySeconds:容器启动后启动活动或就绪探测之前的秒数。默认为 0 秒。最小值为 0。

  • periodSeconds:执行探测的频率(以秒为单位)。默认为 10 秒。最小值为 1。

  • timeoutSeconds:探测超时之前的秒数。默认为 1 秒。最小值为 1。

  • successThreshold:探测失败后被视为成功的最小连续成功次数。默认为 1。活性必须为 1。最小值为 1。

  • failureThreshold:当探测失败时,Kubernetes 在放弃之前会尝试 failureThreshold 次。在活性探测的情况下放弃意味着重新启动容器。如果进行就绪探测,Pod 将被标记为“未就绪”。默认为 3。最小值为 1。

如果您设置 periodSeconds、timeoutSeconds、successThreshold 和 failureThreshold 的最小值,您可以期待更频繁的检查和更快的重新启动。

活性探针:

活性探针配置最佳实践中,您可以找到更多信息。