Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Lab 02: Deployment Strategies

Strategy comparison

  • Blue-green: new RS gets full replicas, tested via preview service, then active service selector switches all at once
    • ~2x pods while both exist, old RS kept for scaleDownDelaySeconds (default 30s) for fast rollback
  • Canary: steps shift weight gradually; without a traffic router weight is approximated by pod ratio
    • 10 replicas, setWeight: 10 = 1 canary pod

Setup

  • rollouts-demo serves its color at /color
kubectl create namespace strategies-demo
kubectl config set-context --current --namespace=strategies-demo
kubectl run test-pod --image=curlimages/curl --restart=Never -- sleep 3600

Blue-green

apiVersion: v1
kind: Service
metadata:
  name: bluegreen-active
spec:
  selector:
    app: bluegreen-demo
  ports:
  - name: http
    port: 80
    targetPort: http
---
apiVersion: v1
kind: Service
metadata:
  name: bluegreen-preview
spec:
  selector:
    app: bluegreen-demo
  ports:
  - name: http
    port: 80
    targetPort: http
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: bluegreen-demo
spec:
  replicas: 3
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: bluegreen-demo
  template:
    metadata:
      labels:
        app: bluegreen-demo
    spec:
      containers:
      - name: app
        image: argoproj/rollouts-demo:blue
        ports:
        - name: http
          containerPort: 8080
  strategy:
    blueGreen:
      activeService: bluegreen-active
      previewService: bluegreen-preview
      autoPromotionEnabled: false
      scaleDownDelaySeconds: 30
kubectl apply -f bluegreen.yaml
kubectl argo rollouts get rollout bluegreen-demo --watch
kubectl exec test-pod -- curl -s http://bluegreen-active/color   # blue
  • Controller adds a rollouts-pod-template-hash selector to both services
  • autoPromotionEnabled: false = pause after preview RS is ready

Update, test, promote

kubectl argo rollouts set image bluegreen-demo app=argoproj/rollouts-demo:yellow
kubectl exec test-pod -- curl -s http://bluegreen-preview/color   # yellow
kubectl exec test-pod -- curl -s http://bluegreen-active/color    # still blue
kubectl argo rollouts promote bluegreen-demo
kubectl exec test-pod -- curl -s http://bluegreen-active/color    # yellow

Abort

kubectl argo rollouts set image bluegreen-demo app=argoproj/rollouts-demo:red
kubectl argo rollouts abort bluegreen-demo
kubectl exec test-pod -- curl -s http://bluegreen-active/color    # yellow
  • Abort before promotion: active never moved, preview RS scaled down
  • Rolling back after promotion: kubectl argo rollouts undo bluegreen-demo (or set the old image) and promote; old RS is only kept warm for scaleDownDelaySeconds

Canary

apiVersion: v1
kind: Service
metadata:
  name: canary-service
spec:
  selector:
    app: canary-demo
  ports:
  - name: http
    port: 80
    targetPort: http
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: canary-demo
spec:
  replicas: 10
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: canary-demo
  template:
    metadata:
      labels:
        app: canary-demo
    spec:
      containers:
      - name: app
        image: argoproj/rollouts-demo:blue
        ports:
        - name: http
          containerPort: 8080
  strategy:
    canary:
      steps:
      - setWeight: 10
      - pause: {duration: 30s}
      - setWeight: 25
      - pause: {duration: 30s}
      - setWeight: 50
      - pause: {duration: 30s}
      - setWeight: 75
      - pause: {duration: 30s}
kubectl apply -f canary.yaml
kubectl argo rollouts set image canary-demo app=argoproj/rollouts-demo:yellow
kubectl argo rollouts get rollout canary-demo --watch

# sample traffic while it runs
for i in $(seq 20); do kubectl exec test-pod -- curl -s http://canary-service/color; echo; done | sort | uniq -c
  • Mix of blue/yellow follows the step weight
  • Auto-advances on pause durations, finishes at 100% after the last step

Manual steps

  • Change steps to use pause: {} and a new image (green)
      steps:
      - setWeight: 20
      - pause: {}
      - setWeight: 50
      - pause: {}
      - setWeight: 100
kubectl argo rollouts promote canary-demo   # one step per promote
kubectl argo rollouts promote canary-demo --full   # skip remaining steps

Abort

kubectl argo rollouts set image canary-demo app=argoproj/rollouts-demo:red
kubectl argo rollouts abort canary-demo
  • Canary RS scaled to 0, traffic back to stable (green); status Degraded

Which one

  • Blue-green: instant switch, pre-prod testing on preview, instant rollback, needs 2x capacity
  • Canary: gradual, real traffic validation, less capacity, pairs with analysis (lab 04)

Cleanup

kubectl delete namespace strategies-demo