<p>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? </p>

<pre><code>lifecycle:
    preStop:
      exec:                
        command: ["kill", "-SIGTERM", "`pidof java`"]
</code></pre>

<p>When a pod should be terminated, Kubernetes does the following:</p>

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

<p>More details here:
<a href="https://pracucci.com/graceful-shutdown-of-kubernetes-pods.html" rel="nofollow">Graceful shutdown of Kubernetes Pods</a></p>
