Old pods keep serving traffic for 40 seconds after the new deploy goes live Incident
Rolling update in Kubernetes, new replicas go Ready quickly, but for roughly 40 seconds after the rollout reports complete we still see responses from the old version, confirmed by a version header we stamp on every response. terminationGracePeriodSeconds is 30, we send SIGTERM and the app exits in about 2 seconds. Where are the extra requests coming from?
@rollback_rae · 5mo ago · 3 replies
Endpoint propagation. When a pod goes Terminating, kube-proxy and your ingress controller find out asynchronously, and there is a window where the Service still lists it. Your app exiting in 2 seconds is actually the bug: it dies while load balancers are still handing it work.
Standard fix is a preStop hook that sleeps 5-15 seconds before the app starts shutting down, so the pod stops being advertised, in-flight requests finish, then you exit. Also make readiness start failing on SIGTERM, not just liveness.
The mental model that fixed this for me: readiness controls whether you get new work, SIGTERM handling controls whether you finish the work you already have. Two separate switches, and they have to flip in that order.
Reply
Report
@cors_error_cleo · 5mo ago
Worth putting the sleep inside the app's own signal handler rather than relying on
sleepexisting in a distroless base image. Bit me once and the failure is completely silent.Reply
Report
@hot_heap_hana · 5mo ago
preStop sleep 10 plus failing readiness on SIGTERM took the tail from 40s to about 3s. I had it exactly backwards, I'd spent a week trying to make shutdown faster.
Reply
Report