Xmas Tech Cookbook : Docker Swarm & Rancher Walkthrough

Objectives of this post

  • Install Docker on all machines
  • Setup a Docker Swarm
  • Setup Rancher to manage the lot

docker-swarm-020-5-638.jpg

Test Scenario

For this walkthrough I’ll be using 4 x Azure A0 Machines with Ubuntu 14.04TLS on them. Three of those will serve as docker hosts and one will be my Rancher management tooling. The docker hosts will be put into a swarm. For easy reference (and as a basic enterprise simulation), I’ve setup my docker hosts in a seperate subnet compared to the rancher.

Prerequisite Installations on all nodes

We are going to install docker on all the four nodes. As we are using Ubuntu 14.04TLS as our base OS for this walkthrough, I used the following guide as a reference ; https://docs.docker.com/engine/installation/ubuntulinux/

sudo apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo “deb https://apt.dockerproject.org/repo ubuntu-trusty main” > /etc/apt/sources.list.d/docker.list

sudo apt-get update

sudo apt-get install linux-image-extra-$(uname -r)

sudo apt-get install docker-engine

sudo service docker start

 

NewRelic Installation (bonus / optional)

As I always want to know how my cattle is doing, I’ve also taken the time to integrate these machines into my NewRelic account.

sudo echo deb http://apt.newrelic.com/debian/ newrelic non-free >> /etc/apt/sources.list.d/newrelic.list

sudo wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add -

sudo apt-get update

sudo apt-get install newrelic-sysmond

sudo nrsysmond-config --set license_key=mylittlelicensekeythatiwontshare

sudo /etc/init.d/newrelic-sysmond start

2015-12-23 09_54_42-Foto's

 

Setup Swarm : Prepare Nodes

(The steps below are based upon this guide ; https://docs.docker.com/swarm/install-manual/ )

On all nodes, do the following ;

docker pull swarm

Then create the cluster on the first node ;

docker run –rm swarm create

The command will return the cluster id (f.e. “f93794dc6f9d6ce3ab00e59c78ada490”). Note this down, as we’ll need it in a bit…

Yet again, on all nodes …

Edit the “/etc/default/docker” and add/change/uncomment the following options ;
DOCKER_OPTS=”-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock”

Then restart the docker service
sudo service docker restart

From the first node, add all nodes to the cluster

docker run -d swarm join –addr=10.0.0.4:2375 token://f93794dc6f9d6ce3ab00e59c78ada490

docker run -d swarm join –addr=10.0.0.6:2375 token://f93794dc6f9d6ce3ab00e59c78ada490

docker run -d swarm join –addr=10.0.0.5:2375 token://f93794dc6f9d6ce3ab00e59c78ada490

 

Setup Swarm : Prepare the manager

Now we will startup the manager at port 2222. Be aware that you can choose this port freely…

docker run -d -p 2222:2375 swarm manage token://f93794dc6f9d6ce3ab00e59c78ada490

And we’ll verify if all went well…Let’s see if the manager knows the nodes we’ve just added ;

f00@docker01:~# docker run –rm swarm list token://f93794dc6f9d6ce3ab00e59c78ada490
10.0.0.6:2375
10.0.0.5:2375
10.0.0.4:2375

Now let us check if all went well… If it looks like this, then your manager isn’t able to contact your nodes!

f00@docker01:~# docker -H tcp://10.0.0.4:2222 info
Containers: 0
Images: 0
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 0
CPUs: 0
Total Memory: 0 B
Name: 1955364fc6c1

Where it should look like this ;

f00@docker01:~# docker -H tcp://10.0.0.4:2222 info
Containers: 14
Images: 3
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 3
docker01: 10.0.0.4:2375
└ Status: Healthy
└ Containers: 14
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 702 MiB
└ Labels: executiondriver=native-0.2, kernelversion=3.19.0-41-generic, operatingsystem=Ubuntu 14.04.3 LTS, storagedriver=aufs
docker02: 10.0.0.5:2375
└ Status: Healthy
└ Containers: 0
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 702 MiB
└ Labels: executiondriver=native-0.2, kernelversion=3.19.0-41-generic, operatingsystem=Ubuntu 14.04.3 LTS, storagedriver=aufs
docker03: 10.0.0.6:2375
└ Status: Healthy
└ Containers: 0
└ Reserved CPUs: 0 / 1
└ Reserved Memory: 0 B / 702 MiB
└ Labels: executiondriver=native-0.2, kernelversion=3.19.0-41-generic, operatingsystem=Ubuntu 14.04.3 LTS, storagedriver=aufs
CPUs: 3
Total Memory: 2.057 GiB
Name: 48d5e431c0d0

 

Caution : Single Point of Failure Detected!

Be wary that the current setup is for development purposes only! For production I would HIGHLY recommend you go for the high available setup ; https://docs.docker.com/swarm/multi-manager-setup/

single.jpg

Here you will combine a clustering mechanism (consul, etcd, zookeeper, …) in combination with replicating the swarm manager to other nodes. The swarm replication will make sure the data is replicated, where the clustering mechanism will take care of the logic in terms of when / how to do a failover.

 

Let’s go Rancher!

In all honesty, setting up Rancher shows the true potential of Docker…

docker run -d –restart=always -p 8080:8080 rancher/server

Now let it “cook” for a while, and the GUI will pop up on port 8080 of our Rancher node. Meanwhile I went and opened up the port between my labo and my own network. This to ensure that I can access the web console.

On a sidenote ; an A0 seems a bit light for Rancher…

2015-12-23 11_14_48-rancher01 - New Relic.png

As it took quite some time to get through the startup.

 

Adding the nodes to Rancher

2015-12-23 11_50_50-New notification

And we’ll see them popping up …

2015-12-23 11_52_35-Rancher

One thing I found sad, is that Rancher doesn’t detect the Swarm. So most of our effort here was in vain. :/

Rancher does support swarm, though apparently only if you provision the hosts via Rancher…

Anyhow, now you can harness the power of Rancher ;


Update ; feedback was sent by the kind people of rancher that Swarm Discovery is being developped.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s