Every deploy causes a short spike of 502 errors from the ALB. Why, and how do you fix it?
IntermediateScenarioDeployments and releases
Answer
Situation read → Classic race between pod termination and target deregistration. The pod stops accepting connections while the ALB still routes to it.
What I'd do →
- Confirm: 502s align with pod terminations, and the ALB access logs show
target_status_codeof-(connection closed). - Add a
preStopsleep longer than the deregistration propagation, and make sureterminationGracePeriodSecondsexceeds it. - Tune the target group deregistration delay to match, via the AWS Load Balancer Controller annotation:
alb.ingress.kubernetes.io/target-group-attributes: deregistration_delay.timeout_seconds=30
- With IP-mode targets, enable pod readiness gates so new pods only count as ready once the ALB marks them healthy:
kubectl label namespace prod elbv2.k8s.aws/pod-readiness-gate-inject=enabled
- Check the app's keep-alive timeout is longer than the ALB idle timeout (60s default), otherwise the app closes idle connections the ALB still reuses.
Why → Each fix closes one window: preStop for shutdown, readiness gates for startup, keep-alive for idle connections.
Interview tip → The keep-alive mismatch is the detail that separates people who have debugged this from people who have read about it.
More on Deployments and releases
A deploy went out and p99 latency doubled. Walk me through it.IntermediateYou deployed a new version and half the pods are in CrashLoopBackOff. What do you do?BeginnerA release passed every test in staging but broke in production. How do you investigate?IntermediateHow would you design a zero-downtime deployment for a stateless API on Kubernetes?BeginnerHow would you set up a canary release, and what decides whether it gets promoted?IntermediateBlue-green or canary? How do you choose for a specific service?Beginner