This post will probably the sortest one of the series, since setting up Docker Swarm is so easy.
Context
After my previous post, I added a new cloud server to my Hetzner account and connected it to the VPN. This new machine I will use as manager, so I'll use it to initialize the swarm.
Why not Kubernetes?
There's no technical reason involved. I picked Swarm mostly because comes with the Docker Engine, so I don't have to install anything else. I'm sure Kubernetes should work just as fine (if not better) if you know how to use it.
I've never used Kubernetes and don't think I need it. If the startup ends up actually scaling a lot, I'm fairly sure I'll have to make the switch, but that's tomorrow's problem. Swarm works fine for me, at least as far as I've used it.
Dependencies
In case it's not obvious, you need Docker Engine installed. If you don't have that yet, follow their own guide or any other you might prefer. I won't be covering that in this guide.
Set up
With my Docker installed I can initialize the swarm. Since I want the swarm to be available only on my VPN, I'll add some extra parameters to specify which IP it should use.
First, let's find out which IP it has on the VPN:
root@hz-manager-1:~# tailscale status
100.64.0.1 hz-manager-1 infra linux -
<....redacted....>
With that information, let's initialize the swarm:
root@hz-manager-1:~# docker swarm init --advertise-addr 100.64.0.1 --listen-addr 100.64.0.1
Swarm initialized: current node (vuqh3puzury9j4y3dqphhiqn3) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token <redacted> 100.64.0.1:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
The swarm has been initialized and it even gives you a few useful commands which you might want to use. Let's add a worker to the swarm, by copying the command from this terminal and pasting it in the other server's terminal:
root@hz-vpn-server-1:~# docker swarm join --token <redacted> 100.64.0.1:2377
This node joined a swarm as a worker.
Seems like it works. Let's confirm by checking in the manager node:
root@hz-manager-1:~# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
vuqh3puzury9j4y3dqphhiqn3 * hz-manager-1 Ready Active Leader 27.3.1
wjf7ijy250r0gaujc53jwel41 hz-vpn-server-1 Ready Active 27.3.1
The swarm is ready to accept services. I won't be doing that on this post, that will be done in the next post of the series to install my reverse proxy.
Top comments (0)