未提供 InitialDelaySeconds 时,Liveness Probe 失败

Liveness Probe failing when InitialDelaySeconds not provided

我已经在基于 C# 的 Kubernetes 应用程序中实现了 Liveness Probe。当我在 livenessconfig 中删除 InitialDelaySeconds 时(在代码级别使用 Kubernetes Client's V1Probe):

IList<string> command = new List<string>();
V1Probe livenessconfig = null;
command.Add("curl");
command.Add("- f");
command.Add("http://localhost:5000/checkhealth/");
V1ExecAction execommand = new V1ExecAction(command);
livenessconfig = new V1Probe { Exec = execommand, PeriodSeconds = 10};

然后我在 Pod 描述中看到 Liveness Probe 失败(虽然没有提到原因):

  Normal   Created    26s               kubelet            Created container App-prox
  Normal   Started    26s               kubelet            Started container App-prox
  Warning  Unhealthy  6s (x2 over 16s)  kubelet            Liveness probe failed:
  Normal   Killing    6s                kubelet            Stopping container App-prox

我不想给我的探测器任何初始延迟,并希望我的探测器在容器启动后立即开始执行命令。我应该如何管理它?

通过提供 initialDelaySeconds,您基本上可以为您的容器提供足够的时间,以便您的容器可以完美启动。您希望您的探测器在您的容器启动后立即开始执行命令,您将如何做到这一点?通过提供 initialDelaySeconds.

如果容器重新启动并且 initialDelaySeconds 参数不够长或未提供,则探测可能会失败。您需要提供 initialDelaySeconds 以便容器可以可靠地重新启动,否则您的探测将失败,因为存在永远不会启动应用程序的风险。

并且,initialDelaySeconds 参数应长于容器的最长初始化时间。

更新

kubelet 使用活动探测来了解何时重启容器。 liveness probe 中有几个术语,例如:periodSecondsinitialDelaySecondsperiodSeconds 指定 kubelet 应该每 periodSeconds 秒执行一次活性探测,而 initialDelaySeconds 告诉 kubelet 它应该等待 initialDelaySeconds 秒执行第一次探测。