Docker Swarm is Awesome
How good is Docker swarm?
Over time I had developed a heap of docker-compose.yml
files for various services and things were starting to get out of hand.
It was difficult to keep on top of updates, it was difficult managing .env
files and keeping track of what was on the server and what wasn't.
I had tried Docker swarm in the past. It looked daunting at first, and at the time, I opted to stick with fiddling with compose files instead of learning something new.
With kubernetes taking the world by storm, I thought about creating a cluster from a bunch of Raspberry Pis and testing it out. A friend challenged me: "Why kubernetes? Why not try Docker swarm?"
So it was time to put my learning cap on and take another look. After a few failures and hissy-fits, i managed to deploy a very simple test service. Then I joined a Raspberry Pi 3B to the swarm and scaled it up. This is cool. And it's actually easier than I thought.
So why is it better than compose?
- I don't have to worry about which machine the service is running on.
There are some services that don't have image digests for all architectures, so some services are constrained to run on a particular node, and of course some services are constrained to manager nodes. But once the constraints are set, the swarm can manage where the services are deployed. - I don't have to worry if a machine goes down.
The swarm will make sure the desired number of service replicas are running. - I get to leverage secrets.
Secrets are a great way to handle sensitive information such as passwords that allow a service to attach to a database. Unfortunately, some public images don't have the required plumbing to fully utilise this feature, as the secrets are stored as a file on the container. - I get to leverage configs.
Configs are a great way of managing configuration files for services. It's much more elegant than stuffing environment variables in a compose file.
What's more is I've also discovered and making heavy use of the docker context
command, or docker --context xyz ...
to deploy stacks from my machine, rather than copying the compose file to the server, copying any config or .env
files, ssh
ing in, and starting the service on the server. This works for just about every docker command.
I've set about transforming my compose files to stack files for deployment to the swarm. I'm taking the time to migrate the individual service databases to a common database service which should help to reduce the load on the server a little.
If swarm is this easy, then maybe kubernetes isn't too bad. Right?
I tried k3s. I uninstalled k3s. I'll try it another time...