How would you design a zero-downtime deployment for a stateless API on Kubernetes?
BeginnerScenarioDeployments and releases
Answer
Situation read → Zero downtime needs four things together: a rolling strategy that never drops capacity, accurate readiness, graceful shutdown, and enough replicas.
What I'd do →
- Rolling update that adds before removing:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 0
- A readiness probe that checks the app can actually serve (DB pool ready), separate from liveness.
- Graceful shutdown: the app handles SIGTERM, plus a short
preStopsleep so the endpoint is removed from the load balancer before the process stops.
lifecycle:
preStop:
exec:
command: ["sleep", "10"]
terminationGracePeriodSeconds: 40
- A PodDisruptionBudget and at least 3 replicas spread across zones.
- Backward-compatible API and DB changes so old and new versions can run side by side.
Why → Without the preStop delay, kube-proxy and the ALB can still send requests to a pod that has already received SIGTERM, giving a burst of 502s on every deploy.
Interview tip → Mention the 502 burst on deploys; it shows you have actually seen this in production.
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?IntermediateEvery deploy causes a short spike of 502 errors from the ALB. Why, and how do you fix it?IntermediateHow 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