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

时间:2017-12-18 04:51:44

标签: linux docker kubernetes kill-process kubernetes-health-check

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

1 个答案:

答案 0 :(得分:3)

在Kubernetes中,Liveness Probe会检查容器的健康状况。

要回答关于它是否使用SIGKILL或SIGTERM的问题,答案是使用但是按顺序。所以这就是幕后发生的事情。

  1. 活体探测检查失败
  2. Kubernetes停止将流量路由到容器
  3. Kubernetes重启容器
  4. Kubernetes开始再次将流量路由到容器
  5. 对于容器重启,首先发送SIGTERM,等待参数化宽限期,然后Kubernetes发送SIGKILL。

    解决您的问题是使用以下属性:

    timeoutSeconds
    

    指定请求在被视为失败之前可以响应多长时间。如果应用程序联机所需的时间是可预测的,则可以添加和调整此参数。

    此外,您可以在readinessProbe之前使用livenessProbe,并且在重新启动流程后,容器有足够的延迟时间投入使用。请查看https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/以获取有关使用哪些参数的更多详细信息。