This article is part of the series Build your very own self-hosting platform with Raspberry Pi and Kubernetes
- Install Raspbian Operating-System and prepare the system for Kubernetes
- Install and configure a Kubernetes cluster with k3s to self-host applications
- Deploy NextCloud on Kuberbetes: The self-hosted Dropbox
- Self-host your Media Center On Kubernetes with Plex, Sonarr, Radarr, Transmission and Jackett
- Self-host Pi-Hole on Kubernetes and block ads and trackers at the network level
- Self-host your password manager with Bitwarden
- Deploy Prometheus and Grafana to monitor a Kubernetes cluster
Fist of all, we need to install and configure Raspbian Linux Operating System on each node of the future Kubernetes cluster.
Our cluster will be composed of three machines (I might use the terms device, machine, node or host, that’s all the same! a Single-Board Computer used as part of our future cluster):
|kube-master||192.168.0.22||A Master represents the main node of the cluster responsible of the orchestration. It can act as a worker as well and run applications|
|kube-worker1||192.168.0.23||A Worker is a machine dedicated to run applications only. It is remotely managed by the master node|
|kube-worker2||192.168.0.24||A Worker is a machine dedicated to run applications only. It is remotely managed by the master node|
We are using a Portable SSD connected to the master node and exposed to the worker via NFS to store the volume data.
- Do not forget to run each step on each node (unless specified)
- We assume here your local network is under 192.168.0.x. You might need to change to match your home network.
- If you prefer to use a NAS rather than a SSD, skip the part “Configure the SSD disk share” but configure the NFS client on each machine.
- When I refer to the “local machine”, it’s usually your laptop or Desktop PC from where you are reading this.
1. Download the latest version of the Raspbian Linux OS for RaspberryPi
Go to the download page and download Raspbian Buster Lite.
- Raspbian is a Debian-based computer operating system for Raspberry Pi.
- Buster Lite is a minimal version of Raspbian that doesn’t contain a Desktop or Recommended software. We can start from a very clean, light and fresh install using this version.
2. Unzip the archive to obtain the image
3. Plug an Micro SD Card into your local machine
4. Use Etcher and flash the image on the SD card
Download Etcher to flash OS images to SD cards & USB drives, safely and easily.
Launch Etcher, select first the image extracted of Raspbian, select the Media (SD card) and click on Flash.
5. Once flashed, navigate to the folder /boot of the SD card and create an empty file
Adding the file named
ssh onto the boot partition enables SSH by default.
6. Unplug the Micro SD Card from your local machine and plug it to the Raspberry Pi
7. Plug the power to the Raspberry Pi as well as an Ethernet cable
After you power up each device, we will attempt to connect from our local machine to the node via SSH. If you are under Linux or MacOS, toy only need to open a new terminal. For Microsoft Windows users, you can download and use Putty as SSH client.
1. Determine the device IP address
Your network router probably assigns an arbitrary IP address when a device tries to join the network via DHCP. To find the address attributed to the device, you can check either on your router admin panel (usually http://192.168.0.1 assuming your local network is 192.168.0.x) or via a tool like angryip.
E.g. Virgin Media Hub
In my case, the device named raspberrypi (hostname) is assigned to the IP address 192.168.0.22.
2. Connect via SSH to the machine
From a new terminal (or Putty), execute the following command
ssh pi@<IP> to connect remotely to the node. You will be asked to accept to establish the connection (answer
yes) and then to enter the password. The default password after a fresh Raspbian installation is
raspberry (this will be change after this step).
greg@laptop:~$ ssh firstname.lastname@example.org
Well done, you are now connected remotely to the machine. Do the same for the other machines of the cluster.
Before starting installing the Kubernetes cluster, we need to run a few common steps and security checks.
The default password configured by Raspbian is well known, so it is highly recommended to change it to something else only you know:
pi@raspberrypi:~ $ passwd
As we saw on the router, the default machine hostname is
raspberrypi, keeping this could be quite confusing when we’d have two more machines with the same name. To change the hostname, two files needs to be edited:
1. Edit the file
/etc/hostname and replace
pi@raspberrypi:~ $ sudo vi /etc/hostname
vi? take a look at the Vim cheat-sheet or alternatively, use nano.
2. Edit the file
/etc/hosts and replace
raspberrypi (line 6) by
pi@raspberrypi:~ $ sudo vi /etc/hosts
To make sure, the system is up-to-date, run the following command to download the latest update and security patches. This step might take a few minutes.
pi@raspberrypi:~ $ sudo apt-get update && sudo apt-get upgrade -y
By default, the router assigns a arbitrary IP address to the device which means it is highly possible that the router will assign a new different IP address after a reboot. To avoid to recheck our router, it is possible to assign a static IP to the machine.
Edit the file
/etc/dhcpcd.conf and add the four lines below:
pi@raspberrypi:~ $ sudo vi /etc/dhcpcd.conf
PS: This could be also done at the network level via the router admin (DHCP).
We need to enable container features in the kernel in order to run containers.
Edit the file
pi@raspberrypi:~ $ sudo vi /boot/cmdline.txt
and add the following properties at the end of the line:
cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
pi@raspberrypi:~ $ sudo reboot
Reconnect after a few seconds
greg@laptop:~$ ssh email@example.com
Check if the hostname has been updated
pi@kube-master:~ $ hostname
Switch Debian firewall to legacy config:
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
As explained during the introduction, I made the choice to connect a portable SSD to the Master node and gave access via NFS to each worker.
====== Master node only - Mount the disk and expose a NFS share ======
A. Mount the disk to the master
1. Plug the SSD to the USB3.0 (blue) port
2. Find the disk name (drive)
Run the command
fdisk -l to list all the connected disks to the system (includes the RAM) and try to identify the SSD. The disk which has a size of 465.6 GiB and a model name Portable SSD T5 and located into
/dev/sda is our SSD.
pi@kube-master:~ $ sudo fdisk -l
3. Create a partition
If your disk is new and freshly out of the package, you will need to create a partition.
pi@kube-master:~ $ sudo mkfs.ext4 /dev/sda
4. Manually mount the disk
You can manually mount the disk to the directory
pi@kube-master:~ $ sudo mkdir /mnt/ssd
5. Automatically mount the disk on startup
Next step consists to configure
fstab to automatically mount the disk when the system starts.
You first need to find the Unique ID of the disk using the command
pi@kube-master:~ $ sudo blkid
Our SSD located in
/dev/sda has a unique ID
Edit the file
/etc/fstab and add the following line to configure auto-mount of the disk on startup.
pi@kube-master:~ $ sudo vi /etc/fstab
Add this line at the end:
UUID=0ac98c2c-8c32-476b-9009-ffca123a2654 /mnt/ssd ext4 defaults 0 0
Reboot the system
pi@kube-master:~ $ sudo reboot
You can verify the disk is correctly mounted on startup with the following command:
pi@kube-master:~ $ df -ha /dev/sda
B. Share via NFS Server
We now gonna make the directory
/mnt/ssd of master accessible to other machines via NFS
1. Install the required dependencies
pi@kube-master:~ $ sudo apt-get install nfs-kernel-server -y
2. Configure the NFS server
Edit the file
/etc/exports and add the following line
pi@kube-master:~ $ sudo vi /etc/exports
3. Start the NFS Server
pi@kube-master:~ $ sudo exportfs -ra
====== Worker nodes only - Mount the NFS share ======
1. Install the necessary dependencies
pi@kube-worker1:~ $ sudo apt-get install nfs-common -y
2. Create the directory to mounty the NFS Share
Create the directory
/mnt/ssd and set the ownership to
pi@kube-worker1:~ $ sudo mkdir /mnt/ssd
3. Configure auto-mount of the NFS Share
In this step, we will edit
/etc/fstab to tell the OS to automatically mount the NFS share into the directory
/mnt/ssd when the machine starts.
pi@kube-worker1:~ $ sudo vi /etc/fstab
Add the following line where
192.168.0.22:/mnt/ssd is the IP of
kube-master and the NFS share path.
192.168.0.22:/mnt/ssd /mnt/ssd nfs rw 0 0
4. Reboot the system
pi@kube-worker1:~ $ sudo reboot
To conclude, we now have three secured, up-to-date and operational machines to build a Kubernetes cluster and easily self-host and maintain applications at home!
In the next chapter, we will see how to install Kubernetes with Rancher k3s on those three machines and deploy the necessary tools such as Package Manager (helm), Proxy and Load Balancer, Certificate Manager, etc. to safely and efficiently deploy our applications.