Credits: Logo created by raspberrypi.org
Installation instructions for setting up a local Raspberry Pi cluster at your home desk.
- Operating System on SD Card
- Network Setup
- RPi Configuration
- SSH Config
- Verification
- Troubleshooting
- Summary
Note: For the time this post was published, there isn't an official
Raspberry Pi OS
image that supports a 64 bit system. There are beta versions but with limitations. This blog post won't cover them until officially released.
Operating System on SD Card
Connect the SD card to your local machine (laptop / desktop)
Download
Raspberry Pi OS Lite (Debian Buster)
image from here-
Flash OS image using
Raspberry Pi Imager
as specified in here After flashing, eject and re-connect the SD card again to your local machine
Check for
boot
connected deviceMount the SD card
-
Open a terminal session and create a text file named
ssh
in the boot partition
# If you are working on macOS sudo touch /Volumes/boot/ssh # Other Unix-like operating system sudo touch <path-to-rpi-boot-volume>/ssh
Eject the SD card and connect it to the Raspberry Pi
Network Setup
- Power up the RPi and connect directly to the home router
-
Open the router network dashboard
Note: Your router dashboard address might differ, check with your router manufacture guide.
Verify under
LAN settings
->Client List
that there is a newraspberrypi
clientAssign a static IP address using this guide
RPi Configuration
- SSH into the server using
ssh pi@<RPI-IP-ADDRESS>
with an IP address from previous step and the default passwordraspberry
-
Set the GPU memory split to 16MB by editing the RPi configuration file
sudo vi /boot/config.txt
and appendinggpu_mem=16
to itNote: We specify the minimum memory possible to reserve for GPU (display) since we won’t require user interface.
Reboot using
sudo reboot
for changes to take effect-
SSH again to the RPI server and type
sudo raspi-config
. Edit the following settings:- Change the password for the
pi
user (recommended) - Set the hostname to your liking
-
Make sure SSH server is enabled
Note: If you are planning on using this server as a Kubernetes master - name it
kmaster
. If it is a Kubernetes node, name itknode<number>
while<number>
is the next in-line number of your cluster stack.
- Change the password for the
Close the SSH session and reconnect to the RPi server again
-
Verify hostname was properly set and force manual replacement, if required. From the RPi terminal:
- Run
cat /etc/hostname
and check forkmaster
- Run
cat /etc/hosts
and check for127.0.1.1 kmaster
- Run
hostname
which should returnkmaster
, otherwise runsudo hostname kmaster
and check again
Note: Use
kmaster
orknode<number>
according to the server type if you are setting up a Kubernetes cluster. - Run
-
(Optional): Install your favourite utilities on the RPi server:
# Use Vim as a text editor sudo apt-get -y install vim
-
(Optional): Set your preferred aliases on
~/.bashrc
:
# Open bash run command file for editing vim ~/.bashrc # List all files/directories including hidden ones with size unit suffixes alias l="ls -lah"
-
(Optional): If you are planning to install the Rancher
k3s
version of Kubernetes, you should enable a few container features by adding them to the end of the/boot/cmdline.txt
file:
# Edit file with sudo sudo vim /boot/cmdline.txt # Append the following cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
SSH Config
We need to configure secure shell access for client <-> RPi server communication. It will allow us to access the RPi server from client machines such as our laptop and also allow secure communication between the RPi server and our locally installed utilities.
Client
These instructions are relevant to the computer being used to connect to the RPi server:
- Create directory
~/.ssh
if it doesn't exists and cd into it - Run
ssh-keygen
(with namekmaster OR knode<number>
, no passphrase) -
Add the private key
kmaster
to the ssh agent (select between permanent/temporary)
ssh-add ~/.ssh/kmaster # Add temporary to keychain ssh-add -K ~/.ssh/kmaster # Add permanently to keychain
Note: This will allow a secure communication without prompting for the password every time.
-
Copy the public key to RPi server
# Master node ssh-copy-id -i ~/.ssh/kmaster.pub pi@<RPI-IP-ADDRESS> # Agent node ssh-copy-id -i ~/.ssh/knode<number>.pub pi@<RPI-IP-ADDRESS>
Important: For this step you will need to authenticate with your password. A file named
~/.ssh/authorized_keys
is auto-created with the public key content on the RPi server. (Optional): If you have defined a static IP for the RPi server as described in here, add named hosts records on your client machine:
# Use names instead of IP addresses
echo -e "<MASTER-IP-ADDRESS>\tkmaster" | sudo tee -a /etc/hosts
echo -e "<NODE-IP-ADDRESS>\tknode1" | sudo tee -a /etc/hosts
RPi Server
These instructions are intended for the RPi server to enable SSH communication:
-
Disable SSH
PasswordAuthentication
:- Edit
ssh_config
bysudo vim /etc/ssh/ssh_config
- Uncomment
PasswordAuthentication
by removing the#
prefix - Change its value to
no
- Make sure
PasswordAuthentication
is properly aligned (4 spaces)
- Edit
Restart SSH server
sudo /etc/init.d/ssh restart
sudo /etc/init.d/ssh status # Verify SSH server is running
Verification
To verify everything is set-up correctly, try to connect from the client machine i.e. laptop to the RPi server with the following command:
ssh pi@kmaster
ssh pi@knode<number>
Troubleshooting
Locale
What? Locale errors/warnings when connecting to a RPi server and/or running locale
on a server node. These are a few example errors:
setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Solution: We'll set our locale to en_US
by running the following steps:
- SSH to the RPi server
- Edit the
locale.gen
file usingsudo vi /etc/locale.gen
- Uncomment the line with
en_US.UTF-8
by removing the#
character (make sure there are no leading spaces) - Run
sudo locale-gen en_US.UTF-8
- Run
sudo update-locale en_US.UTF-8
- Run
locale
and make sure there are no errors/warnings
Summary
By the end of this post you should have a working headless (non-GUI) Raspberry Pi(s) connected to your home network with SSH communication available, good job ! 👏
What now? You are welcome to check back for a future blog post on how to install Kubernetes on top of your amazing RPi cluster.
Please leave your comment, suggestion or any other input you think is relevant to this post in the discussion below.
Like this post?
You can find more by:
Checking out my blog: https://blog.zachinachshon.com
Following me on twitter: @zachinachshon
Thanks for reading! ❤️
Top comments (2)
What did you do with your cluster after you built it? What are the uses a cluster of computers? Is a cluster of computers something like RAID but at the server level? In case one fails it can be replaced without any downtime.
Hey, it's a good question, I've deployed k3s (Kubernetes distribution from Rancher Labs) on top of the RPi cluster. I'm using it as a production environment hosting my personal stack of services running on top of it. In addition, it serves me as a playground environment (on a different k8s namespace) when in need to offload workloads from my local machine.
The RPi cluster is a good alternative to the monthly usage fee you'll have to pay for managed VMs using the different cloud providers. In this case, you pay once and have a home lab ready to go. I'm using k3s to enjoy all the benefits there are in a managed container orchestration.
If you require to communicate with the RPi cluster from outside your home network, you can spin a basic and super cheap VM from one of the cloud providers (~5$ monthly) and run a simple service that interact with a client service running at your home network for basic request tunneling.
I'll be posting soon a k3s installation guide for the RPi cluster, you are welcome to stay tuned :)
Thanks for reading !