In this article we'll setup a 3 nodes Kubernetes Cluster running on 3 Raspberry Pi 4B boards.I chose the 4 GB model even though, according to Kubernetes Docs, 2 GB or RAM should be enough.
If You are interested in building your own Cluster, here is the list of components I used:
Plug the MicroSD Card into you computer and launch Raspberry Pi Imager:
Select the OS "Raspberry Pi OS Lite" because it has no GUI
Select your MicroSD Card
Write the OS onto the MicroSD
Enabling ssh
Since your Raspberry Pis don't have a GUI, we'll manage them over SSH. In order to do that, we'll have to create a ssh file in the /boot partition.
In Windows explorer, select the letter assiciated to your MicroSD, In my case D:
Inside the folder, create a new empty txt file. Name it ssh, without extension.This will instruct the Raspberry OS to enable and start the ssh service at boot.
Step 2 - Booting the Pis and setting hostname and IP
From your home router DHCP devices list, you should be able to see you Raspberry Pi IPin my case, the name is raspberrypi_Ethernet and the ip 192.168.0.114.
Now SSH into you Pi and set the hostname. The default username is pi and default password is raspberry:Using an editor of your choice edit /etc/hostname and /etc/hosts with your choosen name:You could also use sed to replace the original hostname with the new one:
1$ sudo sed -i 's/raspberrypi/itdd-k8s-worker-2/' /etc/hosts /etc/hostname
[Optional] In my case I've also decided to create a DCHP reservation, so that I'll always know what IP assigned to what device:
Proceed in the same way for the remaining nodes. in my case I'll setup 3 nodes:
itdd-k8s-master-1, IP 192.168.0.140
itdd-k8s-worker-1, IP 192.168.0.151
itdd-k8s-worker-2, IP 192.168.0.152
If everything worked fine, you should have your k8s nodes up and running:
Step 3 - Software installation
The following commands have to be exected on all the nodes
Install Docker and add your user to the docker group
1$ curl -sSL get.docker.com | sh
2$ sudo usermod -aG docker pi
In the above, "curl -sSL get.docker.com | sh", be careful when you pipe a curl or wget command into sh, since you don't have control on what is actually been executed on your server. Only do it if you trust the source, or alternatively, download the script first and have a look at it before executing it.
Logout and log back in
As the root user create the file /etc/docker/daemon.json with the following content:
In order to provide networking capabilities among the nodes, we need to deploy a Container Network Interface (CNI). There are many different options to choose from. For this instance, we are going to use one of the most common: Flannel