As I discussed in post Portable #Docker #Swarm made of #RaspberryPI – Updated hardware there were several hardware updates done to the swarm. One of the updates was adding a switch and connecting all the Raspberry PIs to the switch.
First version of the Docker Swarm was done using the wifi connections of the PIs. This is not so reliable as the IPs were obtained through DHCP (so they may change) and the wifi to which they are linked is my house Wifi so not so mobile.
In the following I will change the swarm to a static IP, ethernet based swarm
STEP 1: Set static IPs for eth0 interface of the swarm nodes
To set up a static IP for an interface in Raspbian Jessie one has to add at the end of /etc/dhcpcd.conf the following:
interface eth0 static ip_address=192.168.20.102/24 static routers=192.168.20.1
line 1: declares to what interface we want to do the changes
line 2: declares the static ip (note that this is different for each node but same mask /24)
line 3: declares the address of the default route, the IP of the Edimax router to which Raspberry PIs are connected through the switch.
STEP 2: Recreate the Docker Swarm
On one of the former swarm master nodes do:
docker swarm leave --force docker swarm init --advertise-addr 192.168.20.102
This will force leave the former swarm and then initialize a new swarm, but this time using the eth0 IP address.
Then we can obtain the worker and manager tokens as:
docker swarm join-token worker docker swarm join-token manager
STEP 3: Add all the other swarm nodes
This last step is easy done by executing the commands obtained at Step 2 on the designated worker(2) and manager(3) nodes.
STEP 4: Deploy portainer for monitoring
To monitor the new swarm deploy on the swarm a portainer (https://github.com/portainer) instance by executing on PI1 (master node) the following:
docker service create --name portainer --publish 9000:9000 \ --constraint 'node.role == manager' \ --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \ portainer/portainer -H unix:///var/run/docker.sock
Now I can monitor the swarm directly from PI5 screen.
Look at that 20 CPUs !!! a monster 🙂