I have implemented Liveness Probe in C# based Kubernetes Application. When I am removing InitialDelaySeconds in my livenessconfig (at code level using 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};
then I am seeing Liveness Probe failing in Pod description(no reason is mentioned though):
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
I don't want to give any initialdelay to my probe and want my probe to start executing command as soon as container is up. How should I manage this?
By providing initialDelaySeconds
you basically giving enough time to your container so that your container can be up perfectly. You want your probe to start executing command as soon as your container is up, and how would you do that? by providing initialDelaySeconds
.
If a container is restarted and the initialDelaySeconds
parameter is not long enough or not given then probe can fail. You need to provide initialDelaySeconds
so that containers can be reliably restarted, otherwise your probe will fail because of having the risk of never starting the application.
And, initialDelaySeconds
parameter should be longer than maximum initialization time for your container.
The kubelet
uses liveness probes to know when to restart a container. There are couple of terms in liveness probe, like: periodSeconds
, initialDelaySeconds
. periodSeconds
specifies that the kubelet
should perform a liveness probe every periodSeconds
seconds and the initialDelaySeconds
tells the kubelet
that it should wait initialDelaySeconds
seconds before performing the first probe.