How to Build a Kubernetes Server on a Raspberry Pi cluster Part 1
This blog will serve as a tutorial and guide for the minimum requirements a user would need to host in the Arena platform or with a Kubernetes cluster.
Use Case Overview:
Some of the benefits of having a home server is that you can host small applications, create smart home applications, and even websites, but it’s important to ensure that you have a high upload speed to do that. Additionally, you may want to avoid the costs of using a cloud provider by using a home server. I know I’m guilty of forgetting to delete an instance and racking up quite the bill. In my case, I’m building a home server so I can practice not only my IT, but also my CloudOps skills. And the best part, I can destroy and create as much as my server can handle without worrying about the monthly cost.
If you ever watched the movie Flubber with Robin Williams, you know the movie starts with this opening scene where this rube-goldberg-like machine makes his breakfast every morning. When I was a kid I thought that was absolutely crazy, and when I grew up, I wanted something like that too. Well, I’ve grown up, and now, I want to fulfill my childhood dreams. I eventually will need to get a 3D printer, but we’ll save that for a future post.
I have a goal to create an environment so that when I have children, they will be able to engineer and create whatever they dream of. Having this server is a start to it and I welcome you to follow this engineering journey.
List of Requirements:
3 x Raspberry Pi 4 Model B 8GB | $82.84 | Find Here |
2 x Cluster Case for Raspberry Pi(with fans)*| $11.27 | Find Here |
3 x Micro SD Cards 128Gb* | $21.79 | Find Here |
3 x Mini PoE Expansion HAT | $27.79 | Find Here |
1 x USB keyboard*
1 x HDMI to microHDMI cable*| $3.38 | Find Here
3 x Ethernet Cat6 cords* | $1.69 | Find Here | #EthernetCables.jpg
1 x TP-Link AC1900 Smart WiFi Router| $59.99 | Find Here |
1 x TP-link 5-Port Gigabit PoE Switch | $42.89 | Find Here |*optionalTotal cost may vary depending on the optional choices you make on this build*Shipping prices are not included*Total: $556.48Having a home server to automate breakfast: Eggcellent
Building the Raspberry Pi Cluster:
You’re gonna want to start with building the cluster case. The build should take 30 mins.
WARNING: DO NOT BUILD OVER A CARPET.
These bolts are tiny! This warning was in every tutorial I followed. Unfortunately for me, I ignored the documentation and ended up taking a comb to my carpet as if I were one of the troopers in “Spaceballs” combing the desert.
You can follow along with the provided pictures to assemble the ClusterCase with Pi’s.
You’re gonna want to make sure the round nuts are on top and not the bottom so the case does not slide around.
Add the first pi to the glass stand.
Add the new glass level, but this time, include the fan and attach it to the pi.
Once you have the new level and have added it to the case, finish by attaching another raspberry pi to the case and the top level with the attached fan.
Once the case and Pis are set up, we move to the next step by installing the operating system. In this blog, we will be using Ubuntu.
First, you will want to download the Raspberry Pi Imager; you can go can use one of the following to do so:
- Go to ubuntu and use this link to follow their instructions Download one of the following:
- Raspberry Pi Imager for Ubuntu
- Raspberry Pi Imager for Windows
- Raspberry Pi Imager for macOS
- Use:
$ sudo snap install rpi-imager
Reserving Static Addresses:
Before we address the raspberry pi’s, you will need to set up the router and PoE switchboard to utilize the PoE HATS. If you don’t want to use the HATS use the power supply plugs. Plugin the router to your ISP router that is already connected to the internet, find the connection and connect to it. The next step is to go to the address http://tplinkwifi.net and create a new login to sign in. You can skip the quick setup and go to the console where you will find the advanced settings and the network tab where we will do most of the editing.
To start, let’s first configure the LAN.
LANIp Address: 10.204.4.1SubnetMask: 255.255.255.0
Next, if you go to the Internet tab, you will see a drop-down for the Internet Connection Type and choose Dynamic IP. Since you have connected the router to your ISP router, it dynamically sets the parameters requested.
With that step done, we will now focus on the DHCP server. Make sure that the DHCP server is enabled and the Raspberry Pis are on and connected to the switchboard connected to the router. By doing so, the router will automatically identify the Raspberry Pis and they will be visible on the DHCP Client List. Note the MAC address as you will need that later to set the static IP addresses for the Pi’s. You can use this as an example of how it should look.
Once completed, you can check the internet connection by going to any website and making sure it loads.
Now, to set the static IP addresses, the Address Reservation section on the page is where we will assign the IP address of the RaspberryPis:
Device Name| Mac Address| Reserved Ip Address|Kube-master| R7–3J-95–8H-KL-Y2| 10.204.4.101|Kube-worker-1| R7–3J-95–9U-T4-X1| 10.204.4.100|
Setting up the Pi Kernel:
Once you install the OS to the correct SD card, transfer them to the pi’s and plug in the power supply, micro HDMI, and keyboard. Give it 2 to 3 mins to load, but when you see the insert username, wait until it has more scripts run. If you were able to set a static IP address, another way you can access the Pi’s is by adding the SSH into them from your local computer.
$ ssh ubuntu@10.204.4.100
Once that is finished, you can use these credentials:
Username: ubuntuPassword: ubuntu
Once logged in, you will be prompted to change your password. Use any password of your choosing.
Once you have officially logged into your raspberry pi, we will start running it.
$ sudo dhclient eth0
The next step would be to determine the IP address of the Raspberry Pi’s so you can SSH into them later.
On Ubuntu, you can run:
$ arp -na | grep -i “b8”
Note, if you don’t have arp installed, you can run:
$ sudo apt install net-tools
You can now SSH into that board from any terminal.
Open a terminal and run:
$ ssh ubuntu@<RASBERRYPI-IP-ADDRESS>
Confirm you want to connect.
You will have officially connected to the Pi when the connection is confirmed. You can now add your SSH key if you want to save time for future SSH attempts:
Now, you will need to enable cgroups limit support. You will want to add these to the /boot/firmware/cmdline.txt file
Run the following command:
$ sudo vim /boot/firmware/cmdline.txt
Then add the following to the file:
cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1
After doing so you will need to restart the kernel for the changes to take effect, so run the following:
$ sudo reboot
Make sure you follow the same steps for each board as they all need to be running an Ubuntu Server image.
Now if you’re like me and have recently gotten their CKA, you want to flex those muscles and utilize everything Kubernetes offers. With that in mind, I’ll be using Kubeadm to set up the clusters and for the second part of the tutorial I will be creating & installing the infrastructure to host Arena Concourse, something I’ll be making a tutorial later in the year.
*In the next tutorial I will also add a factor of any new additional costs for any of the new infrastructure based on energy costs.
Before we start installing kubernetes we will need a Docker engine to do so. I’ll catch you in part 2.