when terminate a pod, does kubelet stop containers in parallel?

12/29/2019

As far as I know, docker stop stops containers one by one even though apply multiple containers to it at a time. So does kubelet behave like this?

-- SFurnace
docker
kubernetes

1 Answer

12/29/2019

Pod termination prefectly described on POD lifecycle page

  1. User sends command to delete Pod, with default grace period (30s)

  2. The Pod in the API server is updated with the time beyond which the Pod is considered “dead” along with the grace period.

  3. Pod shows up as “Terminating” when listed in client commands

  4. (simultaneous with 3) When the Kubelet sees that a Pod has been marked as terminating because the time in 2 has been set, it begins the Pod shutdown process.

    1. If one of the Pod’s containers has defined a preStop hook, it is invoked inside of the container. If the preStop hook is still running after the grace period expires, step 2 is then invoked with a small (2 second) extended grace period.

    2. The container is sent the TERM signal. Note that not all containers in the Pod will receive the TERM signal at the same time and may each require a preStop hook if the order in which they shut down matters.

  5. (simultaneous with 3) Pod is removed from endpoints list for service, and are no longer considered part of the set of running Pods for replication controllers. Pods that shutdown slowly cannot continue to serve traffic as load balancers (like the service proxy) remove them from their rotations.

  6. When the grace period expires, any processes still running in the Pod are killed with SIGKILL.

  7. The Kubelet will finish deleting the Pod on the API server by setting grace period 0 (immediate deletion). The Pod disappears from the API and is no longer visible from the client.
-- Oleg Butuzov
Source: StackOverflow