Kubernetes Deployment Strategies: Blue-Green and Canary Deployments Explained

•8 min read•Subid Das
kubernetesdevopsdeploymentinfrastructure
Kubernetes Deployment Strategies: Blue-Green and Canary Deployments Explained

Deploying applications in production environments is one of the most critical and stressful tasks in DevOps. A single mistake can result in service outages, data loss, or degraded user experience. That's why understanding deployment strategies is essential for any infrastructure engineer.

In this article, I'll dive deep into three powerful Kubernetes deployment strategies that help teams deploy with confidence.

The Problem with Simple Deployments#

When you simply push a new version of your application, what happens to users currently using the old version? With naive deployments:

  • Users experience service interruptions
  • There's no easy way to rollback if something breaks
  • Bugs in new versions affect all users immediately
  • Zero-downtime deployments become nearly impossible

Kubernetes deployment strategies solve these problems by controlling how traffic transitions from old to new versions.

1. Blue-Green Deployment#

Blue-green deployment maintains two identical production environments: one active (blue) and one idle (green).

How It Works#

apiVersion: v1
kind: Service
metadata:
  name: my-app
spec:
  selector:
    version: blue  # Points to blue deployment
  ports:
    - port: 80
      targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-blue
spec:
  replicas: 3
  selector:
    matchLabels:
      version: blue
  template:
    metadata:
      labels:
        version: blue
    spec:
      containers:
        - name: app
          image: my-app:v1.0

The Deployment Process#

  1. Deploy to Green: Deploy your new application version to the green environment
  2. Test: Run smoke tests, health checks, and integration tests
  3. Switch Traffic: Update the service selector to point to green
  4. Keep Blue: Keep the old blue environment running for instant rollback

Advantages#

  • Instant Rollback: If something breaks, switch back to blue immediately
  • Zero Downtime: Users never experience service interruption
  • Easy Testing: Test the entire application in production-like conditions before switching

Disadvantages#

  • Resource Intensive: Requires running two complete environments
  • Database Migrations: Challenging when schema changes are involved
  • Network Latency: Switching traffic might cause brief connection losses

2. Canary Deployment#

Canary deployments gradually shift traffic from old to new versions, exposing new features to a small percentage of users first.

Implementation with Kubernetes#

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: my-app
spec:
  hosts:
    - my-app
  http:
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: my-app-stable
            port:
              number: 80
          weight: 95  # 95% traffic to stable version
        - destination:
            host: my-app-canary
            port:
              number: 80
          weight: 5   # 5% traffic to new version
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-canary
spec:
  replicas: 1
  selector:
    matchLabels:
      version: canary
  template:
    metadata:
      labels:
        version: canary
    spec:
      containers:
        - name: app
          image: my-app:v2.0

Traffic Progression#

Time  | Old Version | New Version
------|-------------|------------
T=0   |    100%     |     0%
T=30m |     95%     |     5%
T=1h  |     80%     |     20%
T=2h  |     50%     |     50%
T=3h  |      0%     |    100%

Real-World Example: Detecting Canary Issues#

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: canary-alerts
spec:
  groups:
    - name: canary
      rules:
        - alert: CanaryErrorRateHigh
          expr: |
            rate(http_requests_total{version="canary",status=~"5.."}[5m]) 
            > 0.05
          annotations:
            summary: "Canary error rate exceeds 5%"
            action: "Trigger automatic rollback"

Advantages#

  • Low Risk: Limited user impact from bugs
  • Real Monitoring: Detect issues with real traffic patterns
  • Gradual Rollout: Perfect for testing new features with power users
  • Better Resource Utilization: Fewer resources needed than blue-green

Disadvantages#

  • Complex Monitoring: Need sophisticated observability
  • Longer Rollout: Takes time to fully deploy
  • Data Consistency: Tricky when database schemas differ

3. Rolling Deployment (Kubernetes Default)#

Rolling deployments gradually replace old pods with new ones.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 2        # Allow 2 extra pods during update
      maxUnavailable: 1  # Keep at least 9 pods available
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: app
          image: my-app:v2.0
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5

Pod Replacement Timeline#

Initial:  [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v1]
Step 1:   [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v2] [v2]
Step 2:   [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v1] [v2] [v2] [v2]
...
Final:    [v2] [v2] [v2] [v2] [v2] [v2] [v2] [v2] [v2] [v2]

Choosing the Right Strategy#

StrategyBest ForRiskSpeed
Blue-GreenLarge changes, schema migrationsLowFast
CanaryRegular releases, feature flagsVery LowSlow
RollingStandard updates, high availabilityMediumMedium

Decision Tree#

Are you making a risky change?
├─ YES → Use Blue-Green (instant rollback)
└─ NO → Are you changing the database schema?
    ├─ YES → Use Blue-Green
    └─ NO → Do you want to minimize risk?
        ├─ YES → Use Canary
        └─ NO → Use Rolling (default)

Practical Tips#

  1. Always have readiness probes: Kubernetes won't send traffic to unhealthy pods
  2. Test in staging: Replicate your production deployment strategy in staging
  3. Monitor actively: Have alerts for error rates, latency, and resource usage
  4. Plan rollbacks: Document your rollback procedure before deploying
  5. Use feature flags: Decouple deployment from feature releases

Conclusion#

Choosing the right deployment strategy depends on your risk tolerance, application architecture, and team capabilities. Most teams benefit from starting with rolling deployments for standard updates and adopting canary deployments for high-risk releases.

The key is to minimize blast radius, maintain observability, and have a clear rollback plan. Kubernetes gives you the tools—mastering these strategies ensures you use them effectively.

What's your team's deployment strategy? Share your experiences in the comments below.


Rolling out changes to production Kubernetes with more risk than you're comfortable with? Book a 15-minute call.

FAQ

Which deployment strategy should most teams start with?

Rolling deployment (Kubernetes' default) for routine updates — it's built-in, requires no extra infrastructure, and covers most releases. Reach for canary only when a release carries real risk.

When is blue-green worth the extra infrastructure cost?

When you need instant rollback with zero request-level risk — running two full environments and switching traffic atomically costs double the resources during the switch, which only pays off for high-stakes releases.

What's the biggest risk with canary deployments?

Not watching the right metrics. A canary only protects you if error rates, latency, and business metrics are monitored on the canary subset in real time — without that, it's just a slower rolling deploy.

About the author

Subid Dasis a Forward Deployed Engineer & Systems Architect building high-reliability cloud platforms, AI automations, and custom business software. Explore more technical articles on the blog, or get in touch if you're working on something similar.

Recommended Reading

Continue exploring production engineering guides, systems architecture, and cloud patterns.

Let's
build.

Tell me what’s slowing your business down. We’ll work out what to build next.

Tell me about your project

A few sentences are enough to start. No technical brief needed.

Service, budget & timeline (optional) +
I need help with
Budget (optional)
Timeline (optional)
LET'S CONNECT