Raspberry Pi Cluster, Part 3 - Operating Systems
20 Sep 2021- Raspberry Pi Cluster, Part 1 - Hardware
- Raspberry Pi Cluster, Part 2 - Assembly
- Raspberry Pi Cluster, Part 3 - Operating Systems
- Raspberry Pi Cluster, Part 4 - Jekyll and Docker
- Raspberry Pi Cluster, Part 5 - Kubernetes
- Raspberry Pi Cluster, Part 6 - Dynamic DNS
- Raspberry Pi Cluster, Part 7 - SSL
- Raspberry Pi Cluster, Part 8 - Automation
Now the hardware is sorted, it’s time to turn my attention to the software side of the project. More accurately, the decision I need to make is which operating system I’m going to run on the Pi’s.
There is actually a wider choice here that I originally anticipated, but I’ll keep this bit brief and explain my choices. I worked my way through a couple of options before settling on my operating system of choice.
The initial experiments
To keep things small and simple, one requirement that I scoped out straight-away was that there is no need for any sort of GUI. I want to utilise as much of the onboard power of the Pi’s to run the cluster software, there isn’t any need to waste it on a desktop, etc.
I originally installed the 32 bit version of the official Raspberry Pi OS, but I really wanted to utilise the full 64 bit goodness of the Arm64 processor that the Raspberry Pi’s have, so I rebuilt all of the Pi’s with Ubuntu 21.04 which supports 64 bit. However, and I’m aware that this sounds a little weird, but it just didn’t feel right not running the dedicated Pi OS.
So third time lucky, I rebuilt all of the SD cards again, this time using the 64 bit edition of Raspberry Pi OS.
Even though Kubernetes (or more accurately, the Rancher K3S flavour of Kubernetes) does work on 32 bit OS’s, it seems to be much happier on the 64 bit OS’s and most of the docker images that I originally worked with all were built for 64 bit architectures, so this seems like the best way to go.
Installing Raspbien OS 64 bit
At the time of writing, the 64bit version of the Raspberry Pi OS is still not officially published by the Raspberry Pi Foundation, but it is available to download here: https://downloads.raspberrypi.org/raspios_arm64/images/. Grab the latest .zip and extract the files.
While you’re there, if you haven’t already, download the Raspberry Pi Imager application too as this makes pushing the OS to the SD card a breeze.
The very handy Raspberry Pi Imager
Click on the Choose OS button, scroll to the bottom of the list, select the Use custom option and load up the Raspberry Pi OS 64 image we downloaded earlier. Similarly, click the Choose Storage button and select the SD card that you want to write to.
DON’T CLICK THE WRITE BUTTON YET!
As with any OS install, we need to do some configuration. Fortunately, there is a hidden menu in the app that gives us an easy way to configure the most important settings. On a Mac, if you press Ctrl + Shift + x, you’ll get a new menu popup (I’m not sure what this would be on Windows, I’m sure a quick Google will sort you out).
Now, check Set hostname and give the Pi a unique hostname. I called my first Pi einstein-master, then the next three einstein-worker-01, einstein-worker-02 and einstein-worker-03.
Next, check Enable SSH, I choose the Use password authentication and then set a good password. I’m actually going to setup the public key authentication once the Pi is online, but this means that I can set a good sudo password now. The rest you can leave, unless of course you wish to add some more config now.
Click Save, now you can click that Write button to image the SD card.
Just for your info, this setup can all be done on the Pi itself and when I built the 32 bit versions, I did all this configuration manually, but it’s much quicker to do it this way.
Setting up the Pi’s
We’re getting there now! Stick the SD card into the Pi and power it up. To be honest, I’m not sure if it is necessary to have a static IP for the Pi, but at the very least, it makes it a lot easier to manage. So set a static IP by which ever means floats your boat. I just log into my router and find the IP address and then set a DHCP reservation so that the Pi gets the same IP all the time.
Now we know the IP, we can transfer over our public key to secure up the Pi a little bit better. If you don’t have a key setup, follow these instructions.
Copy over the key with (insert the IP address of your Pi):
ssh-copy-id pi@<IP-ADDRESS>
We can now login to the Pi:
ssh pi@<IP-ADDRESS>
Kubernetes requires the control groups kernel feature to be enabled (more info here), run:
sudo nano /boot/cmdline.txt
And add the following to the end of the line, making sure that everything is on the same line:
cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
Save and close. Next, we can reduce the amount of memory that is allocated to the GPU as we don’t require any graphical features. Run:
sudo nano /boot/config.txt
And add the following to the end of the file:
gpu_mem=16
Almost there! Next we need to disable the SWAP file, again this is for Kubernetes, run each of the following commands:
sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo apt purge dphys-swapfile
I mentioned earlier that we are going to disabled password authentication to increase the security, run:
sudo nano /etc/ssh/sshd_config
And update the following option (you may need to removed the # at the beginning of the line):
PasswordAuthentication no
Finally, let’s update everything (the -y automatically says yes to every question):
sudo apt update && sudo apt dist-upgrade -y
This is probably take a little while, but we are done configuring the Pi. We just need to run reboot the Pi with sudo reboot to make sure all of the new configuration options take effect.
Rinse and repeat for all of your Pi’s, they all need the same setup.