Raspberry pi cluster, Traefik, Docker Swarm, GlusterFS and AZ - Part 2

Raspberry pi cluster, Traefik, Docker Swarm, GlusterFS and AZ - Part 2

Now when we have our Raspberry Pi´s ready to go, we want to install docker on each of the pi to create our swarm. First, we need to install some other stuff needed for docker. Simply run this:

sudo apt-get install apt-transport-https ca-certificates software-properties-common -y


then we run a simple command provided from docker that i found is the easiest way to install docker on ARM. The script set apt sources and find the right build architecture.

sudo curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh

you will get a nice print with all information about the install and at the bottom you can also see docker provide you with a command to add your user to the docker group. And we want to do this user can run docker commands.

sudo usermod -aG docker jonathan

We can now check if docker is running with this command:

systemctl status docker.service

If it says running, we are done with our first one. Now you need to do this for all the other pi´s.

To make this a bit smoother you can pipe (fire commands after each other) in Linux. So, let's do this:

sudo apt-get install apt-transport-https ca-certificates software-properties-common -y && curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh && sudo usermod -aG docker jonathan && systemctl status docker.service

you can fire this on every node and just look that everything went fine.


We can finally create our swarm!

Now on our manager node, you can choose any one you want but i recommend a rpi4 since that some services requires to be single instance and need persistence. In my case i will chose my rpi4-node1.

Before we fire the docker swarm init, log out and in, for the permissions to take effect, otherwise our user have no access to use docker and you will see a permission denied. When you logged in again on rpi4-node1 run:

docker swarm init --advertise-addr 192.168.1.210

We going to get message that we created the swarm and a command to join workers or managers to the. But first we can check our nodes to see which nodes are active and which are worker or manager nodes:

docker node ls

Login to the other pi´s and fire the command:

docker swarm join --token SWMTKN-1-2o21f7nquutz4o3fthtaucwdiofbxkkg5r2uqjlyekfy8r5yf0-5y6sxcpbpm5cjzkedfrb0s341 192.168.1.210:2377

Then we fire our command to list all nodes in our cluster. We can also see status, on each node, if they are active and if it is a manager node or can be promoted to one and the docker version.

This will be the end for the second part. In the next we will look at Traefik and load balancing. We will add it to the cluster and add an application that is routed through Traefik.

Subscribe to Jonathan Stendahl

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe