Blog

Rolling upgrade of Docker applications using CoreOS and Consul

06 Apr, 2015
Xebia Background Header Wave

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.
[bash]
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…

[/bash]

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.
[bash]
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
[/bash]

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.
[bash]
fleetctl submit paas-monitor\@.service
[/bash]
Then, you load and start the new instances.
[bash]
fleetctl load paas-monitor\@{1..6}.service
fleetctl start paas-monitor\@{1..6}.service
fleetctl list-units | grep paas-monitor
[/bash]
You can now see the paas-monitor in operation on your machine by opening https://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!

hostreleasemessage# of callsavg response timelast response time
47ea72be3817:1337v1Hello World from v153811
cc4227a493d7:1337v1Hello World from v159118
04a58012910c:1337v1Hello World from v15476
090caf269f6a:1337v1Hello World from v15877
096d01a63714:1337v1Hello World from v15379
d43c0744622b:1337v1Hello World from v15576

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.
[bash]
sed -i -e ‘s/–env RELEASE=[^ ]*/–env RELEASE=v2/’ paas-monitor\@.service
[/bash]
Now we have changed the unit template file, you should destroy the old unit file and submit the new one.
[bash]
fleetctl destroy paas-monitor\@.service
fleetctl submit paas-monitor\@.service
[/bash]
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 🙂
[bash]
./rolling-upgrade.sh paas-monitor\@.service
[/bash]

Fast Option

The fast option is to start 6 new ones and stop all 6 old ones after the new ones are running.
[bash]
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
[/bash]
When you watch your monitor, you should see the new instance appear one by one.

hostreleasemessage# of callsavg response timelast response time
47ea72be3817:1337v1Hello World from v153811
cc4227a493d7:1337v1Hello World from v159118
04a58012910c:1337v1Hello World from v15476
090caf269f6a:1337v1Hello World from v15877
096d01a63714:1337v1Hello World from v15379
d43c0744622b:1337v1Hello World from v15576
fee39f857479:1337v2Hello World from v21879
99c1a5aa3b8b:1337v2Hello World from v2279

Conclusion

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

Mark van Holsteijn
Mark van Holsteijn is a senior software systems architect at Xebia Cloud-native solutions. He is passionate about removing waste in the software delivery process and keeping things clear and simple.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts