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
-f --grace-period=0
Engineering Lead, Cloud and DevOps - Gartner
1moThere 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.