蓝绿部署
并行运行与蓝环境一致的绿环境,验证后切换流量,实现不停机发布。
结构与工作原理
按步骤查看箭头所示的流程。
先准备两个环境,再切换流量。数据库变更的兼容性需要单独评估。
预期收益
可快速回滚路由、按环境进行比较,并避免切换后混跑不同版本。
权衡
需要承担重复基础设施成本,状态同步和身份管理也更复杂。
删除式迁移等不可逆变更会破坏蓝绿回滚保障,不宜采用或应谨慎处理。
运维与应用指南
综合说明,与有原文摘录支持的条目分开。实际应用前请先验证。
何时使用
适用于要求不停机发布和快速回滚的 Web 或 API 服务、定期 Kubernetes 集群升级和云迁移切换。
应用场景
一家韩国电商企业面向数百万用户每月两次部署订单 API,要求不停机、5 分钟内回滚,并保证支付数据一致。蓝环境继续承载现有流量;绿环境部署新版并通过冒烟测试、性能和 SLO 验证后,切换路由。切换后观察指标,出现异常立即切回蓝环境。
部署原则
- 蓝绿环境采用相同的应用、配置和依赖
- 在负载均衡器、API 网关或服务网格等路由层切换流量
- 使用新旧版本均可读写且前后向兼容的数据库模式
- 明确会话、缓存和外部集成是按环境隔离还是共享,并确定状态同步方式
- 按需用 IaC 创建和清理绿环境,以控制配置漂移和成本。
本地部署
保留源环境一段时间,为回滚留出路径。提前验证负载均衡器或 DNS 切换以及数据迁移的兼容性,并通过运维流程管理两个环境的配置漂移和资源成本。
云环境
用托管负载均衡、DNS 和自动扩缩容,以代码预配蓝绿环境。在 CI/CD 中自动运行验证关卡和流量切换,并在切换后监控成本、SLO 和回滚情况。
Kubernetes
在不同命名空间或集群部署相同工作负载,通过 Service、Ingress 或服务网格切换流量。检查就绪状态、冒烟测试、HPA 和 PDB 后再切换,观察期结束后清理旧环境。
故障应对
常见故障包括路由配置错误、模式不兼容、新版性能或错误问题,以及数据同步不一致。发现后立即将路由切回以前的环境,重新验证其健康状况和数据完整性,再分析原因并按需恢复或重新部署。
14 个维度的证据
反映调研时的证据收录情况,请另行判断来源是否准确、是否仍然有效。
定义与概览有证据
并行运行与蓝环境一致的绿环境,验证后切换流量,实现不停机发布。
runs two identical production environments simultaneously to achieve zero-downtime deployments and enable fast rollbacks解决的问题有证据
缩短部署停机时间,降低失败后恢复耗时的风险,并支持快速回滚。
to achieve zero-downtime deployments and enable fast rollbacks.关键组件与资源有证据
两个相同的生产环境,以及在两者之间路由和切换流量的机制。
Blue/green environments also have a mechanism to route traffic between them.数据与资产放置原则有证据
考虑数据库等有状态资产在两个环境中的兼容性,使共享数据库或模式同时兼容新旧版本。
configure a single database for backward and forward compatibility.代表性使用场景有证据
在空闲环境部署并验证新版,再切换流量,实现不停机发布。
The current release is always deployed to the idle environment and traffic is switched to it after deployment completes, with no downtime.应用场景示例有证据
从源环境或本地环境迁移到新的 AKS 集群时,如出现问题可快速回滚到源环境。
I need rapid traffic rollback to the source if anything goes wrong after cutover.不适用情形与注意事项有证据
删除式迁移等不可逆变更会破坏蓝绿回滚保障,不宜采用或应谨慎处理。
Irreversible changes break the rollback promise outright.本地部署:开发、发布与运维有证据
将本地或源集群、虚拟机切换至新环境时,保留源环境以便回滚。
migrating workloads from a source cluster, VM estate, or on-premises environment into a new AKS cluster云环境:开发、发布与运维有证据
在托管 Kubernetes 或云环境中验证新版,再通过修改路由切换用户流量。
Once the new version is validated, a routing change switches user traffic to it.Kubernetes:开发、发布与运维有证据
升级 EKS 等 Kubernetes 集群时,新建第二个集群,部署并验证应用后再切换。
we do a blue-green deployment, where we create a second cluster with the latest version of Amazon EKS and Istio.故障应对有证据
回滚或撤销后,重新验证旧环境的健康状况及数据完整性。
Re-validate old environment health and data integrity.优势有证据
可快速回滚路由、按环境进行比较,并避免切换后混跑不同版本。
fast routing rollback; - clean environment-level comparison; - no mixed application versions after cutover不足与权衡有证据
需要承担重复基础设施成本,状态同步和身份管理也更复杂。
near-double serving infrastructure during overlap; - state synchronization and identity complexity代表性技术与工具有证据
Amazon EKS、Istio 等集群和服务网格技术。
we create a second cluster with the latest version of Amazon EKS and Istio.更多参考资料 (23)
- Untitled result ↗
- Selecting a deployment strategy - Engineering Guidance and Standards - Home Office ↗
- What Is Blue-Green Deployment? | IBM ↗
- Blue-green deployment of AKS clusters - Azure Architecture Center | Microsoft Learn ↗
- Using blue-green deployment to reduce downtime | Cloud Foundry Docs ↗
- Blue-green deployments: Zero-downtime deployments for software and database updates ↗
- Blue-Green Deployment in Azure Container Apps | Microsoft Learn ↗
- Deploy blue/green infrastructure for zero-downtime | Well-Architected Framework | HashiCorp Developer ↗
- Kubernetes cluster upgrade: the blue-green deployment strategy | Containers ↗
- Blue/Green Kubernetes upgrades for Amazon EKS Anywhere using Flux | Containers ↗
- Azure Kubernetes Service (AKS) production upgrade strategies - Azure Kubernetes Service | Microsoft Learn ↗
- Zero-Downtime Migration to Azure Kubernetes Service (AKS) - Azure Kubernetes Service | Microsoft Learn ↗
- Reference Architecture: GKE Enterprise hybrid environment - part 2 - Dec '24 - Google Docs ↗
- Deploy an app on Kubernetes ↗
- aws-samples/sample-eks-bg-upgrades ↗
- Recommendations for designing a deployment failure mitigation strategy - Power Platform | Microsoft Learn ↗
- OPS06-BP03 Employ safe deployment strategies ↗
- What Is Blue-Green Deployment? The Complete Guide ↗
- Progressive Delivery and Deployment Strategies | System Design Patterns ↗
- Blue-Green Deployment Strategy: Safe Releases, Fast Rollback, and Hidden Tradeoffs ↗
- Blue-Green Deployments: A Definition and Introductory Guide ↗
- Implement zero-downtime deployments with blue/green, canary, and rolling strategies | Well-Architected Framework | HashiCorp Developer ↗
- Architecture strategies for safe deployment practices - Microsoft Azure Well-Architected Framework | Microsoft Learn ↗