Servercore is a dynamic cloud platform that has recently unveiled its servers in the vibrant city of Nairobi, Kenya. Intrigued by the enticing offer of a free coupon to experience their cloud resources, I couldn’t resist exploring the unique server specifications they boast, including the Raspberry Pi 4B servers.
Servercore:https://servercore.com/
In this guide we will go through the process of configuring a Raspberry Pi 4B on Servercore, evolving seamlessly into the creation of a robust Kubernetes cluster. Together, we’ll navigate the intricacies of configuring all the necessary elements, culminating in establishing a fully functional cluster.
For this setup, I will be using the K3s distro from Rancher labs since it is optimized for ARM servers and works super well with the Pi. You can also use other distro such as K0s fo the setup.
Prerequisites
- Account with Servercore
- Knowledge of Kubernetes and K3s
Provisioning the Raspberry Pi 4B
- On your main account page select Servers
- Filter the results by selecting MicroSD
3. Select Raspberry Pi 4B
Note: At the moment the Pi is only in Saint Petersburg.
4. Select the Ubuntu version
Note: You can also add your SSH keys
5. Click on Pay Now
6. View the provisioned Servers
7. Get the password by expounding more on the server and selecting the Operating System tab
Configure and Update the Pi 4B
These steps are to be done on both master and worker nodes
Update and upgrade
sudo apt update | sudo apt upgrade
Enable IP tables
sudo iptables -f
It is recommended to turn off ufw (uncomplicated firewall):
ufw disable
Install curl and other necessary tools:
sudo apt install curl unzip -y
Since you are using Ubuntu on Raspberry Pi4B, by default cgroup is not enabled and you have to enable it manually.
Note: It is not configured on /boot/cmdline.txt.
Configure cgroups
Move to boot/firmware
cd /boot/firmware
Edit the cmdline.txt folder
sudo nano /boot/firmware/cmdline.txt
Add the following cgroup setting 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 Master Node
Download and run the K3s script
curl -SL https://get.k3s.io | sh -
This will download and start k3s on the management node you can view this by checking if the nodes are running.
kubectl get nodes
Obtain and copy the join token to be used to join 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.
Check the Nodes
View if the nodes are joined.
kubect get nodes
The worker node is joined to the master node and we are ready to test our cluster by running an application on it.
Testing the cluster
Let us run an NGINX container to check if the cluster works well
kubectl create deployment nginx-deployment --image=nginx
View if the pods are running
kubectl get pods -o wide
We can see that the pod is running on the worker node. Let's now expose the application.
kubectl expose deployment nginx-deployment --port=80 --type=NodePort --name=nginx-service
Finally, let's port forward the application so that we can view it outside the cluster.
kubectl port-forward deployment/nginx-deployment 8080:80
We can view the application running in the browser
Conclusion
In this blog, we have been able to provision a Raspberry Pi 4B cluster running on Servercore and configure Kubernetes using K3s.
Original URL: https://overcast.blog/building-a-lightweight-kubernetes-cluster-raspberry-pi-4b-on-servercore-1a744fda9fcb