Strategy comparison

StrategyBuilt-inDowntimeTwo versionsUse
RollingUpdateYes (default)NoYes brieflyProduction zero-downtime
RecreateYesYesNoDev/test, breaking changes
Blue/GreenManualNoYes fullInstant rollback
CanaryManualNoYes partialGradual / A/B

Blue/Green and Canary are not built-in: patterns implemented using multiple Deployments and Service label selectors.

RollingUpdate (default)

spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 40%
      maxSurge: 10%
  minReadySeconds: 60 # must stay Ready this long before proceeding
  • Service routes to both old and new Pods during rollout
  • Breaking API changes risky: keep backward compatible

Recreate

spec:
  strategy:
    type: Recreate
  • All old Pods terminated before new ones start: downtime

Blue/Green: switch via Service selector

Blue Deployment (current)

metadata:
  name: webapp-blue
  labels: {app: webapp, version: blue}
spec:
  template:
    metadata:
      labels: {app: webapp, version: blue}

Service points to blue:

spec:
  selector:
    app: webapp
    version: blue

Green Deployment (new version)

metadata:
  name: webapp-green
  labels: {app: webapp, version: green}
spec:
  template:
    metadata:
      labels: {app: webapp, version: green}

Switch Traffic

Change to selector to green to switch all traffic instantly:

spec:
  selector:
    app: webapp
    version: green

Or Use JSON patch to apply update directly from CLI:

kubectl patch svc webapp --type=merge -p '{"spec":{"selector":{"version":"green"}}}'

To Rollback just flip selector back to blue.

Canary: split traffic by replica ratio

To route 10% traffic through Canary version, set canary replicas replicas to 1 and stable deployment replicas to 10, and use same label as stable. Then use the same label as service selector.

Stable deployment

# Stable deployment: 9 replicas
metadata:
  name: webapp-stable
  labels:
  - app: webapp
  - track: stable

Canary Deployment

metadata:
  name: webapp-canary
  labels:
  - app: webapp
  - track: stable
spec:
  replicas: 1 # 
  template:
    metadata:
      labels:
        app: webapp
        track: canary

Service

Use a selector that matches both stable and canary pods

spec:
  selector:
    app: webapp

Exam gotchas

  • Canary: second Deployment with same app label, different image; Service selector on app only → routes to both; ratio = replica counts
  • Canary needs shared label on both Deployments for same Service