Kubernetes Probes
There might be many problems for the pod failure though the pod fails and the main process in the container fails kubelet automatically restarts pod but if there are bugs, any database failures , out of memory issues kubelet wont start the pod and the application will not show the desired result.
Probes are used when we want kubelet to restart the pod when we dont expect desired result..
There are 3 types of probes.
Liveness probe
Readinesss probe
Start up probe
LivenessProbe
Ensures container is always running and pods are always running. We make network calls / execute some commands inside the container,
if fails then kubelet restarts the pod.
We can run some commads / make network calls / verify some port is open at the container level. If probe results in failure kubelet restarts the pod.
How frequently we have to run the pod ?
initialdelaySeconds - After how much time after the container is ready kubernetes has to run the probe.
periodSeconds- How frequently kubernetes has to run the probe.
time out Each probe is marked as failure after these many seconds.
failure threshold How many times kubernetes has to restart the probe after the failure .
Readiness Probe
It determines when container is ready to accept traffic from service. If this fails pod is not restarted and then pod Ip was removed from service end points.
StartUp probe
Liveness and Readiness Probe will only be executed when startup probe is successful.
So After waiting for initialDelaySeconds after the pod has been scheduled, if it is successful then only Liveness Probe and Readiness Probes will be executed. If failed kubernetes repeates for failure threshold times if failed again pod will be stopped.
In case of Readiness Probe same story continues if success receives traffic from service , if failed runned again till failure threshold times. In any case probe execution is successful receives traffic but fails again then pod will be removed from service endpoints and pod doesn’t receive traffic.
Liveness Probe (Self Explanatory)
Probes must be used when we have many pods and debugging is difficult. Using Probes frequently and unnecessarily might use heavy resources.
So increasing period seconds , using light weight network calls while executing probe, can save some cpu/memory.
Thanks for reading my blog. Have a great day.