Interview Prep/Kubernetes/Services, DNS, Ingress and NetworkPolicy

Requests to a Service sometimes hit a Pod that was deleted seconds ago, causing errors during every rollout.

AdvancedTroubleshootingServices, DNS, Ingress and NetworkPolicy
Answer

Likely causes → Endpoint removal is asynchronous. When a Pod gets deletion, kubelet sends SIGTERM while kube-proxy on every node, ingress controllers and cloud LBs are still removing it from their backends. An app that stops listening immediately receives traffic for a few more seconds.

Diagnose →

kubectl get events --field-selector reason=Killing -n web --watch &
kubectl logs -n ingress-nginx deploy/ingress-nginx-controller -f | grep -E ' 50[23] '

Fix → Delay shutdown so endpoint removal propagates first, then drain:

lifecycle:
  preStop:
    sleep: {seconds: 10}
terminationGracePeriodSeconds: 45

The app should keep serving in-flight requests after SIGTERM and stop accepting new ones gracefully.

Prevent → Standard preStop in base charts; with AWS LB Controller, also tune target group deregistration_delay and use Pod readiness gates.

All Kubernetes questions Roadmap: Kubernetes networking, storage & scaling

More on Services, DNS, Ingress and NetworkPolicy