I turned my drawer full of “useless” Raspberry Pis into a powerful Docker Swarm cluster


If you’re like me and have a drawer full of Raspberry Pis that are sitting unused, pull them out and turn them into something useful. I chose to create a Docker Swarm cluster with mine, and I think it’d be a great benefit to your homelab, too.

Want an affordable Linux server? Get a Raspberry Pi

They’re compact, can be picked up for cheap, and you might already own a few

Closeup of a Raspberry Pi SBC. Credit: Corbin Davenport / How-To Geek

The best part of a Raspberry Pi is that it’s a full-fledged computer in an ultra-small form factor. You’re able to run full operating systems on the fanless and silent single-board computer. This is fantastic considering comparable microcontrollers only execute base code, and don’t run a full operating system.

The Raspberry Pi also uses hardly any power. For example, the latest Raspberry Pi 5 only draws around 2.5W to 5W at idle, and under load (with a SSD attached) it maxes out around 12W. Compare this to the average power draw of around 20W to 40W of a Core Ultra 5 mini PC, and the Pi is so much more efficient. This is especially seen in older Pis like the Pi 4 B, which maxes out around 7W, or the Pi Zero 2 W, which idles at around 0.6W to 1.4W, and maxes out at around 3W under heavy load.

So, when building a low-power Docker Swarm cluster, the Raspberry Pi is really one of the most ideal systems you can choose.

  • Brand

    Raspberry Pi

    CPU

    Cortex-A72 (ARM v8)

    With the Raspberry Pi 4 Model B, you can create all kinds of fun projects, and upgrade gadgets around your home. Alternatively, install a full desktop OS and use it like a regular computer.


  • Raspberry Pi Zero 2 W,png

    Brand

    Raspberry Pi

    CPU

    Quad-core 64-bit ARM Cortex-A53

    The Raspberry Pi Zero 2 W is super tiny and super affordable, but it packs enough computing power for a variety of DIY projects. You can use it to create a handheld retro gaming console, for Klipper/Mainsail, a super compact home or media server, and more. 


Docker is fully supported on the Raspberry Pi

Most images come with ARM versions that are perfect for the single-board computer

A container floating in the sea with the Docker logo inside it. Credit: Lucas Gouveia/How-To Geek | klyaksun/Shutterstock

One of the other major reasons to turn Raspberry Pis into a Docker Swarm cluster is that Docker is fully supported on the Pi. While not every container offers ARM support, a vast majority of them do, which makes using Pis as Docker hosts all the better.

The other thing to keep in mind is that, while many containers do support ARM, not every container is meant to run on ARM. Take Plex as an example. It definitely can run on a Raspberry Pi, but the experience won’t be the best as you won’t have access to hardware transcoding, even on newer Pis.

Before you go all-in on using Raspberry Pis for a Docker Swarm cluster, just do a quick sanity check to make sure that the containers you plan to run work well on Pi. If they don’t, or if they aren’t even available, then a Swarm cluster will do you no good. Thankfully, the containers I planned to run work perfectly on ARM, making my Pis a fantastic option for my Docker Swarm cluster.


Illustration of the Docker logo, featuring a stylized whale carrying containers and a NAS server.


How I run my entire homelab on Docker (and why you should too)

All my services, all in neat little boxes.

It’s easy to put multiple Docker systems into a cluster

Docker Swarm doesn’t have to be as complicated as you think

Now, how do you actually turn a drawer of unused Raspberry Pis into a full-on Docker Swarm cluster? It’s not as hard as you may think, though there are definitely several steps involved. Step one is getting Raspberry Pi OS 64-bit Lite installed. Go the route of Lite because there’s no reason for a desktop environment here, terminal-only is just fine.

From there, you need to make sure each Pi is connected via Ethernet, has a proper hostname, and Docker gets installed. You can use Wi-Fi, but it’s definitely recommended to use Ethernet for a setup like this for reliability.

sudo hostnamectl set-hostname pi-swarm-1
curl -fsSL [<https://get.docker.com>](<https://get.docker.com/>) | sh
sudo usermod -aG docker $USER
sudo reboot

The hostname is very important (and also needs to be unique to each Pi in the Swarm cluster). While not necessary, having unique and identifiable hostnames makes it easier to manage the nodes through their hostnames.

Now, before actually creating the cluster, you should mount shared storage to each Pi. The shared storage ideally would be a NAS, but could also be the manager Pi (that we’ll talk about in a minute). The reason you need shared storage is so that when a container stops running on one Pi for whatever reason, another Pi can pick up where it left off with the same configuration files.

sudo apt install nfs-common -y
sudo mkdir -p /mnt/nfs/shared
echo "192.168.x.x:/path/to/nfs/share /mnt/nfs/shared nfs defaults,_netdev 0 0" | sudo tee -a /etc/fstab
sudo systemctl daemon-reload
sudo mount -a

Now that there’s shared storage, it’s time to actually set up the Docker Swarm cluster. You’ll run the following command on your primary manager node: docker swarm init --advertise-addr . I say manager node because in a Docker Swarm setup, at least one Docker instance has to be the manager, and then you have worker nodes that join the manager.

Whenever you run that command, you’ll get an output command that has a token in it. Take that join command, and run it on the other Pis to get them to join up to the manager node. It’ll look something like this: docker swarm join --token SWMTKN-... 192.168.x.x:2377 Lastly, once everything is joined up, run docker node ls to make sure that the other Pis are properly joined with the manager node.

Now that you have the nodes and manager set up, you could just start deploying services. But, I’d take a few more minutes to properly set up the NFS share with Docker using a Docker Volume. You don’t have to do this step, and could just bind mount the NFS share in your Docker deploy commands, but packaging it up in a Docker Volume just makes things a bit tidier.

docker volume create \
--driver local \
--opt type=nfs \
--opt o=addr=192.168.x.x,rw \
--opt device=:/srv/nfs/shared \
nfs-volume

Once you have that volume mounted, you just reference the data as nfs-volume in your deploy commands and Docker handles the rest. Just keep in mind, some services, like MySQL or PostgreSQL, really don’t like NFS storage and prefer local storage or more advanced setups like clustered storage.

Now you can deploy containers however you normally do, through Portainer, Docker CLI, Docker Compose, or any other method. The Pis will now work in a cluster and move services around as needed, without you having to do anything else. It turns your cheap collection of Raspberry Pis into a full-on home server setup.


Raspberry Pis offer a ton of homelab value

Being able to take a handful of Raspberry Pis that were sitting unused in a drawer and deploy a full Docker Swarm setup within just a few minutes is an invaluable skill and feature to any homelab. Once deployed, it’s extremely simple to spin up an instance of anything you need and just have it redundantly fall back between different systems as you maintain or update a Pi down the road.

Plus, having the experience of setting up a distributed, high-availability system like this with cheap hardware helps prepare you for doing the same thing on more expensive hardware down the road. While I used to run three Raspberry Pis in my homelab, now I have three mini PCs which offer way more power and capability, but the setup procedure was exactly the same.



Source link

Leave a Reply

Subscribe to Our Newsletter

Get our latest articles delivered straight to your inbox. No spam, we promise.

Recent Reviews


If you’ve bought a new Raspberry Pi, or just got your hands on an older model that someone else didn’t want, there are many ways to put that little computer to good use, and here are six of them.

Retro gaming galore

Recalbox running on a Raspberry Pi 500+. Credit: Tim Brookes / How-To Geek

One of the most popular uses for Raspberry Pi computers is as a retro gaming emulation system. Which systems can be emulated depends on which specific model of Pi you have, but even the oldest ones can do a great job with retro 8-bit and 16-bit titles, or MAME arcade titles. In fact, building your own arcade cabinet with a Pi at its heart is a common project, and you’ll find lots of instructional guides on the web to that effect.

8bitdo arcade stick for Nintendo Switch.

8/10

Number of Colors

1

Control Types

Arcade Stick


Build your own NAS

A Raspberry Pi configured as a NAS. Credit: Raspberry Pi Foundation

A NAS or Network-Attached Storage device is effectively a local file server that lets you store and access data on your local network using hard drives. You can go out and buy a NAS or you can follow the official Raspberry Pi NAS tutorial and turn your old USB hard drives into a NAS using stuff you already have, or can get for just a few dollars.

Everyone loves local streaming tools like Plex or Jellyfin, but not everyone wants to dedicate an expensive computer to act as the streaming server. Well, as long as your requirements aren’t too fancy, you can use a Raspberry Pi as a Plex server.

Just don’t expect it to handle heavy-duty transcoding. The good news is that most of your client devices can probably play back videos without the need for transcoding.

Turn your Pi into a home automation hub

The Home Assistant Green smart home hub surrounded by smart home devices. Credit: home-assistant.io

Home automation hub devices can cost hundreds of dollars, but if you have an old Raspberry Pi, you can run your smart home off it. The most common and effective solution is an open-source app called Home Assistant.

Raspberry Pi logo above a photo of Raspberry Pi boards.


I Run My Smart Home Off a Raspberry Pi, Here’s How It Works

Make your home smarter on a budget with a Raspberry Pi.

Build a weather station

If you’re interested in the weather, want to contribute to weather data, or are just sick of getting rained on when you least expect it, you have the option of getting a weather station kit for your Raspberry Pi or using something like the Raspberry Pi Sense HAT, which can detect pressure, humidity, and temperature, but not wind speed. However, there are also generic wind and rain sensors you can buy, and, of course, don’t forget an outdoor project enclosure.

There are a few guides on the web, but this weather station guide for Raspberry Pi is a good place to get some ideas.

Create a home web server

Another fun project to do is hosting your own little web server using a Raspberry Pi. You can make a website that only works on your home LAN, or even host something that people from outside your home network can access. Using open source software to host your own web resources is highly educational, and it can also be a way to do something genuinely useful without having to rely on a cloud service somewhere on the internet.

Imagine having your own little bulletin board at home, or hosting content like ebooks, music, or audiobooks?


Infinite possibilities

Despite lacking in the raw power department, all Raspberry Pi devices are little miracles—single board computers that can (in principle) do anything their bigger cousins can. Just more slowly. So if you have a few old Raspberry Pis hanging around, don’t be too quick to retire them yet.



Source link