🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes: Deployment Strategies

A deployment strategy is the plan for swapping an old version for a new one. The plan decides how much downtime and risk the swap carries.

Rolling keeps the app up

Old pods and new pods run together for a short time. Traffic never stops.

kubectl get pods -l app=web -w

Recreate stops everything first

The old pods all stop before the new pods start. The app is down in between.

kubectl patch deployment web -p '{"spec":{"strategy":{"type":"Recreate"}}}'

Canary tests with a few users

A small share of traffic reaches the new version. A bad release hurts only that small share.

kubectl get pods -l app=web,version=v2

Pick by risk

Each strategy trades downtime against risk. Rolling is the safe default for most apps.

kubectl get deployment web -o jsonpath='{.spec.strategy.type}'

Example

kubectl get deployment web -o jsonpath='{.spec.strategy.type}'
kubectl describe deployment web | grep -A 3 Strategy

Key points

  • Deployment strategy: the plan a Deployment follows when it replaces old pods with new pods
  • Rolling update replaces pods in small batches and keeps the app running
  • Recreate stops every old pod before it starts any new pod
  • Blue-green runs the old version and the new version side by side and then switches traffic
  • Canary sends a small share of traffic to the new version first
  • Zero downtime is the goal of rolling, blue-green and canary releases
  • Recreate causes downtime, so it suits apps that cannot run two versions at once

In this example, the first command prints the strategy type of the web Deployment. The second command shows the strategy detail. The output shows a rolling update. At most 25 percent of pods are unavailable during the swap. At most 25 percent extra pods run at the same time.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Which strategy sends only a small share of traffic to the new version first?