In This Post...
Anybody who’s set up more than a single Raspberry Pi knows how frustrating it can be to keep them all up-to-date and working correctly. The slightest configuration change can require copying files and/or repeating steps between devices.
When I first built my Magic Spellbooks for home automation, I quickly ran in to the Raspberry Pi config management problem. Each “spellbook” acts as a kiosk, connecting to my Home Assistant server, while also running a number of other background tasks. For example, they all act as beacons, determining which room of the house I am in by detecting my phone.
To keep all the spellbooks working together properly, I built a Raspberry Pi config management tool, which I call Tiny Cluster.
Check out Tiny Cluster on Github, which includes setup and quick start instructions.
Why Another Raspberry Pi Config Tool?
There are a number of tools available for Raspberry Pi configuration management. Puppet, in particular, is a popular way to keep multiple devices all working as-expected. Although they are excellent and I would highly recommend them, there are good reasons to take a different approach.
- The community of developers using Docker and Kubernetes gives you access to a wide variety of features and support. You can deploy anything: PiHole, Home-Assistant, WordPress, or even sophisticated cluster monitoring like Prometheus and Grafana (see the end of this post for screenshots).
- They are familiar to any modern system administrator. For the hobbyist, using these tools for configuration management means learning valuable skills applicable to jobs at large technology companies.
- Docker images deployed via Kubernetes are “hermetically sealed.” Instead of attempting to coordinate and sync many different files, each “feature” (like the “beacon” ability I mentioned above) can be encapsulated into a single Docker container. Kubernetes can then schedule the features on the desired devices, without risk of conflict. In a word, container deployment is idempotent.
These days, it’s pretty easy to install Kubernetes with tools like kubeadm. Still, there are a lot of steps which I found repetitive and annoying.
Config Management as Code
At first, it seemed enough to simply install kubeadm on each of my Raspberry Pis and call it a day. This quickly became untenable, as not everything can be entirely encapsulated by Kubernetes. Boot configurations, for example, must necessarily live on the host machine (and not in a Docker container).
Enter Tiny Cluster, my open-source solution to managing a Kubernetes fleet of Raspberry Pis. It takes a simple configuration file and provides a variety of management commands. It allows you to set up a new Raspberry Pi, or deploy updates to a RPi with minimal effort.
YAML has been called the “world’s most popular” programming language. Hairsplitting about what constitutes a programming language, and the many faults of YAML aside… it has indisputably become the de-facto tool of system administrators. This is in no small part due that Kubernetes itself uses to define resources.
A simple tiny cluster configuration file is as follows:
kubernetes: master: address: 192.168.0.1 connect: ssh username: pi nodes: 192.168.0.1: name: main 192.168.0.2: name: spellbook
Raspberry Pi + Kubernetes = Tiny Cluster
Some of the other key features are as follows:
- Set up a brand new Raspberry Pi with a single command.
- Provide “Kiosk Mode” (turn a Raspberry Pi into a dedicated web browser).
- Avoid of one-off scripts and backups.
- Easy to integrate with Home Assistant
- Easy to deploy any Docker image
In the background, each Spellbook is also running a number of Docker containers. At home, node-pi-beacon uses BTLE to detect which room I am in based upon the proximity of my phone to one of the Spellbooks.
Both clusters can also be easily monitored with Grafana:
The possibilities are pretty much endless. I’ve provided a detailed setup guide in the README for Tiny Cluster, as well as examples for deploying a number of different containers like you see above. If you happen to try it out, I’d love to hear how it goes! Drop me a line in the comments below or on Github.