Kubernetes rolling update causes 503s: long preStop hook and readiness removal drop in-flight requests
Environment
Managed cluster (GKE-style) running a microservice as a Deployment behind an NGINX IngressController. Pods define a preStop hook that performs a graceful shutdown script (closes resources, flushes queues) and a readinessProbe HTTP endpoint. terminationGracePeriodSeconds set to default 30s.
Symptoms
During Deployments/rollouts, users see frequent 503 Service Unavailable responses and aborted in-flight POSTs. Issues happen even when pods report Ready prior to rollout and when new pods become Ready quickly.
Observations
Pod lifecycle logs show controller sends SIGTERM, preStop starts and runs for ~25s. ReadinessProbe appears to stop returning 200 only after preStop begins (or sometimes after a delay). Ingress logs show upstream marked as unhealthy and NGINX returns 503s while preStop is still running; new pod not yet fully serving some internal caches, so requests hit removed-but-still-shutting pods.
Already attempted
Increased terminationGracePeriodSeconds to 60s (partial mitigation) and attempted to make preStop faster by reducing cleanup steps; adding explicit readinessProbe failures inside preStop was attempted but timing remained flaky. Rolling update strategy set to maxUnavailable 1, maxSurge 1.
Question
How to ensure pods stop receiving new requests immediately on SIGTERM and allow preStop/termination to finish without causing 503s? What pod spec/readiness changes are safest and reversible?
Verified community troubleshooting
Make the pod stop receiving new traffic as soon as it begins shutdown. Modify the app to: on SIGTERM, immediately set readiness to false (or close the HTTP listener) and continue background cleanup; this tells kubelet/Ingress to remove the pod from rotation before preStop runs. Add a short readiness endpoint change and keep terminationGracePeriodSeconds long enough for cleanup. Verify by hitting the service with continuous requests and doing a rollout: healthy pods should accept traffic while the shutting pod finishes outstanding requests without 503s. Roll back by restoring previous signal handling if behavior is undesirable.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Cloud Computing21% match
Kubernetes admission webhook causes API server 404s for gRPC services only when behind AWS NLB with proxy-protocol enabled
Open0 answers - Cloud Computing20% match
Kubernetes pods OOMKilled while node shows 80GB free memory on Ubuntu 20.04 (kubelet+Docker cgroup mismatch suspected)
Open0 answers