How to install Kubernetes cluster on Raspberry PI

How to install Kubernetes cluster on Raspberry PI

Kubernetes

Kubernetes, as it's self defined, is an open-source system for automating deployment, scaling, and management of containerized applications.

Event though it has been used for orchestration (optional) nowadays is required by several applications as requirement.

In this lab, we'll use microk8s, which is a powerful, lightweight, reliable production-ready Kubernetes distribution and which requires a small amount of memory and disk. So it's perfect for us.

Raspberry PI

Raspberry PI in the other hand are small single-board computers, which allow us to use their own Debian fork, or other OS, like Ubuntu. In this lab we'll use the latest Ubuntu Desktop 64bit. On this lab we'll use the Raspberry PI 4B, and even when it's possible to use the 2GB RAM option, I totally recommend to use the 4GB RAM.

To setup Raspberry PI for Kubernetes

In order to setup the Raspberry PI to run Kubernetes, you need to assemble it and install the OS and do some minor adjustments. This is covered in this other post to facilitate the reading of this post.


Install MicroK8s

To start we need to enable c-groups, so you will modify the cmdline.txt

sudo vi /boot/firmware/cmdline.txt

or

sudo nano /boot/firmware/cmdline.txt

and add the following at the start of the line:

cgroup_enable=memory cgroup_memory=1

save the file and reboot:

sudo reboot

Once done, install MicroK8s snap:

sudo snap install microk8s --classic

and that's it. You can know more details about the microk8s installed by running:

snap info microk8s


Kubernetes cluster

Adding nodes

To setup the kubernetes cluster, you need to manage the master node and the leaf node(s).

Master node

On the master run the following:

sudo microk8s.add-node

This will return you a command with the token to run on the leaf node

Leaf node

Now on the leaf node you need to run the command you got above, adding the sudo

microk8s.join <master_ip>:<port>/<token>

for example:

microk8s.join 192.168.0.12:25000/eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFt

It might take up to a couple of minutes. When completed you can get the list of nodes from the master:

microk8s.kubectl get node

You can repeat the steps above on the master and leaf, to add more nodes


Removing a node

If you want to remove some node from the cluster, do the following

On the master run the remove-node, by using the <node-name> listed with the "get node" command above:

sudo microk8s remove-node <node name>

and although that's it, you have removed the node from the cluster, if you want to reconnect the same leaf node to the cluster you will need to disconnect the leaf node before adding it back again. So run it in the leaf node:

sudo microk8s.leave


What's next

Now you can add more nodes to the cluster and extend it. I will publish a new post with some demos of kubernetes usage.

That's it. Enjoy your Kubernetes cluster !


Comentarios

Entradas más populares de este blog

To setup Raspberry PI for Kubernetes