使用 Harness 部署
企业 CI/CD 平台,提供流水线编排、特性开关和云成本管理。
CI/CD高级
为什么
Harness 在一个平台统一 CI、CD、特性开关和成本管理,支持 GitOps。DORA 2024 DevOps 状态报告显示精英团队部署频率比低绩效团队高 973 倍。
带自动化测试的 CI/CD 管道将变更失败率降至 5-15%,而手动部署为 40-60%。
何时使用
需要端到端交付、治理和成本可见性的企业团队。贡献者少于 5 人的仓库避免复杂管道编排 — pre-commit 钩子 + GitHub Actions 足够。
除非需要 GPU 或 VPN 访问,否则跳过自托管 runner。
如何做
# Harness 管道 YAML (excerpt)
pipeline:
name: deploy-prod
stages:
- stage:
name: Build
steps:
- step:
type: BuildAndPushDockerRegistry
spec:
connectorRef: dockerhub
repo: myorg/app
tags: ["<+pipeline.executionId>"]
- stage:
name: Deploy
strategy:
canary:
percentages: [25, 50, 100]
steps:
- step:
type: KubernetesRollingDeployment
spec:
cluster: prod-cluster
4. 验证部署 — curl -I https://your-app.example.com
5. 监控日志 — 前 5 分钟检查错误
6. 需要时回滚 — 回退到上一版本
示例
# Harness CLI
harness deploy --account=$ACCOUNT \
--org=$ORG --project=$PROJECT \
--pipeline=deploy-prod \
--env=production
常见问题
- ⚠Connector 认证失败 — 验证 delegate 能访问服务
- ⚠Canary 卡住 — 检查验证提供方(AppDynamics/Prometheus)
- ⚠环境间配置漂移 — 使用基础设施即代码(Terraform/Pulumi)保持 dev/staging/prod 一致
最佳实践
- ✓每个 VPC 部署 delegate — 避免网络出口费用
- ✓用部署验证 — 异常时自动回滚
- ✓设置健康检查和优雅关闭 — 处理 SIGTERM 以在退出前排空进行中的请求