Install Docker Swarm
April 10, 2021 | ClusterNow, I came to Swarm after have been in the K8s universe for a year or so. And I just fell in love with Docker Swarm from first try. So, I would encurage anyone working with Pi's to choose Docker Swarm over any K8s solution out there, any day under any circumstances!
The first think and most complicated is to install Docker. Do not install from snap which is not maintained any longer. Follow the instructions from Docker (or the steps below): https://docs.docker.com/engine/install/ubuntu/#installation-methods
This command:
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
add the official repository GPG-key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
and for arm64bit arch:
echo \
"deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
and last:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Test everything by deploying a container:
sudo docker run hello-world
and make sure every thing is running as it should.
To prevent using "sudo" infront of every command, we will make a docker group and add our user:
sudo groupadd docker
and
sudo usermod -aG docker $USER
After the above you have to log out of the session and in again.
Setting up Swarm
Start by initialising Swarm on the "manager" node:
docker swarm init --advertise-addr 192.168.68.121 (manager ip)
after that you will get a command with a token, that you have to run on all nodes (agents/slaves) that you want to connect to the master (cluster). Important: You have to install docker on those machines too.
Command ex.:
docker swarm join --token SWMTKN-1-3k26e5jjbr6pgha59wt7xo5nsdcyjlgw6hu0fcl4ons8-cwvdge26mywxi5nh70q1lbwu2 192.168.68.121:2377
After all nodes are connected, run the following command to check that the master has connection:
docker node ls
You should see something like this: