feat: add drain delay to graceful shutdown process#9211
Open
mwain wants to merge 2 commits into
Open
Conversation
drainDelay defines how long the shutdown manager waits before failing healthchecks (delaying call to healthcheck/fail). The delay allows external load balancers time to deregister a terminating pod while still serving traffic. Signed-off-by: Michael Wain <michael@sanity.io>
When a pod terminates, the shutdown-manager immediately calls `healthcheck/fail` to fail health checks. This causes the readiness probe to fail and removes the pod from service endpoints. External load balancers that use health checks for deregistration need several failed probes before they stop sending new connections to the pod. On GKE, the L4 passthrough load balancer probes every 3 seconds and needs 2 failures (at the time of writing), so deregistration takes 6 seconds or more. The pod readiness probe fails faster than that, so for a few seconds the load balancer keeps sending connections that kube-proxy no longer routes. Kubernetes has a mechanism for this window. When a service has no other ready endpoints, kube-proxy keeps routing to terminating pods that still pass their readiness probe (KEP-1669). This only works if the pod keeps passing its probe while the load balancer deregisters it. Calling `healthcheck/fail` at the start of shutdown breaks that. This adds a drainDelay field to ShutdownConfig which delays the `healthcheck/fail` call. During the delay the pod stays ready and keeps serving, so the load balancer has time to deregister it. The ready-timeout and termination grace period are extended by the delay. Signed-off-by: Michael Wain <michael@sanity.io>
✅ Deploy Preview for cerulean-figolla-1f9435 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #9211 +/- ##
==========================================
- Coverage 74.90% 74.88% -0.02%
==========================================
Files 252 252
Lines 40797 40822 +25
==========================================
+ Hits 30559 30570 +11
- Misses 8154 8165 +11
- Partials 2084 2087 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Author
|
@zirain Thanks for the speedy approval! What are the next steps for me? |
Member
|
can you fix the conlfict and we need another approval from other maintainers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
feat
What this PR does / why we need it:
When a pod terminates, the shutdown-manager immediately calls
healthcheck/fail. This fails the readiness probe and removes the pod from service endpoints within ~5s.External load balancers that use health checks for deregistration need longer than that. On GKE, the L4 passthrough load balancer probes every 3 seconds and needs 2 failures, so deregistration takes 6 seconds or more. In between, the load balancer keeps sending new connections that kube-proxy no longer routes. They are reset or hang until they time out.
Kubernetes handles this window via KEP-1669. When no other ready endpoints remain, kube-proxy keeps routing to terminating pods that still pass their readiness probe. Failing readiness at the start of shutdown defeats this.
This adds a
drainDelayfield toShutdownConfigwhich delays thehealthcheck/failcall.During the delay the pod stays ready and keeps serving, so the load balancer has time to deregister it.
Which issue(s) this PR fixes:
Fixes #9210
Release Notes: Yes