In the previous blog post we showed you how to setup a High Available Docker Container Application platform using CoreOS and Consul. In this short blog post, we will show you how easy it is to perform a rolling upgrade of a deployed application.

(Updated - june 2nd 2015 - removed consul-http-loadbalancer-lb from the Vagrant architecture)

Architecture

In this blog post we will use the same but for the deployment we used Vagrant instead of Amazon AWS which is a little bit snappier to use  :-).architecture, which does not include a Load Balancer.

 In order to get your own container platform as a service running on vagrant, clone the repository and start your cluster.


git clone https://github.com/mvanholsteijn/coreos-container-platform-as-a-service.git
cd coreos-container-platform-as-a-service/vagrant
vagrant up
...
vagrant up
Bringing machine 'core-01' up with 'virtualbox' provider...
Bringing machine 'core-02' up with 'virtualbox' provider...
Bringing machine 'core-03' up with 'virtualbox' provider...
...

Checkout the cluster

After the cluster has started, you can use the following command to checkout whether your cluster is fully operational. You should see 4 units running on each machine.

for node in 1 2 3 ; do
  vagrant ssh -c "systemctl | grep consul" core-0$node
done
...
consul-http-router.service loaded active running consul-http-router
consul-server-announcer.service loaded active running Consul Server Announcer
consul-server-registrator.service loaded active running Registrator
consul-server.service loaded active running Consul Server Agent

 

Deploying the application

Once the cluster is running, you can deploy or paas-monitor application. This happens in two stages. First you submit the template.

fleetctl submit paas-monitor\@.service

Then, you load and start the new instances.

fleetctl load paas-monitor\@{1..6}.service
fleetctl start paas-monitor\@{1..6}.service
fleetctl list-units | grep paas-monitor

You can now see the paas-monitor in operation on your machine by opening http://paas-monitor.127.0.0.1.xip.io:8080 and clicking on start.  You should see something like shown in the table below. Leave this running while we are going to update the application!

host release message # of calls avg response time last response time
47ea72be3817:1337 v1 Hello World from v1 53 8 11
cc4227a493d7:1337 v1 Hello World from v1 59 11 8
04a58012910c:1337 v1 Hello World from v1 54 7 6
090caf269f6a:1337 v1 Hello World from v1 58 7 7
096d01a63714:1337 v1 Hello World from v1 53 7 9
d43c0744622b:1337 v1 Hello World from v1 55 7 6

Updating the application

Now we are going to update your application. Normally, we would expect that you specify a higher version of the Docker image into unit file. But instead of changing the version of the image to be executed change the value of the environment variable RELEASE in the unit template file  paas-monitor\@.service.

sed -i -e 's/--env RELEASE=[^ ]*/--env RELEASE=v2/' paas-monitor\@.service

Now we have changed the unit template file, you should destroy the old unit file and submit the new one.

fleetctl destroy paas-monitor\@.service
fleetctl submit paas-monitor\@.service

Now you have two options, a slow one and a fast one.

Slow Option

The slow option is to  iterate over the running instances, stop them one by one, destroy them and start a new instance based on the newly submitted template. Because this is boring, repetitive work we have created a small script that does this 🙂


./rolling-upgrade.sh paas-monitor\@.service

Fast Option

The fast option is to start 6 new ones and stop all 6 old ones after the new ones are running.

fleetctl load paas-monitor\@1{1..6}.service
fleetctl start paas-monitor\@1{1..6}.service
fleetctl list-units | grep 'paas-monitor\@1[1-6].service' | grep running
fleetctl stop paas-monitor@{1..6}.service
fleetctl destroy paas-monitor@{1..6}.service

When you watch your monitor, you should see the new instance appear one by one.

host release message # of calls avg response time last response time
47ea72be3817:1337 v1 Hello World from v1 53 8 11
cc4227a493d7:1337 v1 Hello World from v1 59 11 8
04a58012910c:1337 v1 Hello World from v1 54 7 6
090caf269f6a:1337 v1 Hello World from v1 58 7 7
096d01a63714:1337 v1 Hello World from v1 53 7 9
d43c0744622b:1337 v1 Hello World from v1 55 7 6
fee39f857479:1337 v2 Hello World from v2 18 7 9
99c1a5aa3b8b:1337 v2 Hello World from v2 2 7 9

Conclusion

CoreOS and Consul provides all the basic functionality to manage your Docker containers and perform rolling upgrade of your application.