← Back to blog
·2 min read·CI/CD

Blue-Green Deployments on Kubernetes

Implement zero-downtime blue-green releases with Kubernetes Services, Ingress, and CI/CD automation.

Blue-green deployment keeps two identical environments and switches traffic atomically. On Kubernetes, you achieve this with two Deployments and a Service selector flip.

Architecture

Deployment Steps

Database migrations

Blue-green with schema changes requires backward-compatible migrations or expand-contract patterns. Both versions may run simultaneously during the switch.

Kubernetes Manifest Pattern

# green deployment (currently active) apiVersion: apps/v1 kind: Deployment metadata: name: api-green spec: replicas: 3 selector: matchLabels: app: api version: green template: metadata: labels: app: api version: green --- apiVersion: v1 kind: Service metadata: name: api spec: selector: app: api version: green # flip to blue after validation ports: - port: 80

CI/CD Integration

deploy:blue: stage: deploy script: - kubectl apply -f k8s/blue/ - ./scripts/smoke-test.sh https://blue.internal.example.com environment: name: blue switch:production: stage: deploy when: manual script: - kubectl patch service api -p '{"spec":{"selector":{"version":"blue"}}}'

When to Use Blue-Green

ScenarioFit
Stateless APIsExcellent
Instant rollback neededExcellent
Stateful apps with sticky sessionsRequires care
Cost-sensitiveHigher (2x resources during switch)

Conclusion

Blue-green trades resource cost for simplicity and instant rollback. Pair it with automated smoke tests in CI before flipping the Service selector.

Related Articles