<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9" -->

---
title: Graceful shutdown in Kubernetes | daily.dev
description: A deep technical walkthrough of what happens internally in Kubernetes when Pods are created and deleted, tracing the interaction between the API server,...
canonical: https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Graceful shutdown in Kubernetes | daily.dev
og:description: A deep technical walkthrough of what happens internally in Kubernetes when Pods are created and deleted, tracing the interaction between the API server,...
og:url: https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9
og:image: https://api.daily.dev/og/posts/HABL4uXr9.png
og:image:alt: Graceful shutdown in Kubernetes
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Graceful shutdown in Kubernetes

**[LearnKube](https://daily.dev/sources/learnkube)** · 25 min read · 0 upvotes · 0 comments

## Summary

A deep technical walkthrough of what happens internally in Kubernetes when Pods are created and deleted, tracing the interaction between the API server, scheduler, kubelet, CRI/CNI/CSI, Endpoints, kube-proxy, Ingress controllers, CoreDNS, and service meshes. It explains why deleting a Pod can cause dropped connections due to race conditions between endpoint propagation and Pod termination, and details how SIGTERM, preStop hooks, and terminationGracePeriodSeconds (default 30 seconds) control graceful shutdown. It also covers implications for cluster autoscaling during rolling updates and recommends 'rainbow deployments' — spinning up a new Deployment per release instead of extending grace periods — for long-lived connections like WebSockets or long-running jobs like video transcoding.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://learnkube.com/graceful-shutdown>

## Questions this post answers

### How long does Kubernetes wait before force-killing a pod after sending SIGTERM?

By default, Kubernetes sends SIGTERM and waits 30 seconds before force-killing the process with SIGKILL, a value controlled by terminationGracePeriodSeconds in the Pod spec. A preStop hook runs before SIGTERM is sent and its duration counts against that same 30-second budget, so a 25-second preStop hook leaves only 5 seconds after SIGTERM before SIGKILL.

_daily.dev surfaces practical Kubernetes deployment guidance for engineers tuning shutdown timing to avoid dropped connections._

### Why do I get dropped connections when Kubernetes deletes a pod even though the pod passed its readiness probe?

Deleting a pod removes its endpoint from the Endpoint object and signals the kubelet to terminate the container at the same time, in parallel, rather than sequentially as happens on pod creation. Components like kube-proxy, the Ingress controller, and CoreDNS need time to propagate that removal, so traffic can still be routed to the terminated pod's IP address before they catch up, causing broken connections.

_engineers debugging pod termination race conditions can track these Kubernetes networking patterns on daily.dev._

### How should I handle long-lived WebSocket connections during a Kubernetes rolling deployment without losing them?

Rather than extending terminationGracePeriodSeconds to hours, create a new Deployment for every release and leave the old one running until its connections drain naturally, a pattern known as rainbow deployments. This avoids losing Prometheus metrics scraping, avoids debugging confusion from mixed-version pods, and avoids liveness-probe restarts; tools like KEDA can then scale the old deployment to zero once tasks finish.

_teams choosing a deployment strategy for stateful or long-lived connections can find comparisons like this on daily.dev._

## Similar posts on daily.dev

- [Blog: Graceful Shutdowns in Go](https://daily.dev/posts/blog-graceful-shutdowns-in-go-hidlppkrp) · Wawandco · 74 upvotes · 0 comments

---

Tags: [#kubernetes](https://daily.dev/tags/kubernetes), [#networking](https://daily.dev/tags/networking), [#orchestration](https://daily.dev/tags/orchestration)

[View this post on daily.dev](https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Graceful shutdown in Kubernetes","url":"https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9"},"datePublished":"2026-08-31T11:20:03.526Z","dateModified":"2026-08-31T11:20:31.099Z","description":"A deep technical walkthrough of what happens internally in Kubernetes when Pods are created and deleted, tracing the interaction between the API server,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6c88169ac530e23559ffae69dd200c32?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6c88169ac530e23559ffae69dd200c32?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"LearnKube","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"LearnKube","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/90786df1b5d44abb91a090a0b6c81517","url":"https://daily.dev/sources/learnkube"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"kubernetes,networking,orchestration","timeRequired":"PT25M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"LearnKube","item":"https://daily.dev/sources/learnkube"},{"@type":"ListItem","position":3,"name":"Graceful shutdown in Kubernetes"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/graceful-shutdown-in-kubernetes-habl4uxr9#faq","mainEntity":[{"@type":"Question","name":"How long does Kubernetes wait before force-killing a pod after sending SIGTERM?","acceptedAnswer":{"@type":"Answer","text":"By default, Kubernetes sends SIGTERM and waits 30 seconds before force-killing the process with SIGKILL, a value controlled by terminationGracePeriodSeconds in the Pod spec. A preStop hook runs before SIGTERM is sent and its duration counts against that same 30-second budget, so a 25-second preStop hook leaves only 5 seconds after SIGTERM before SIGKILL. daily.dev surfaces practical Kubernetes deployment guidance for engineers tuning shutdown timing to avoid dropped connections."}},{"@type":"Question","name":"Why do I get dropped connections when Kubernetes deletes a pod even though the pod passed its readiness probe?","acceptedAnswer":{"@type":"Answer","text":"Deleting a pod removes its endpoint from the Endpoint object and signals the kubelet to terminate the container at the same time, in parallel, rather than sequentially as happens on pod creation. Components like kube-proxy, the Ingress controller, and CoreDNS need time to propagate that removal, so traffic can still be routed to the terminated pod's IP address before they catch up, causing broken connections. engineers debugging pod termination race conditions can track these Kubernetes networking patterns on daily.dev."}},{"@type":"Question","name":"How should I handle long-lived WebSocket connections during a Kubernetes rolling deployment without losing them?","acceptedAnswer":{"@type":"Answer","text":"Rather than extending terminationGracePeriodSeconds to hours, create a new Deployment for every release and leave the old one running until its connections drain naturally, a pattern known as rainbow deployments. This avoids losing Prometheus metrics scraping, avoids debugging confusion from mixed-version pods, and avoids liveness-probe restarts; tools like KEDA can then scale the old deployment to zero once tasks finish. teams choosing a deployment strategy for stateful or long-lived connections can find comparisons like this on daily.dev."}}]}
```

