How to turn your Zimablades into a Docker Swarm

A swarm is a cluster of docker daemons working as a cluster to run their workloads. This means that you have an effective way to horizontally scale out your workloads by allowing them to run on multiple machines as well as offering resiliency. In this case we will have a three node cluster so if we lose one node the other two are able to continue to operate.

In a swarm you have at least one manager and a number of worker nodes. A single daemon can undertake both roles in unison. When you create a service within your swarm, you are describing an optimal state which the manager monitors and schedules tasks to the worker nodes in order to maintain that state.

Note that a manager is also a work by default. This is why I create 3 managers in the cluster. Only one manager can be a leader of the cluster at any one time.

Getting to the Console

Swarm mode is not available through the CasaOS interface so you will need to configure the service by issuing docker commands at the command line on the target host.

Please note that setting up your ZimaBlades to act as a swarm does not impact the normal operation of CasaOS through the UI. However, I can't guaruntee that this won't be the case in future releases of CasaOS.

You can of course launch a console within the CasaOS interface at the top left hand .

This will launch a SSH session. Note that the login credentials are defaulted to casaos with password casaos. Although your home network maybe secure you will definitely want to change this. Securing the ZimaBlade will be a project for another time.

This is simply connecting through ssh, and you can infact connect directly from my desktop in this case a windows 11 machine. To do this you simply

ssh casaos@192.168.4.126

You will be prompted for the password. On a later post I'll show you how to authenticate in a different way which is useful for remotely managing your docker swarm. For the time being we'll run the docker commands directly on the machine.

Now we need to initialise the swarm.

Initialising the Swarm

sudo docker swarm init --advertise-addr 192.1684.126

Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager. 
To add a worker to this swarm, run the following command: 
    docker swarm join \ 
  --token SWMTKN-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c   192.168.4.126:2377

the swarm has been created with a single manager node. Note that the command gives you the command for joining other nodes as workers. In our case we want to create a cluster of managers. To get this command you run

sudo docker swarm join-token manager
To add a manager to this swarm, run the following command:

sudo docker swarm join-token manager
 
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1e00rable83lqta3iopazya3e8lkmpoxqfagmq0g8p9bup5vph-0q38vlken7v0i9nxua0p4qwww 192.168.4.126:2377

Now all we need to do is log into our other machines, in my case 192.168.4.127 and 192.168.4.128 and then issue the command below:

sudo docker swarm join --token SWMTKN-1-1e00rable83lqta3iopazya3e8lkmpoxqfagmq0g8p9bup5vph-0q38vlken7v0i9nxua0p4qwww 192.168.4.126:2377

Now once you've done that from any machine you issue

sudo docker node ls

Now you have your swarm up and running. Next I'll show you how to run a service on your swarm.