Files
nexus/wiki/concepts/Canary-Deployment.md

57 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Canary Deployment"
type: concept
tags: [DevOps, Deployment, Kubernetes, ECS, AWS]
sources: [learning-sessions-ecs-deployment-using-iac-20230808-183322-meeting-recording]
last_updated: 2026-05-05
---
# Canary Deployment
## Definition
金丝雀部署Canary Deployment是一种软件发布策略通过将新版本逐步推向一小部分用户来降低风险——在新版本全面推广前先将少量流量导向新版本观察其行为和性能验证无误后再逐步扩大比例。
## Core Mechanism
1. **流量分割**:将用户流量按比例分割(如 5%/10%/50%/100%
2. **逐步提升**:从低比例开始,逐步增加新版本流量
3. **快速回滚**:发现问题时,立即将流量切回旧版本
## Implementation in AWS
### ECS (Elastic Container Service)
ECS 模块支持金丝雀部署,通过 Target Group 权重调整实现流量控制:
- 创建新旧两个 Task Definition
- 通过 ALB/NLB 的 Target Group 逐步调整权重
- 结合 CloudWatch 监控自动决策扩缩比例
### EKS (Elastic Kubernetes Service)
Kubernetes 原生支持金丝雀部署,通过以下机制:
- `ReplicaSet` 控制新旧版本副本数
- `Service` 选择器配合金丝雀标签
- Argo Rollouts 等高级工具提供声明式金丝雀策略
### AWS Tools
- **AWS CodeDeploy**:原生支持 ECS 和 Lambda 的金丝雀部署策略
- **ALB Target Groups**:权重路由实现流量分割
- **CloudWatch**:金丝雀指标监控
## Comparison with Other Deployment Strategies
| 策略 | 风险 | 成本 | 适用场景 |
|------|------|------|----------|
| **Blue-Green** | 中 | 高(双倍资源) | 快速回滚需求 |
| **Canary** | 低 | 中 | 生产验证 |
| **Rolling** | 中 | 低 | 资源受限环境 |
| **A/B Testing** | 低 | 中 | 功能验证 |
## Key Metrics to Monitor
- 错误率5xx
- 延迟P50/P95/P99
- 业务指标(转化率/点击率)
- 资源利用率
## Related Concepts
- [[Blue-Green-Deployment]]:双环境切换策略
- [[ECS-Module-Deployment]]ECS 场景的模块化部署
- [[Infrastructure-as-Code]]:部署自动化基础