How Kubernetes handles pod deletion: SIGTERM, SIGKILL, and PreStop hooks

Deleting a pod ≠ stopping it instantly Here is the hidden shutdown flow Kubernetes follows👇 - The API server sends a deletion event. - Kubernetes executes the PreStop hook if any exists. - kubelet sends a SIGTERM signal to the container's main process (PID 1). - Applications have 30 seconds by default to handle the signal and shut down gracefully. - If the application process does not exit within the grace period, Kubernetes sends a SIGKILL signal to terminate the pod. 𝗡𝗼𝘁𝗲: Kubernetes does not give extra time for the PreStop hook. If your pod has a 30-second grace period, the PreStop hook and your app’s shutdown process must both finish within those same 30 seconds. We covered the following in detail in our newsletter edition. - What are SIGTERM and SIGKILL - How Kubernetes handles SIGTERM and SIGKILL - How applications can handle SIGTERM for graceful shutdown - The role of PreStop hooks and why it matters - The link between SIGTERM and container PID 1 → 𝗥𝗲𝗮𝗱 𝗶𝘁 𝗛𝗲𝗿𝗲: https://lnkd.in/gC-tsrgu Over to you… Have you written any custom logic to handle SIGTERM? #devops #kubernetes

  • No alternative text description for this image
Narayanan Narasimhan

Engineering Lead, Cloud and DevOps - Gartner

1mo

There is also the option of using terminationGracePeriodSeconds in combination with this, which will then enable the POD to be retained for longer than the default 30s.

Anvesh Gummala

Cloud Technical Consultant | DevOps Engineer | Network Security Engineer | Ethical Hacker

1mo

-f --grace-period=0

See more comments

To view or add a comment, sign in

Explore content categories