Blue-Green Deployments on Cloud Foundry (利用CloudFoundry实现蓝绿发布)


原文地址:Blue-Green Deployments on Cloud Foundry

We’ll begin with a basic Spring application named ms-spr-demo. This app takes users to a simple web page announcing the ubiquitous “Hello World!” message. We’ll utilize the cf command-line interface to push the application:

这里先向CF PUSH一个很简单的打印“Hello World”的应用:

The end result of this cf push event is that an application is now serving requests at The following graphic shows the state of our system, with the CF Router sending traffic to our application:

这个应用的实例将被映射到 这个域名上,如下所示:


Next, we make a slight change to our application. Rather that saying “Hello World!” we decide to make it say “Goodbye World!” We build a new war file for the application. Rather than letting cf prompt us this time, we’ll make use of the manifest.yml file that we saved from our previous push. However, we’ll rename the application and provide a new route. Take a look:

接下来,我们对应用源码做了修改,使之打印“Goodbye World”,然后使用第一次部署时生成的manifest.yml来进行PUSH,不过,这一次我们将源码部署成一个新应用并映射了新域名:

As you can see, we’re calling our new application version ms-spr-demo-green and we’re mapping it to the URL Let’s push the application:


We now have two instances of the application running, each of them using distinct routes:



Now it’s time for the magic to happen. We’ll map our original URL route ( to our “green” instance. This is accomplished very simply by using cf:


The CF router immediately begins to load balance requests between each instance of the application, as shown here:



Now our router will send requests to to both instances of the application, while only services the “green” instance. Once we determine that all is well, it’s time to stop routing requests to the “blue” instance. This is just as simple using cf:


Our “blue” instance is now no longer receiving any web traffic:


We can now decomission our “blue” instance, or we can leave it around for a period of time in case we decide we need to roll back our changes. The important thing is that our customers suffered absolutely no downtime!

这样, ms-spr-demo-green.cfapps.io都将流量导向了绿色应用,我们可以删除旧的蓝色应用或者保留一段时间以防意外情况。最后,我们可以把ms-spr-demo-green.cfapps.io这个测试域名也删除。


附录 Martin Fowler大神提出的蓝绿发布:

One particular practice associated with Continuous Delivery is Blue-Green Deployments. Martin Fowler describes these very well at the link provided, but I’ll summarize briefly here:

  • Cut-over to a new software version is tricky, and must be quick in order to minimize downtime events.
  • Blue-green deployments ensure the parallel existence of two, identical (as possible) production environments.
  • At any given point, only one (e.g. blue) services production traffic.
  • New deploys are made to the other (e.g. green) environment. Final smoke testing is performed here.
  • When green is determined ready, we begin routing traffic to it.
  • We then stop routing traffic to blue.


Leave a Reply

Your email address will not be published. Required fields are marked *