Lightweight Kubernetes Cluster on Raspberry Pi with Servercore

Lightweight Kubernetes Cluster on Raspberry Pi with Servercore

Servercore is a dynamic cloud platform that recently launched its servers in the vibrant city of Nairobi, Kenya. I was attracted by their free coupon offer to experience their cloud resources, so I couldn’t resist exploring their proud unique server specifications, including the Raspberry Pi 4B server.

Servercore: https://servercore.com/

In this guide, we will introduce how to configure the Raspberry Pi 4B on Servercore and smoothly create a powerful Kubernetes cluster. We will navigate the complexities of configuring all necessary elements together, ultimately establishing a fully functional cluster.
For this setup, I will use Rancher Labs’K3s distribution, as it is optimized for ARM servers and works exceptionally well with the Pi. You can also use other distributions likeK0s for the setup.

Prerequisites

1. Have a Servercore account
2. Understand Kubernetes and K3s

Configuring Raspberry Pi 4B

1. Select “Servers” on your main account page
2. Filter results by selecting “MicroSD”
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
3. Select “Raspberry Pi 4B”
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
Note: Currently, the Pi is only available in Saint Petersburg.
4. Select the Ubuntu version
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
Note: You can also add your SSH key
5. Click “Pay Now”
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
6. View the configured server
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
7. Get the password by drilling down into the server and selecting the “Operating System” tab
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore

Configuring and Updating Pi 4B

The following steps need to be performed on both the master node and worker nodes
Update and upgrade
sudo apt update && sudo apt upgrade
Enable IP tables
sudo iptables -f
It is recommended to disable ufw (uncomplicated firewall):
ufw disable
Install curl and other necessary tools:
sudo apt install curl unzip -y
Since you are using Ubuntu on Raspberry Pi 4B, cgroup is not enabled by default, and you need to enable it manually.
Note: It is not configured in /boot/cmdline.txt.

Configuring cgroup

Move to /boot/firmware
cd /boot/firmware
Edit the cmdline.txt folder
sudo nano /boot/firmware/cmdline.txt
Add the following cgroup settings at the end of the line
cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
Reboot the Raspberry Pi node
sudo reboot

Installing K3s on the Master Node

Download and run the K3s script
curl -SL https://get.k3s.io | sh -
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
This will download and start k3s on the management node; you can check by verifying if the nodes are running.
kubectl get nodes
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
Obtain and copy the join token used to connect the two nodes
sudo cat /var/lib/rancher/k3s/server/node-token

Worker Node

Install k3s and join it to the master node
curl -sfL https://get.k3s.io | K3S_TOKEN="YOUR TOKEN" K3S_URL="https://[your server ip]:6643" K3S_NODE_NAME="servername" sh -
This will download the K3s binary and join it to the master node.

Checking Nodes

Check if the nodes have joined.
kubectl get nodes
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
The worker node has joined the master node, and we are ready to test our cluster by running an application on the cluster.

Testing the Cluster

Let’s run an NGINX container to check if the cluster is running well
kubectl create deployment nginx-deployment --image=nginx
Check if the Pod is running
kubectl get pods -o wide
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
We can see that the Pod is running on the worker node. Now let’s expose the application.
kubectl expose deployment nginx-deployment --port=80 --type=NodePort --name=nginx-service

Lightweight Kubernetes Cluster on Raspberry Pi with Servercore

Finally, let’s port-forward the application so we can view it externally from the cluster.
kubectl port-forward deployment/nginx-deployment 8080:80
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
We can view the running application in the browser
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore

Conclusion

In this blog, we successfully configured a Raspberry Pi 4B cluster on Servercore and set up Kubernetes using K3s.

If you want to inquire about Raspberry Pi standard products and industrial products, feel free to contact us~

1. Scan the QR code to add Engineer Yang for consultation.

Lightweight Kubernetes Cluster on Raspberry Pi with Servercore

2. Send us your contact information via private message, and we will get back to you as soon as possible.
3. Official website of Raspberry Pi distributor Shanghai Jingheng: https://www.edatec.cn/cn
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore
1
Lightweight Kubernetes Cluster on Raspberry Pi with Servercore

We will update regularly~

Follow Raspberry Pi developers~

Learn more about Raspberry Pi related content~

Leave a Comment