Skip to main content

Implementing Blue-Green and Canary Deployments

Implement blue-green and canary deployments in CI/CD with Argo Rollouts, Prometheus analysis gates, and automatic rollback on failure.

22 Terms

Overview and What You Will Learn

Blue-green and canary are the two standard zero-downtime release strategies. Blue-green runs the new version next to the old one and switches all traffic at once after you have tested it. Canary sends the new version a small, growing share of real traffic and lets metrics decide whether to continue. Both give you a fast, automatic way back when a release is bad.

In this lab you will:

  • Choose between blue-green and canary for a given service.
  • Install Argo Rollouts and convert a Deployment into a Rollout.
  • Split traffic with Istio so the canary gets an exact percentage.
  • Gate each step with a Prometheus analysis that fails closed.
  • Trigger a rollout from CI without stored cloud keys.
  • Prove automatic rollback works before you trust it in production.
  • Run the same service as a blue-green release with a preview environment.

Why This Matters in Production

A rolling update sends full production traffic to a new pod as soon as its readiness probe passes, and a readiness probe only proves the process is running, not that the code is correct. For a payments or checkout path, such as the traffic Razorpay or Stripe handle, a subtle bug can fail thousands of requests before anyone is paged.

Canary bounds that damage to a small, known slice of traffic for a known short window. Blue-green lets you smoke-test the whole new version with zero customer traffic, then switch with an instant way back. Teams at companies like Netflix and Spotify rely on this kind of progressive delivery so that releasing is routine, not an event.

Common Mistake

Calling a release "canary" when it jumps from 5 to 100 percent with one manual click and no metric check in between. Without an automated gate it is just a slower rolling update. The value is the analysis deciding whether to proceed.

Core Principles

Blue-green and canary compared

Strategy Best when Trade-off
Blue-green You need a full preview and instant switch Double capacity during cutover
Canary You want real-traffic evidence in small steps Needs good metrics and traffic routing

Blue-green keeps two full versions side by side. Blue is live and green is the new version, idle until tested. A switch moves every request to green at once, and rollback is switching back, which is fast because blue never stopped running.

flowchart TD A[Deploy green, no traffic] --> B[Smoke test preview] B --> C{Checks pass?} C -->|Yes| D[Switch traffic to green] C -->|No| E[Discard green] D --> F[Keep blue warm, then scale down] classDef step fill:#326CE5,color:#FFFFFF classDef good fill:#10B981,color:#FFFFFF classDef bad fill:#EF4444,color:#FFFFFF class A,B,C step class D,F good class E bad

Canary exposes the new version gradually and checks metrics between steps. Each step either sets a traffic weight, pauses, or runs an analysis. A failed analysis aborts the rollout and returns all traffic to the stable version.

flowchart TD A[Canary at 5 percent] --> B[Analysis: error rate] B --> C{Healthy?} C -->|Yes| D[25 percent, then 50 percent] C -->|No| E[Abort, back to stable] D --> F[Manual approval] F --> G[100 percent] classDef step fill:#326CE5,color:#FFFFFF classDef good fill:#10B981,color:#FFFFFF classDef bad fill:#EF4444,color:#FFFFFF classDef gate fill:#8B5CF6,color:#FFFFFF class A,B,C step class D,G good class E bad class F gate

Exact percentages need a traffic router. Without Istio, NGINX Ingress, or a similar integration, Argo Rollouts approximates the weight by scaling replica counts. With 10 replicas, a 5 percent step rounds up to one pod, which is 10 percent. For precise low percentages use a router.

Database changes must work for both versions. Both versions talk to the same database during the rollout, so use expand and contract migrations: add new columns first, deploy, and remove old ones in a later release.

Feature flags are an alternative for logic risk. When the risk is in application behaviour rather than infrastructure, a flag service can expose a code path to a percentage of users with no traffic splitting, and rolling back means flipping the flag.

Tip

Scope analysis queries to the canary service only. A canary at 5 percent can be failing badly while the aggregate error rate, dominated by stable traffic, still looks fine.

Detailed Step-by-Step Practical Lab

This lab releases an order-gateway service in the mumbai-prod-cluster using Argo Rollouts and Istio, with a Prometheus error-rate gate.

Milestone 1 - Install Argo Rollouts and the kubectl plugin

Bash
export ARGO_ROLLOUTS_VERSION=v1.7.2
kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts \
-f https://github.com/argoproj/argo-rollouts/releases/download/${ARGO_ROLLOUTS_VERSION}/install.yaml
# Install the plugin
curl -LO https://github.com/argoproj/argo-rollouts/releases/download/${ARGO_ROLLOUTS_VERSION}/kubectl-argo-rollouts-linux-amd64
chmod +x kubectl-argo-rollouts-linux-amd64
sudo mv kubectl-argo-rollouts-linux-amd64 /usr/local/bin/kubectl-argo-rollouts
kubectl argo rollouts version

The controller is running, but no Rollout exists yet.

Milestone 2 - Create stable and canary Services and an Istio VirtualService

YAML
apiVersion: v1
kind: Service
metadata:
name: order-gateway-stable
namespace: orders
spec:
selector:
app: order-gateway
ports:
- port: 80
targetPort: 8080
YAML
apiVersion: v1
kind: Service
metadata:
name: order-gateway-canary
namespace: orders
spec:
selector:
app: order-gateway
ports:
- port: 80
targetPort: 8080
YAML
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: order-gateway-vs
namespace: orders
spec:
hosts:
- order-gateway.orders.svc.cluster.local
http:
- name: primary
route:
- destination:
host: order-gateway-stable
weight: 100
- destination:
host: order-gateway-canary
weight: 0

Argo Rollouts will edit the two weights for you and add the right pod-hash selectors to each Service.

Milestone 3 - Define the AnalysisTemplate

YAML
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: canary-error-rate
namespace: orders
spec:
args:
- name: canary-service
metrics:
- name: error-rate
interval: 1m
count: 5
failureLimit: 1
# fail closed: no data means we cannot judge, so it fails
successCondition: len(result) > 0 && result[0] < 0.01
provider:
prometheus:
address: http://prometheus.monitoring:9090
query: |
(
sum(rate(istio_requests_total{reporter="destination",destination_service_name="{{args.canary-service}}",response_code=~"5.."}[2m]))
or vector(0)
)
/
sum(rate(istio_requests_total{reporter="destination",destination_service_name="{{args.canary-service}}"}[2m]))

The or vector(0) matters. If the canary has no 5xx errors at all, the numerator has no series and the whole division returns nothing, which would fail a perfectly healthy canary. If there is no traffic at all, the denominator is empty, the result is empty, and the step correctly fails because the canary cannot be judged.

Milestone 4 - Create the canary Rollout

YAML
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: order-gateway
namespace: orders
spec:
replicas: 10
selector:
matchLabels:
app: order-gateway
template:
metadata:
labels:
app: order-gateway
spec:
containers:
- name: order-gateway
image: 418773912004.dkr.ecr.ap-south-1.amazonaws.com/order-gateway:v1.4.0
ports:
- containerPort: 8080
strategy:
canary:
stableService: order-gateway-stable
canaryService: order-gateway-canary
trafficRouting:
istio:
virtualService:
name: order-gateway-vs
routes:
- primary
steps:
- setWeight: 5
- pause: {duration: 2m}
- analysis:
templates:
- templateName: canary-error-rate
args:
- name: canary-service
value: order-gateway-canary
- setWeight: 25
- pause: {duration: 5m}
- analysis:
templates:
- templateName: canary-error-rate
args:
- name: canary-service
value: order-gateway-canary
- setWeight: 50
- pause: {} # wait here for a human to approve
- setWeight: 100
Bash
kubectl apply -f order-gateway-rollout.yaml
kubectl argo rollouts get rollout order-gateway -n orders --watch

A new image now starts a canary instead of a rolling update.

Milestone 5 - Trigger the rollout from CI without stored keys

In a GitOps setup, CI opens a pull request that bumps the image in the config repo and ArgoCD applies it. For a direct pipeline, authenticate with OIDC and set the image:

YAML
permissions:
id-token: write
contents: read
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::418773912004:role/github-orders-deploy
aws-region: ap-south-1
- run: aws eks update-kubeconfig --name mumbai-prod-cluster --region ap-south-1
- name: Start canary rollout
run: |
kubectl argo rollouts set image order-gateway \
order-gateway=418773912004.dkr.ecr.ap-south-1.amazonaws.com/order-gateway:${{ github.sha }} \
-n orders

The watch command should now show the weight moving to 5 percent and pausing.

Milestone 6 - Prove automatic rollback

Deploy a build that deliberately returns HTTP 500 on a small share of requests, then watch the rollout.

Bash
kubectl argo rollouts get rollout order-gateway -n orders
kubectl get analysisrun -n orders
kubectl describe analysisrun <name> -n orders

The status should become Degraded, the canary weight should return to 0, and the stable version should still serve all traffic. Do this in staging before you trust the gate in production.

Milestone 7 - Approve and promote a healthy canary

Bash
kubectl argo rollouts promote order-gateway -n orders
kubectl argo rollouts get rollout order-gateway -n orders --watch

Promote resumes the indefinite pause at 50 percent and the rollout completes at 100 percent.

Milestone 8 - Run the same service as blue-green

YAML
strategy:
blueGreen:
activeService: order-gateway-active
previewService: order-gateway-preview
autoPromotionEnabled: false
scaleDownDelaySeconds: 600 # keep the old version warm for rollback
prePromotionAnalysis:
templates:
- templateName: preview-smoke-check

The new version is reachable at the preview Service while the active Service still serves users. After checks pass, kubectl argo rollouts promote order-gateway switches the active Service, and the old ReplicaSet stays up for ten minutes in case you need to go back.

Remember

pause: {} with no duration waits forever for a human. Decide deliberately which steps are automated and which are manual approvals.

Security

Blue-green keeps the old version running during cutover. Apply the same network policies and secret access to both versions, not just whichever one the live Service points at.

Production Best Practices & Common Pitfalls

  • Start the first canary step at 5 percent or lower so any damage is small.
  • Scope every analysis query to the canary service or pods, not the whole service.
  • Make analysis fail closed, and test it against both a healthy and a broken build.
  • Use expand and contract database migrations so both versions work against the same schema.
  • In blue-green, keep the old version warm for a defined rollback window before scaling it down.
  • Alert on rollouts stuck in Paused longer than expected, which usually means a forgotten approval.
  • Pin the Argo Rollouts version and upgrade it deliberately, like any other cluster controller.

Quick Reference & Troubleshooting Commands

Symptom Command What to look for
Rollout stuck at a step kubectl argo rollouts get rollout order-gateway -n orders A manual pause waiting for promote
Analysis always fails kubectl describe analysisrun <name> -n orders Query returns no data or wrong labels
Traffic not split as expected kubectl get virtualservice order-gateway-vs -n orders -o yaml Weights not matching the current step
Blue-green did not switch kubectl get svc order-gateway-active -n orders -o yaml Selector still on the old ReplicaSet
Need to stop a bad release kubectl argo rollouts abort order-gateway -n orders Weight returns to 0, status Degraded

Resources

Explore More in Deployment Strategies and GitOps

All 6 Topics

Frequently Asked Questions

Is Implementing Blue-Green and Canary Deployments 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 Blue-Green and Canary Deployments topic cover?

Implement blue-green and canary deployments in CI/CD with Argo Rollouts, Prometheus analysis gates, and automatic rollback on failure.

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