CD & Deployment Strategies
Overview
Continuous Delivery (CD) automates the deployment of applications to production. This tutorial covers the major deployment strategies: blue‑green, canary, rolling updates, and rollback strategies. You'll learn to choose the right strategy for your application based on risk tolerance and operational requirements.
1. Deployment Strategies Overview
Key considerations
- Downtime tolerance: Can your application afford downtime?
- Risk tolerance: How much risk are you willing to accept?
- Rollback speed: How quickly can you revert if something goes wrong?
- Infrastructure cost: Extra resources needed for the deployment.
2. Blue-Green Deployment
Blue‑green deployment maintains two identical environments: blue (current) and green (new). Traffic is switched from blue to green once the new version is verified.
3. Canary Deployments
Canary deployments gradually roll out the new version to a small subset of users before a full rollout.
4. Rolling Updates
Rolling updates gradually replace old instances with new ones, maintaining availability during the deployment.
5. Rollback Strategies
- Immediate rollback: Switch back to the previous version instantly (blue‑green).
- Gradual rollback: Roll back one instance at a time (rolling update).
- Automated rollback: Triggered by monitoring alerts (canary).
- Manual rollback: Human intervention required.
- Always have a rollback plan.
- Automate rollback detection when possible.
- Test rollback procedures regularly.
- Keep previous versions available for quick rollback.
Quiz
Question 1
Which deployment strategy uses two identical environments and switches traffic between them?
- Canary
- Blue-Green
- Rolling Update
- Recreate
Show answer
Question 2
What is the primary advantage of a canary deployment?
- Zero infrastructure cost
- Gradual rollout with monitoring, reducing risk
- Instant rollback
- Simple implementation
Show answer
Question 3
Which Kubernetes strategy controls the number of extra pods during a rolling update?
- maxUnavailable
- maxSurge
- replicas
- strategy
Show answer
Exercises
Exercise 1
Design a blue‑green deployment strategy for a web application. Describe the infrastructure, the switching mechanism, and the rollback plan.
Sample answer
- Infrastructure: Two environments (blue/green) behind a load balancer.
- Switching: Update load balancer target group or DNS record.
- Rollback: Switch load balancer back to blue.
- Testing: Verify green environment before switching.
Exercise 2
Explain how you would implement a canary deployment with a 10% initial rollout and automated rollback if the error rate exceeds 1%.
Sample answer
- Deploy: Deploy new version with 10% traffic weight.
- Monitor: Track error rate, latency, and success rate.
- Automation: If error_rate > 0.01, trigger rollback.
- Tool: Use Argo Rollouts with analysis template.
Homework
Homework 1
Choose a deployment strategy for your capstone project. Write a 300‑word justification, considering risk tolerance, downtime requirements, and infrastructure constraints.
Sample outline
- Strategy: Rolling update (or canary).
- Justification: Low cost, zero downtime, simple to implement.
- Infrastructure: Kubernetes with rolling update configuration.
- Rollback: `kubectl rollout undo`.
Mini‑Project
Deployment Strategy Implementation
Implement a deployment strategy for a microservice application:
- Choose a strategy (blue‑green, canary, or rolling)
- Write Kubernetes manifests or Terraform configuration
- Implement a CI/CD pipeline that uses the strategy
- Include a rollback mechanism
- Document the complete setup
Sample outline
- Strategy: Blue‑green with nginx ingress controller.
- Kubernetes: Blue deployment, Green deployment, Service pointing to active.
- Pipeline: GitHub Actions that deploys to green, tests, and switches traffic.
- Rollback: Manual switch via `kubectl patch service`.
Tutorial Summary
You learned the major deployment strategies: blue‑green, canary, rolling updates, and rollback strategies. Each has different trade‑offs in terms of risk, cost, and complexity. Choosing the right strategy is essential for safe, reliable software delivery.
Key takeaway: Deployment strategy is a business decision as much as a technical one. Balance risk, cost, and speed based on your application's requirements.