npx skills add https://github.com/claude-dev-suite/claude-dev-suite --skill deployment-strategies| 策略 | 停机时间 | 风险 | 回滚速度 | 资源成本 |
|---|---|---|---|---|
| Recreate | 有 | 高 | 慢(重新部署) | 低 |
| Rolling Update | 无 | 中 | 中 | 低 |
| Blue-Green | 无 | 低 | 即时(切换) | 2倍资源 |
| Canary | 无 | 极低 | 快(流量转移) | +10-20% |
┌─── Blue (v1) ← 当前流量
Load Balancer ──────┤
└─── Green (v2) ← 在此部署、测试,然后切换
| Strategy | Downtime | Risk | Rollback Speed | Resource Cost |
|---|---|---|---|---|
| Recreate | Yes | High | Slow (redeploy) | Low |
| Rolling Update | No | Medium | Medium | Low |
| Blue-Green | No | Low | Instant (switch) | 2x resources |
| Canary | No | Very Low | Fast (route shift) | +10-20% |
┌─── Blue (v1) ← current traffic
Load Balancer ──────┤
└─── Green (v2) ← deploy here, test, then switch
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// 将流量从蓝组切换到绿组
await elbv2.modifyListener({
ListenerArn: listenerArn,
DefaultActions: [{
Type: 'forward',
TargetGroupArn: greenTargetGroupArn, // 指向绿组
}],
});
// 回滚:重新指向蓝组
await elbv2.modifyListener({
ListenerArn: listenerArn,
DefaultActions: [{
Type: 'forward',
TargetGroupArn: blueTargetGroupArn,
}],
});
# Kubernetes: Argo Rollouts
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
strategy:
canary:
steps:
- setWeight: 5 # 5% 流量到金丝雀版本
- pause: { duration: 5m }
- setWeight: 20
- pause: { duration: 10m }
- setWeight: 50
- pause: { duration: 10m }
- setWeight: 100 # 完全部署
analysis:
templates:
- templateName: error-rate
startingStep: 1 # 从步骤 1 开始检查
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1 # 最多 1 个 Pod 不可用
maxSurge: 1 # 最多 1 个额外 Pod
1. 部署 v2 代码(向后兼容 v1 模式)
2. 运行前向迁移(仅限添加:新列、新表)
3. 验证 v2 正常工作
4. 在下一个版本中运行清理迁移(删除旧列)
-- 版本 1: 扩展(添加新列)
ALTER TABLE users ADD COLUMN full_name TEXT;
UPDATE users SET full_name = first_name || ' ' || last_name;
-- 版本 2: 代码使用 full_name,停止写入 first_name/last_name
-- 版本 3: 收缩(删除旧列)
ALTER TABLE users DROP COLUMN first_name, DROP COLUMN last_name;
# 1. 检测问题(自动或手动)
# 2. 将流量路由回先前版本
kubectl rollout undo deployment/my-app
# 3. 验证回滚成功
kubectl rollout status deployment/my-app
# 4. 如果运行了数据库迁移,执行向后迁移
# (仅在迁移向后兼容时执行)
| 反模式 | 修复方案 |
|---|---|
| 一步完成部署+迁移 | 将部署与迁移分离 |
| 破坏性数据库迁移 | 使用扩展-收缩模式 |
| 无就绪状态健康检查 | 配置就绪探针 |
| 无自动回滚触发器 | 设置错误率阈值 |
| 手动部署 | 通过 CI/CD 流水线自动化 |
每周安装数
1
仓库
首次出现
3 天前
安全审计
安装于
amp1
cline1
openclaw1
opencode1
cursor1
kimi-cli1
// Switch traffic from blue to green
await elbv2.modifyListener({
ListenerArn: listenerArn,
DefaultActions: [{
Type: 'forward',
TargetGroupArn: greenTargetGroupArn, // Point to green
}],
});
// Rollback: point back to blue
await elbv2.modifyListener({
ListenerArn: listenerArn,
DefaultActions: [{
Type: 'forward',
TargetGroupArn: blueTargetGroupArn,
}],
});
# Kubernetes: Argo Rollouts
apiVersion: argoproj.io/v1alpha1
kind: Rollout
spec:
strategy:
canary:
steps:
- setWeight: 5 # 5% traffic to canary
- pause: { duration: 5m }
- setWeight: 20
- pause: { duration: 10m }
- setWeight: 50
- pause: { duration: 10m }
- setWeight: 100 # Full rollout
analysis:
templates:
- templateName: error-rate
startingStep: 1 # Start checking from step 1
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1 # At most 1 pod down
maxSurge: 1 # At most 1 extra pod
1. Deploy v2 code (backward-compatible with v1 schema)
2. Run forward migration (additive only: new columns, tables)
3. Verify v2 works correctly
4. Run cleanup migration (remove old columns) in next release
-- Release 1: EXPAND (add new column)
ALTER TABLE users ADD COLUMN full_name TEXT;
UPDATE users SET full_name = first_name || ' ' || last_name;
-- Release 2: code uses full_name, stops writing first_name/last_name
-- Release 3: CONTRACT (remove old columns)
ALTER TABLE users DROP COLUMN first_name, DROP COLUMN last_name;
# 1. Detect issue (automated or manual)
# 2. Route traffic back to previous version
kubectl rollout undo deployment/my-app
# 3. Verify rollback successful
kubectl rollout status deployment/my-app
# 4. If DB migration was run, execute backward migration
# (only if migration was backward-compatible)
| Anti-Pattern | Fix |
|---|---|
| Deploy + migrate in one step | Separate deployment from migration |
| Destructive DB migrations | Use expand-contract pattern |
| No health checks for readiness | Configure readiness probes |
| No automated rollback trigger | Set error rate thresholds |
| Manual deployments | Automate via CI/CD pipeline |
Weekly Installs
1
Repository
First Seen
3 days ago
Security Audits
Installed on
amp1
cline1
openclaw1
opencode1
cursor1
kimi-cli1
Azure Data Explorer (Kusto) 查询技能:KQL数据分析、日志遥测与时间序列处理
114,200 周安装