Skip to main content

Zero-Downtime Kubernetes Deployments: Complete Guide

8 min read
Set up zero-downtime releases

We configure readiness probes and the rollout strategy that fits each of your services.

Master rolling updates, blue-green deployments, and canary releases in Kubernetes to achieve true zero-downtime production deployments.

Why Zero-Downtime Matters

In production environments serving millions of requests, even a few seconds of downtime during a deployment can result in failed transactions, broken user sessions, and SLA violations. Kubernetes provides powerful primitives for zero-downtime deployments, but using them correctly requires understanding rolling updates, readiness probes, and traffic management at the pod level.

This guide walks through three proven deployment strategies and the configuration details that make each one reliable in high-traffic production clusters.

Rolling Update Strategy

Rolling updates are the default deployment strategy in Kubernetes. The controller gradually replaces old pods with new ones, ensuring that a minimum number of pods remain available throughout the process.

Deployment Configuration

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-api
spec:
  replicas: 6
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2
      maxUnavailable: 0
  template:
    spec:
      containers:
      - name: api
        image: registry.example.com/web-api:v2.4.1
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
          failureThreshold: 3
        livenessProbe:
          httpGet:
            path: /livez
            port: 8080
          initialDelaySeconds: 15
          periodSeconds: 10
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "sleep 10"]

Setting maxUnavailable: 0 guarantees that the current replica count never drops below the desired number. The maxSurge: 2 allows Kubernetes to create two extra pods at a time, speeding up the rollout without risking availability.

The preStop Hook

The preStop lifecycle hook with a sleep command is critical. When a pod receives a termination signal, Kubernetes simultaneously removes it from the Service endpoints and sends SIGTERM. Without the sleep, in-flight requests routed before the endpoint removal can hit a terminating pod. The 10-second delay gives the kube-proxy and ingress controllers time to update their routing tables.

Blue-Green Deployments

Blue-green deployments run two complete environments side by side. Traffic switches from the "blue" (current) environment to the "green" (new) environment in a single operation.

Implementation with Services

apiVersion: v1
kind: Service
metadata:
  name: web-api
spec:
  selector:
    app: web-api
    version: green
  ports:
  - port: 80
    targetPort: 8080

Deploy the green environment with the new version label. Once readiness probes confirm all green pods are healthy, update the Service selector from version: blue to version: green. The switch is atomic at the Service level, meaning traffic shifts within seconds.

Rollback Procedure

Rolling back is equally fast. Change the selector back to version: blue and the previous environment handles all traffic immediately. Keep the blue deployment running for at least 30 minutes after a successful switch to allow quick rollbacks.

Canary Releases

Canary releases route a small percentage of traffic to the new version, letting you validate behavior under real production load before a full rollout.

Using Ingress Annotations

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-api-canary
  annotations:
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-weight: "10"
spec:
  rules:
  - host: api.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web-api-canary
            port:
              number: 80

Start with 10 percent traffic, monitor error rates and latency in your observability stack, and gradually increase the weight to 25, 50, and finally 100 percent.

The controller these annotations belong to is retired. Kubernetes moved the community Ingress NGINX controller (kubernetes/ingress-nginx) to end of life in March 2026, with no further releases for bug fixes or security patches. Existing installations keep routing traffic exactly as before, which is the part that catches people out: nothing breaks to tell you. The annotations above still work on an installation you already run, so treat them as a bridge while you plan a move to Gateway API or another maintained controller, not as the way to build a new canary. F5's separately maintained NGINX Ingress Controller (nginxinc/kubernetes-ingress) is a different codebase and is not affected by this. Canary releases without a service mesh covers the replacement path, including weighted canaries driven by a progressive delivery controller and the automated pass or fail check against Prometheus.

Pod Disruption Budgets

Regardless of strategy, always define a PodDisruptionBudget to protect against voluntary disruptions such as node drains during cluster upgrades:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-api-pdb
spec:
  minAvailable: 4
  selector:
    matchLabels:
      app: web-api

Best Practices Checklist

  • Always set maxUnavailable: 0 for critical services
  • Configure readiness probes that check actual application health, not just TCP port availability
  • Use preStop hooks to drain connections gracefully
  • Set terminationGracePeriodSeconds long enough for in-flight requests to complete
  • Monitor deployment progress with kubectl rollout status
  • Automate rollback triggers based on error rate thresholds in your CI/CD pipeline

Zero-downtime deployments require more than just Kubernetes defaults. Proper probe configuration, lifecycle hooks, and disruption budgets work together to ensure seamless releases. For complex microservice architectures, consider our Kubernetes management services to implement these patterns at scale across your clusters.

Frequently asked questions

What maxSurge and maxUnavailable values give a zero-downtime Kubernetes rolling update?

Set maxUnavailable to 0 so the replica count never drops below the desired number during the rollout. A maxSurge of 2 lets Kubernetes create two extra pods at a time, which speeds up the update without risking availability. Rolling updates are the default Kubernetes strategy, and maxUnavailable 0 belongs on every critical service.

Why does a Kubernetes pod need a preStop sleep for zero-downtime deployments?

When a pod is terminated, Kubernetes removes it from the Service endpoints and sends SIGTERM at the same time. Requests routed just before the endpoint removal can still land on the terminating pod. A preStop hook that runs sleep 10 adds a 10 second delay, giving kube-proxy and the ingress controllers time to update their routing tables. Set terminationGracePeriodSeconds long enough for in-flight requests to finish as well.

How does a blue-green deployment switch traffic in Kubernetes?

Run the new version as a separate green Deployment next to the blue one, labelled with its own version. Once readiness probes confirm every green pod is healthy, change the version label in the Service selector from blue to green. The switch is atomic at the Service level, and traffic shifts within seconds.

How do I roll back a Kubernetes blue-green deployment?

Point the version label in the Service selector back to blue, and the previous environment takes all traffic immediately. A rollback that fast needs the blue Deployment to still be running, so keep it up for at least 30 minutes after a successful switch to green.

How do I send 10 percent of traffic to a canary with NGINX Ingress annotations?

Create a second Ingress for the canary Service with nginx.ingress.kubernetes.io/canary set to "true" and nginx.ingress.kubernetes.io/canary-weight set to "10". Watch error rates and latency, then raise the weight to 25, 50 and finally 100 percent. These annotations belong to the community Ingress NGINX controller, which reached end of life in March 2026, so treat them as a bridge on an existing installation and pick a maintained option for a new canary setup.

Is the Kubernetes Ingress NGINX controller still maintained in 2026?

No. Kubernetes moved the community Ingress NGINX controller (kubernetes/ingress-nginx) to end of life in March 2026, with no further releases for bug fixes or security patches. Existing installations keep routing traffic as before, so nothing breaks to warn anyone, and the next step is planning a move to Gateway API or another maintained controller. F5's NGINX Ingress Controller (nginxinc/kubernetes-ingress) is a separate codebase that is not affected by the retirement.

What does a PodDisruptionBudget do during Kubernetes deployments and node drains?

A PodDisruptionBudget protects a workload against voluntary disruptions, such as node drains during cluster upgrades, by keeping a minimum number of pods available. With minAvailable set to 4 and a selector on app web-api, at least four web-api pods stay up while nodes are drained. Define one for every service whatever deployment strategy it uses.

What should a Kubernetes readiness probe check for zero-downtime deployments?

Actual application health, through an HTTP check such as GET /healthz on port 8080, because TCP port availability alone does not show that the app can serve requests. One working setup waits 5 seconds, probes every 5 seconds and marks the pod unready after 3 failures, with a separate /livez endpoint for the liveness probe. Follow each rollout with kubectl rollout status.

Read how we handle it in Cloud & Server Management.