Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the signal sent to the process running in the container when k8s liveness probe fails? KILL or TERM

I have a use case to gracefully terminate the container where i have a script to kill the process gracefully from within the container by using the command "kill PID".( Which will send the TERM signal ) But I have liveness probe configured as well. Currently liveness probe is configured to probe at 60 second interval. So if the liveness probe take place shortly after the graceful termination signal is sent, the overall health of the container might become CRITICAL when the termination is still in progress. In this case the liveness probe will fail and container will be terminated immediately.

So i wanted to know whether kubelet kills the container with TERM or KILL.

Appreciate your support Thanks in advance

like image 844
Beatrix Kiddo Avatar asked Dec 18 '17 04:12

Beatrix Kiddo


People also ask

What happens when liveness probe fails in Kubernetes?

If the liveness probe fails, the kubelet kills the container, and the container is subjected to its restart policy. If a container does not provide a liveness probe, the default state is Success . readinessProbe. Indicates whether the container is ready to respond to requests.

What happens if readiness probe fails?

After a liveness probe fail, the container should restart and ideally should start serving the traffic again, just like how it would happen for a k8s deployment.

How does k8s liveness probe work?

A liveness probe indicates if the container is operating: If it succeeds, no action is taken and no events are logged. If it fails, the kubelet kills the container, and it is restarted in line with the pod restartPolicy.

What component of the Kubernetes control plane ultimately responds to failed liveness probes of containers?

Answer: E.The kubelet (a component not in the control plane) sends out the liveness probe. The source is page 90 of Kubernetes in Action by Luksa. 21.


1 Answers

In Kubernetes, Liveness Probe checks for the health state of a container.

To answer your question on whether it uses SIGKILL or SIGTERM, the answer is both are used but in order. So here is what happens under the hood.

  1. Liveness probe check fails
  2. Kubernetes stops routing of traffic to the container
  3. Kubernetes restarts the container
  4. Kubernetes starts routing traffic to the container again

For container restart, SIGTERM is first sent with waits for a parameterized grace period, and then Kubernetes sends SIGKILL.

A hack around your issue is to use the attribute:

timeoutSeconds

This specifies how long a request can take to respond before it’s considered a failure. You can add and adjust this parameter if the time taken for your application to come online is predictable.

Also, you can play with readinessProbe before livenessProbe with an adequate delay for the container to come into service after restarting the process. Check https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ for more details on which parameters to use.

like image 64
Aby Sheffer Avatar answered Sep 22 '22 16:09

Aby Sheffer