Building a Pi Cluster 2020
Yet Another Raspberry Pi Cluster
Following in the footsteps of many others, I’ve built a Raspberry Pi cluster.
Parts
- 4 x 4Gb Raspberry Pi 4 Model B.
- All-the-fours! I’m running them headless, so don’t need the extra memory for graphics.
- 4 x SanDisk Ultra 32 GB microSDHC Memory Card.
- 2 x Cluster Case for Raspberry Pi.
- Nb. if you use the fans, you connect to two of the gpio pins)
- USB Power Cable - to DC Barrel connector.
- This allows you to power the router via USB.
- Anker [Most Compact 10-Port Charger] PowerPort 10 (60W 10-Port USB Charging Hub)
- D-Link GO-SW-8G 8 Port Gigabit Easy Desktop Switch.
- Short USB C Cables [5 Pack 8 inches].
- Cat6 Snagless Ethernet Patch Cable, 5-Pack, 0.3m.
- GL.iNet GL-AR750S-Ext (Slate) Gigabit Travel AC VPN Router.
- I’m happy to have this on its own subnet with fixed ip addresses.
- Thin velcro ties.
- This is to mount the switch and router next to the cluster.
- Velcro adhensive tape.
- This allows you to secure the router against the switch.
The key, as many people have said, is to keep the USB and patch cables short. You may find flat patch cables easier to work with. I’ve chosen regular ones, though they have tendency to twist the cluster gradually, if it’s not secured well enough.
Assembly
The assembly is straight forward, and the case has online video instructions.
Installation
I’ve installed Ubuntu Server 64-bit and microk8s.
To install the OS, simply grab the imager from https://www.raspberrypi.org/downloads/ and write the OS to the SD cards.
Then follow the instructions here: https://ubuntu.com/tutorials/how-to-kubernetes-cluster-on-raspberry-pi#1-overview.
As I’ve built this as a headless cluster, you simply ssh
into each machine to perform the extra set up steps:
sudo snap install microk8s --classic
sudo microk8s.add-node
which generates a connection string in the form of <master_ip>:<port>/<token>
Then you add each node to your k8s cluster:
microk8s.join <master_ip>:<port>/<token>
Finally:
microk8s.kubectl get node
lists all connected nodes.
Persistent Storage
For persistent storage between all the nodes, I’ve mounted my NAS using systemd
on each device so that they can all write to /mnt/nas
, using /etc/systemd/system/mnt-nas.mount
[Unit]
Description=nas mount using cifs
Requires=network-online.target
After=network-oneline.target
[Mount]
What=//mynas.local/home
Where=/mnt/nas
Type=cifs
Options=username=MYNAME,password=MYPASSWORD,rw,uid=1000,gid=1000
[Install]
WantedBy=multi-user.target