Three Pis, One Network
Setting up a subnet with three Pis and a switch
This is the second article in my home lab series. The first article in the series, Three Pis, One Network, describes in detail how to set up a private network with 3 (or more) Raspberry Pis.
I chose Kubernetes (a.k.a. k8s) because most of my home lab experiments are container based and require minimal resources. There are two Kubernetes distributions of note, microk8s and k3s. K3s has been around for longer, with a bigger support community. Microk8s is a relatively new Canonical project with excellent documentation.
The diagram above describes role delegation for all the cluster nodes. The Router RPi will serve as the k8s master and the remaining two RPi hosts will serve as k8s leaf nodes. Microk8s is my Kubernetes distro of choice.
Kubernetes requires static IP addresses for each node in the cluster.
I edited /etc/dnsmasq.conf
and added the following lines.
The lines above bind each RPi’s MAC address to a static IP address.
Before installing MicroK8s I had to enable cgroups. I looked this up because my Linux kernel understanding is a bit rusty. Cgroups (Control Groups) are a kernel feature which allow processes to be organized into ordered groups whose resource usage can be monitored and managed. Kubernetes uses this feature to manage container resources in a pod.
As per the MicroK8s tutorial, I edited the file /boot/firmware/cmdline.txt
and added the following options:
After the edit, a reboot is required. I did this on all the Pis in my network.
Installing Microk8s is very straight forward. There’s a snap package available, all I needed to do was install it on each RPi in my network.
I executed the following commands on each RPi:
I read through this command reference to familiarize myself with the microk8s command line interface.
At the time of writing, Microk8s v1.20
was the latest stable release available. Prior to its release I tried out v1.19
and encountered a major issue while adding multiple nodes to the cluster. I have not encountered this issue with v1.20
.
Once microk8s is installed on all the Pis, I ran the following command on the Router RPi (designated master node):
The command above generates the following output:
I ssh'd
into one of the RPi nodes and ran the command:
I generated a new connection string and added the other RPi node to the cluster.
Back on the master node I ran the following command:
Which returns:
The cluster is on like the break of dawn.
Microk8s comes with a number of addons that you can use to enrich your Kubernetes cluster. The first addon I enabled was the Kubernetes dashboard. How else could I monitor my little pods?
I executed the following commands on my master node:
Executing the command kubectl cluster-info
now returns:
The Kubernetes dashboard has a secure token based login system. I’m not too concerned about security (the Kubernetes cluster is only accessible from my home network) so I disabled the login mechanism on the dashboard.
The edit should end up like this:
The dashboard was now accessible on the master node’s home network IP address:
Note: the login page still shows up but there’s a skip
button which allow you to bypass the login procedure.
Microk8s v1.20
ships with Prometheus.
I could now access the Prometheus dashboard on..
..and the Grafana dashboard on
The Grafana dashboard has a default username:password => admin:admin.
Besides the node connection issue I encountered with microk8s v1.19
, I did not encounter any other blockers while creating my k8s cluster.
The next article in this series will be about one of my favorite experiments!