Skip to main content

Implementing Kubernetes Deployment Strategies

Release new Kubernetes versions with zero downtime using rolling updates, blue-green switching, and canary traffic splitting, with a tested lab.

52 Terms

Overview and What You Will Learn

Kubernetes has three main ways to release a new version without downtime: a rolling update replaces pods gradually, blue-green runs two full copies and switches traffic at once, and a canary sends a small share of traffic to the new version first. Pick by how much risk you can tolerate and how much spare capacity you can afford.

In this lab, you will:

  • Run a rolling update, break it on purpose, and watch Kubernetes keep the old version serving
  • Switch a Service between blue and green versions and roll back in seconds
  • Split traffic between stable and canary pods and measure the split
  • Clean up the namespace

Why This Matters in Production

Every release puts users at risk if it is done carelessly. Picture a food delivery platform like Swiggy shipping during dinner peak: a naive release means thousands of requests hitting errors or half-started pods. The strategy decides how many users a bad version can reach, and how fast you can undo it.

Core Principles

Which Strategy Fits

Each strategy trades blast radius, cost and rollback speed differently.

Strategy Extra capacity Rollback
Rolling update Small, set by maxSurge kubectl rollout undo, gradual
Blue-green A full second copy Flip the selector, near instant
Canary A few extra pods Scale the canary to zero

A fourth built-in strategy, Recreate, stops every old pod before starting new ones. It causes downtime, so use it only when two versions must never run together.

How a Rolling Update Works

Kubernetes starts new pods up to maxSurge, waits until each passes its readiness probe, and only then terminates old pods, never dropping below the count maxUnavailable allows.

flowchart TD A([New image applied]) --> B[Start new pod
within maxSurge] B --> C{Readiness
probe passes?} C -->|Yes| D[Terminate one old pod] C -->|No| E[Rollout stalls
old pods keep serving] D --> F{More old pods?} F -->|Yes| B F -->|No| G([Rollout complete]) classDef start fill:#475569,color:#FFFFFF classDef step fill:#326CE5,color:#FFFFFF classDef decision fill:#F59E0B,color:#111827 classDef bad fill:#EF4444,color:#FFFFFF classDef good fill:#10B981,color:#FFFFFF class A start class B,D step class C,F decision class E bad class G good
Remember

The readiness probe is what makes a rolling update safe. Without it Kubernetes treats a pod as ready the moment it starts, and users reach a pod that has not finished booting.

How Blue-Green Works

Two Deployments run side by side, distinguished by a slot label. A Service selects one slot, and changing that selector moves all traffic at once.

flowchart LR U([Users]) --> S{{Service
selector slot}} S -->|slot=blue| B[Blue v1
live] S -.->|slot=green| G[Green v2
idle until switch] classDef user fill:#475569,color:#FFFFFF classDef svc fill:#F59E0B,color:#111827 classDef blue fill:#326CE5,color:#FFFFFF classDef green fill:#10B981,color:#FFFFFF class U user class S svc class B blue class G green
Tip

Blue-green helps with database changes only if both versions work with the same schema at the same time. Use expand-and-contract migrations: add new columns first, ship the code, and remove old columns in a later release.

How a Replica-Based Canary Works

A Service that selects on app alone spreads connections across every matching pod, stable and canary. With 9 stable pods and 1 canary pod, roughly 10% of new connections reach the canary.

flowchart LR U([Users]) --> S{{Service
selector app}} S -->|About 90%| ST[Stable v1
9 pods] S -->|About 10%| CA[Canary v2
1 pod] classDef user fill:#475569,color:#FFFFFF classDef svc fill:#F59E0B,color:#111827 classDef stable fill:#326CE5,color:#FFFFFF classDef canary fill:#F97316,color:#FFFFFF class U user class S svc class ST stable class CA canary

The split is approximate and tied to pod counts, and you cannot route by header or exact percentage. For that, use ingress canary annotations, Gateway API traffic weights, a service mesh, or Argo Rollouts, which automates the steps below with metric checks.

Detailed Step-by-Step Practical Lab

The lab uses a throwaway namespace and small public images, so it is safe on any cluster. Demo services answer with their version name, which lets you see which pods served a request.

  1. Create the namespace:
Bash
kubectl create namespace strategies-lab
  1. Deploy a rolling update configuration. With maxUnavailable: 0 and maxSurge: 2, capacity never drops below 6 pods:
YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-api
namespace: strategies-lab
spec:
replicas: 6
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 0
selector:
matchLabels:
app: order-api
template:
metadata:
labels:
app: order-api
spec:
containers:
- name: order-api
image: nginx:1.26
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 5
Bash
kubectl apply -f order-api.yaml
kubectl rollout status deployment/order-api -n strategies-lab
  1. Roll out a new version, then check the history. In a GitOps workflow you would edit the manifest instead of using set image, so the change lives in Git:
Bash
kubectl set image deployment/order-api order-api=nginx:1.27 -n strategies-lab
kubectl rollout status deployment/order-api -n strategies-lab
kubectl rollout history deployment/order-api -n strategies-lab
kubectl get rs -n strategies-lab
  1. Break a release on purpose. The new pods cannot pull their image, so they never become ready, and the old pods keep serving. Then undo:
Bash
kubectl set image deployment/order-api order-api=nginx:does-not-exist -n strategies-lab
kubectl rollout status deployment/order-api -n strategies-lab --timeout=60s # times out
kubectl get pods -n strategies-lab # 6 healthy old pods plus pods stuck in ErrImagePull
kubectl rollout undo deployment/order-api -n strategies-lab
kubectl rollout status deployment/order-api -n strategies-lab
  1. Set up blue-green. Create both slots from one template, and point the Service at blue:
Bash
for pair in blue:v1 green:v2; do
SLOT=${pair%%:*}
VERSION=${pair##*:}
cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: payment-api-$SLOT
namespace: strategies-lab
spec:
replicas: 3
selector:
matchLabels:
app: payment-api
slot: $SLOT
template:
metadata:
labels:
app: payment-api
slot: $SLOT
spec:
containers:
- name: payment-api
image: hashicorp/http-echo:1.0
args: ["-text=payment-api $SLOT $VERSION", "-listen=:8080"]
ports:
- containerPort: 8080
EOF
done
cat << 'EOF' | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: payment-api
namespace: strategies-lab
spec:
selector:
app: payment-api
slot: blue
ports:
- port: 80
targetPort: 8080
EOF
kubectl get pods -n strategies-lab -l app=payment-api
  1. Test green directly, switch traffic, then roll back. A short-lived curl pod shows which slot answers:
Bash
kubectl port-forward deployment/payment-api-green 8081:8080 -n strategies-lab &
sleep 2 && curl -s localhost:8081 && kill %1 # payment-api green v2, before any user sees it
curl_pod() {
kubectl run curl --rm -i --restart=Never --image=curlimages/curl \
-n strategies-lab --command -- curl -s payment-api 2>/dev/null
}
curl_pod # blue v1
kubectl patch service payment-api -n strategies-lab \
-p '{"spec":{"selector":{"slot":"green"}}}'
curl_pod # green v2
kubectl patch service payment-api -n strategies-lab \
-p '{"spec":{"selector":{"slot":"blue"}}}'
curl_pod # blue v1 again, rollback done
  1. After green is confirmed stable, scale blue to zero rather than deleting it, so you can still switch back quickly:
Bash
kubectl patch service payment-api -n strategies-lab \
-p '{"spec":{"selector":{"slot":"green"}}}'
kubectl scale deployment payment-api-blue --replicas=0 -n strategies-lab
  1. Set up a canary with 9 stable pods and 1 canary pod behind one Service:
Bash
for pair in stable:9:v1 canary:1:v2; do
IFS=: read TRACK REPLICAS VERSION <<< "$pair"
cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: notification-api-$TRACK
namespace: strategies-lab
spec:
replicas: $REPLICAS
selector:
matchLabels:
app: notification-api
track: $TRACK
template:
metadata:
labels:
app: notification-api
track: $TRACK
spec:
containers:
- name: notification-api
image: hashicorp/http-echo:1.0
args: ["-text=notification-api $VERSION", "-listen=:8080"]
ports:
- containerPort: 8080
EOF
done
cat << 'EOF' | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: notification-api
namespace: strategies-lab
spec:
selector:
app: notification-api
ports:
- port: 80
targetPort: 8080
EOF
  1. Measure the split with 50 requests from inside the cluster. Expect roughly 45 stable and 5 canary, with some random variation:
Bash
measure() {
kubectl run curl-loop --rm -i --restart=Never --image=curlimages/curl \
-n strategies-lab --command -- sh -c \
'for i in $(seq 1 50); do curl -s notification-api; done' 2>/dev/null | sort | uniq -c
}
measure
  1. Increase the canary. Scale the canary up first, so total capacity never dips, then scale stable down. Re-measure at each step, and in a real release watch error rate and latency in your metrics before moving on:
Bash
kubectl scale deployment notification-api-canary --replicas=3 -n strategies-lab
kubectl scale deployment notification-api-stable --replicas=7 -n strategies-lab
measure
kubectl scale deployment notification-api-canary --replicas=0 -n strategies-lab
kubectl scale deployment notification-api-stable --replicas=9 -n strategies-lab

In a real release, you finish by updating the stable Deployment to the new image and scaling the canary to zero, which keeps one Deployment as the source of truth.

  1. Clean up:
Bash
kubectl delete namespace strategies-lab

Production Best Practices & Common Pitfalls

Common Mistake

Using maxSurge: 0 with maxUnavailable: 1. Kubernetes then removes an old pod before a new one is ready, so capacity dips during every release and a traffic spike drops requests. Use maxUnavailable: 0 for production. Setting both to zero is rejected.

Tip

Add a PodDisruptionBudget and a sensible terminationGracePeriodSeconds with a preStop hook, so in-flight requests finish when old pods are removed.

  • Define a readiness probe on every Deployment. It is the gate that stops traffic reaching unready pods during any strategy.
  • Keep the old blue Deployment at zero replicas for at least a day. A bug found the next morning can then be undone by flipping the selector.
  • Start canaries small and watch real signals. Begin at 5 to 10% for at least 15 minutes and check error rate, latency and memory, because a Running pod only proves it started. kubectl top shows resource use, not errors.
  • Mind autoscalers. An HPA on both canary and stable Deployments fights manual scaling, so pause it or use a tool that manages traffic by weight.
  • Make sure both versions can run together. All three strategies briefly run old and new code at once, so APIs and database schemas must stay compatible.
  • Keep revision history. revisionHistoryLimit controls how many ReplicaSets remain for rollout undo.

Quick Reference & Troubleshooting Commands

Command Description
kubectl rollout status deployment/NAME Watch a rolling update
kubectl rollout undo deployment/NAME Roll back to the previous revision
kubectl rollout history deployment/NAME List past revisions
kubectl rollout pause deployment/NAME Pause a rollout midway
kubectl rollout resume deployment/NAME Resume a paused rollout
kubectl patch service NAME -p '{"spec":{"selector":{"slot":"green"}}}' Switch blue-green traffic
kubectl scale deployment NAME --replicas=N Change the canary share
Problem Likely cause Fix
Rollout stuck New pods fail readiness or image pull Run kubectl describe pod and fix or undo
Errors during a rolling update No readiness probe Add one before the next release
Service has no endpoints after a switch Selector matches no pods Compare Service selector and pod labels
Canary gets the wrong share Pod counts or keep-alive connections Check replicas, or use weight-based routing
rollout undo does nothing useful Revision history was pruned Raise revisionHistoryLimit

Resources

Velero vs etcd Snapshot: Which Do You Need?

Velero vs etcd Snapshot: Which Do You Need?

Velero and etcd snapshots protect different layers of a Kubernetes cluster. See what each backs up, what each misses, and why most DR needs both.

11 min read•Aug 2026
Istio Ambient vs Linkerd in 2026: Which Mesh?

Istio Ambient vs Linkerd in 2026: Which Mesh?

Istio Ambient cuts the sidecar tax at L4, but L7 adds waypoint hops, and Linkerd stable builds now come from Buoyant. Choose with tests.

11 min read•Aug 2026
Nginx Ingress vs Traefik vs Gateway API in 2026

Nginx Ingress vs Traefik vs Gateway API in 2026

Ingress-NGINX is retired. Compare Traefik and Gateway API controllers as replacements, plus a safe migration plan that avoids outages.

10 min read•Aug 2026
OPA Gatekeeper vs Kyverno: Policy Engine in 2026

OPA Gatekeeper vs Kyverno: Policy Engine in 2026

OPA Gatekeeper vs Kyverno compared for 2026: Rego vs YAML, mutation, reporting, and operations, plus how to pick a Kubernetes policy engine.

10 min read•Aug 2026
Helm vs Kustomize in 2026: Templating vs Patching

Helm vs Kustomize in 2026: Templating vs Patching

Helm vs Kustomize compared for 2026 - templating vs patching, Helm 4's new features, and why most production teams end up running both.

5 min read•Aug 2026
Prometheus vs Datadog vs New Relic: Real Costs

Prometheus vs Datadog vs New Relic: Real Costs

Prometheus, Datadog, and New Relic compared for 2026 - real pricing at scale, hidden cost drivers, and which fits a Kubernetes-heavy stack.

5 min read•Aug 2026
Cluster Autoscaler vs Karpenter for EKS in 2026

Cluster Autoscaler vs Karpenter for EKS in 2026

Cluster Autoscaler vs Karpenter on EKS: scale-up speed, bin-packing, Spot handling, Auto Mode limits and a safe migration path, with v1 NodePool YAML.

11 min read•Aug 2026
GKE vs EKS vs AKS in 2026: Which Fits Your Team?

GKE vs EKS vs AKS in 2026: Which Fits Your Team?

GKE, EKS, and AKS compared for 2026 - control plane pricing, Autopilot vs Karpenter vs Node Auto Provisioning, and which platform actually fits your team.

5 min read•Aug 2026
K3s vs K8s vs MicroK8s: Which Distro in 2026?

K3s vs K8s vs MicroK8s: Which Distro in 2026?

Compare K3s, upstream Kubernetes and MicroK8s on footprint, datastores, HA and updates, and pick the right fit for edge, dev or production.

10 min read•Aug 2026
Canary Deployments with Argo Rollouts & Flagger

Canary Deployments with Argo Rollouts & Flagger

Ship to 5% of users first and auto-rollback on bad metrics: canary deployments on Kubernetes with Argo Rollouts, Flagger, and Gateway API.

11 min read•Jun 2026
OpenTelemetry Explained: Metrics, Logs, Traces

OpenTelemetry Explained: Metrics, Logs, Traces

OpenTelemetry in practice: instrument a Node.js service, run a production Collector, sample traces and link metrics, logs and traces in Grafana.

11 min read•Jun 2026
Kubernetes Cost Optimization Without SLO Risk

Kubernetes Cost Optimization Without SLO Risk

Kubernetes clusters average about 8% CPU use. Cut waste safely with request rightsizing, autoscaling, spot, and OpenCost, keeping SLOs.

11 min read•Jun 2026
ArgoCD vs FluxCD: GitOps for Kubernetes in 2026

ArgoCD vs FluxCD: GitOps for Kubernetes in 2026

ArgoCD vs FluxCD compared for 2026: UI, multi-tenancy, Helm, image automation and pruning risks, with a clear guide to picking your GitOps engine.

10 min read•Jun 2026

Explore More in Kubernetes Networking and Traffic Management

All 6 Topics

Frequently Asked Questions

Is Implementing Kubernetes Deployment Strategies free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Implementing Kubernetes Deployment Strategies topic cover?

Release new Kubernetes versions with zero downtime using rolling updates, blue-green switching, and canary traffic splitting, with a tested lab.

Found a mistake, an outdated step or a broken link?