Kubernetes pod graceful shutdown

2021-08-12  本文已影响0人  涣涣虚心0215

Because Pods represent processes running on nodes in the cluster, it is important to allow those processes to gracefully terminate when they are no longer needed (rather than being abruptly stopped with a KILL signal and having no chance to clean up).
Typically, the container runtime sends a TERM signal to the main process in each container. Many container runtimes respect the STOPSIGNAL value defined in the container image and send this instead of TERM. Once the grace period has expired, the KILL signal is sent to any remaining processes, and the Pod is then deleted from the API Server. If the kubelet or the container runtime's management service is restarted while waiting for processes to terminate, the cluster retries from the start including the full original grace period.

example flow

Kubectl delete pod ftp-rest-service-84599d54fd-m56bj

This command is trying to delete a specific pod, with the default grace period (30 seconds).

  1. If you use kubectl describe to check on the Pod you're deleting, that Pod shows up as "Terminating". On the node where the Pod is running: as soon as the kubelet sees that a Pod has been marked as terminating (a graceful shutdown duration has been set), the kubelet begins the local Pod shutdown process.
  1. At the same time as the kubelet is starting graceful shutdown
  1. When the grace period expires, the kubelet triggers forcible shutdown. The container runtime sends SIGKILL to any processes still running in any container in the Pod. The kubelet also cleans up a hidden pause container if that container runtime uses one.

  2. The kubelet triggers forcible removal of Pod object from the API server, by setting grace period to 0 (immediate deletion).

  3. The API server deletes the Pod's API object, which is then no longer visible from any client.

Summary

image.png

The following 5 steps occur when Kubernetes kills a pod:

上一篇 下一篇

猜你喜欢

热点阅读