Blue-Green 部署
一句话解释
Blue-green 部署 maintains two identical 环境 (blue and green) and 切换 traffic 从旧 到新 in one 步骤.
用大白话说
Blue-green deployment is a release strategy that reduces downtime and risk. You maintain two identical production environments: blue (the current version) and green (the new version).
- Deploy the new version to the green environment (while blue is still serving traffic).
- Test the green environment to make sure it works.
- Switch the router/load balancer to send all traffic to green instead of blue.
- If something goes wrong, switch back to blue instantly (rollback).
- Once green is confirmed stable, blue becomes the old version for the next release.
The advantage is instant rollback — you just switch the router back. The disadvantage is that you need double capacity (two full environments running). A related strategy is canary deployment, where you route a small percentage of traffic to the new version first to test it.
示例
# 1. Deploy new version as 'green'
kubectl apply -f deployment-green.yaml
# 2. Test green environment
curl http://green-service/health
# 3. Switch traffic from blue to green
kubectl patch service my-app -p '{"spec":{"selector":{"version":"green"}}}'
# 4. If issues, switch back to blue instantly
kubectl patch service my-app -p '{"spec":{"selector":{"version":"blue"}}}'部署 green, 测试它, 切换 Service selector 到 route traffic 到 green, and 切换后面到 blue 如果需要.
工作原理
- The current version runs in the blue environment.
- You deploy the new version to the green environment (no traffic yet).
- You test green to verify it works correctly.
- You switch the load balancer/router to send all traffic to green.
- If problems occur, switch back to blue instantly. Blue and green swap roles for the next release.
常见混淆
容易混淆的对象: Canary 部署
关键区别: Blue-green 切换所有 traffic at 一次 (100% 到新); canary gradually increases traffic 到新 version (e.g., 5% → 25% → 100%), 允许 earlier detection 的 issues.
相关术语
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。