A checklist for zero-downtime deploys on Kubernetes

1 min readThis post is also available in Turkish →

Tested with: Kubernetes 1.35

Contents
  1. 1. Readiness probe
  2. 2. Graceful shutdown
  3. 3. PodDisruptionBudget
  4. Summary

Setting the Deployment strategy to RollingUpdate does not mean no requests will be dropped during a rollout. Our team was seeing a few hundred 502s on every deploy, and the cause was three separate missing settings.

1. Readiness probe

If no readiness probeReadiness probe A Kubernetes health check that decides whether a pod is ready to receive traffic. is defined, a pod starts receiving traffic the moment it reaches Running. If the application has not yet set up its database connection pool, the first requests fail.

deployment.yaml
readinessProbe:
httpGet:
path: /healthz/ready
port: 8080
periodSeconds: 5
failureThreshold: 2

Note

The readiness endpoint should actually check dependencies, not just return 200 OK. But don’t point the liveness probe at the same endpoint: if the database is briefly unreachable, every pod gets restarted.

2. Graceful shutdown

When a pod is deleted, Kubernetes kicks off two things at once: it sends SIGTERM and removes the pod from the endpoint list. The endpoint update can take a few seconds to reach every node. Requests arriving in that window land on a pod that is shutting down.

The sequence looks like this:

preStop hook (sleep 10) Remove pod from endpoint list SIGTERM Finish in-flight requests, exit Update propagates to nodes Kubelet Pod Endpoint controller kube-proxy (nodes)
What happens when a pod is deleted

The simplest fix is a short preStop wait:

deployment.yaml
lifecycle:
preStop:
exec:
command: ["sleep", "10"]
terminationGracePeriodSeconds: 40

The application also needs to stop accepting new connections and finish in-flight requests when it receives SIGTERM. In Go, this is done with http.Server.Shutdown.

3. PodDisruptionBudget

During node maintenance, several pods can be evicted at the same time. A PDB limits this:

pdb.yaml
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: api
spec:
minAvailable: 2
selector:
matchLabels:
app: api

Summary

After these three changes, the error count during deploys dropped to zero. We added the same settings as defaults to our new service template.

Revision history (1)
  1. Alt bilgiye build imzası, 404 ve çevrimdışı sayfalarına terminal görünümü ekleae75462

Keyboard shortcuts

Search and commands
K
Search
/
Home
gh
Posts
gy
Next post
j
Previous post
k
Toggle theme
t
Show this list
?