Kubernetes state of the pod when running preStop command

12/10/2015

I'm using preStop command to gracefully shutdown my server application when I delete a pod. What is the state of the pod/ container when it runs preStop command? For example, does it stop the network interfaces before running the preStop command?

lifecycle:
    preStop:
      exec:                
        command: ["kill", "-SIGTERM", "`pidof java`"]
-- Dimuthu
kubernetes

2 Answers

12/10/2015

The state of the pod doesn't change while preStop hooks are run -- the preStop hook is run in the container, and then the container is stopped.

-- Paul Morie
Source: StackOverflow

8/19/2016

When a pod should be terminated, Kubernetes does the following:

  1. Switch the Pod to the Terminating state
  2. Invoke the preStop hook (if any)
  3. Once the preStop hook ends, it sends a SIGTERM to the main process in the container (PID 1)
  4. If the container doesn't terminate with the termination grace period (30 seconds by default - starts counting at point #1), Kubernetes will send a SIGKILL to the container's main process to violently stop it

More details here: Graceful shutdown of Kubernetes Pods

-- Marco Pracucci
Source: StackOverflow