Interview Prep/Real-World Interview/Deployments and releases

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 →

  1. Confirm: 502s align with pod terminations, and the ALB access logs show target_status_code of - (connection closed).
  2. Add a preStop sleep longer than the deregistration propagation, and make sure terminationGracePeriodSeconds exceeds it.
  3. 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
  1. 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
  1. 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.

All Real-World Interview questions Roadmap: Interview readiness

More on Deployments and releases