如何利用Kubernetes的ReadinessProbe自我修复Pod而不重启它?

时间:2019-02-20 12:20:38

标签: kubernetes kubernetes-health-check

根据本文档,我看到readinessProbe可用于暂时暂停对Pod的请求,而无需重新启动它即可正常恢复。

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-readiness-probes

当我看到Pod事件时,它似乎在“就绪”探测失败时重新启动了Pod。这是事件:

 1. Readiness probe failed
 2. Created container
 3. Started container
 4. Killing container with id {}

试图将容器restartPolicy修改为OnFailure,希望此配置在ReadinessProbe失败时决定pod操作,但是我看到以下错误:

The Deployment {} is invalid: spec.template.spec.restartPolicy: Unsupported value: "OnFailure": supported values: "Always"

哪种是停止对pod的请求而不必重新启动它并让应用程序正常恢复的正确方法?

1 个答案:

答案 0 :(得分:0)

有两种类型的探针。 由于活动性探针失败,因此会重新启动。 https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

活力探针

  

kubelet使用活动探针来了解何时重新启动Container。例如,活动性探针可能会陷入僵局,而应用程序正在运行,但无法取得进展。在这种状态下重新启动容器可以帮助使应用程序在存在错误的情况下更加可用。

准备情况调查

  

有时,应用程序暂时无法提供流量。例如,应用程序可能需要在启动过程中加载大数据或配置文件,或者在启动后依赖于外部服务。在这种情况下,您不想杀死应用程序,但也不想发送请求。 Kubernetes提供了准备就绪探针以检测和缓解这些情况。装有报告其容器尚未就绪的容器的容器无法通过Kubernetes Services接收流量。

今天,我发现了一篇有关探针https://blog.colinbreck.com/kubernetes-liveness-and-readiness-probes-how-to-avoid-shooting-yourself-in-the-foot/的很好的文章