My Authors
Read all threads
THREAD: How to gracefully shut down Pods without dropping production traffic in Kubernetes

If you've ever noticed dropped connection after a rolling upgrade, this thread digs into the details.

Let's start: 𝘸𝘩𝘒𝘡 𝘩𝘒𝘱𝘱𝘦𝘯𝘴 𝘸𝘩𝘦𝘯 𝘒 π˜—π˜°π˜₯ π˜ͺ𝘴 π˜₯𝘦𝘭𝘦𝘡𝘦π˜₯?
1/6

When the Pod is deleted the endpoint controller removes the endpoint from the Services.

The changes are then propagated to all endpoint consumers:

- iptables
- DNS
- ingress
- etc.
2/6

While the endpoint controller removes the endpoint, the kubelet is notified of the change.

The kubelet is in charge of

- triggering the preStop hook (if any)
- sending the SIGTERM
- sending the SIGKILL if the process hasn't stopped in time
3/6

Since the two flows are triggered independently, there are opportunities for things to go wrong.

What happens if you shut down the application before the endpoints are removed in kube-proxy or the Ingress?

The traffic flows to a delete Pod.
4/6

𝘚𝘰 𝘩𝘰𝘸 π˜₯𝘰 𝘺𝘰𝘢 𝘧π˜ͺ𝘹 π˜ͺ𝘡?

You just need to wait long enough.

𝘏𝘰𝘸 𝘭𝘰𝘯𝘨?

Wait for kube-proxy, ingress, etc. to update their endpoints.
5/6

Is there anything else you should do other before terminating the process?

π—¬π—²π˜€.

1. Wait!
2. Close all persistent connections (DBs, WebSockets, etc.)
3. Wait for all active connection to drain
Missing some Tweet in this thread? You can try to force a refresh.

Keep Current with Daniele Polencic

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!