Kubernetes on pi script

Discover the world of IT

Kubernetes on pi script

In my previous post I made a guide, Kubernetes pi cluster which illustrated how one can setup Kubernetes on minimum two raspberry pi’s. However to prevent going though that post and all the steps manually every time a new raspberry pi is added to a cluster, I made a script to automate most of the process, all it needs is a few configurations and Kubernetes can run on your cluster.

The script for setting up Kubernetes can be found on Github were a small guide on how to use it is included. I made a fast forward video and a small stepwise guide as an complement to the video below that illustrates how I used it to setup two nodes in a very simple way and hopefully this will provide a little guidance on how to use it.

Simplified guide

Configure and Connect

Firstly flash the latest Raspberry pi OS to your SD Card.

GIF

Each of the SD Cards now have a boot partition, where the following code must be append to the cmdline.txt and an empty file named “ssh” file must be created.

cgroup_memory=1 cgroup_enable=memory
GIF

Once your pi’s are started fetch their IP addresses using an ip scanner, i knew mine was in the range of 140-165 to that’s what I changed default is 0-255.

GIF

Connect to your pi’s using ssh the default username and password for the raspberry pi OS is found below.

Username: pi
Password: raspberry

Script Configuration and Execution

Once a SSH connection to your pi is established enter download the script and make it executable using the following commands.

sudo curl -LO https://raw.githubusercontent.com/starchap/RaspberryPiKubernetesClusterScript/master/kube.sh

sudo curl -LO https://raw.githubusercontent.com/starchap/RaspberryPiKubernetesClusterScript/master/config.sh

sudo chmod +x ./kube.sh

Modify your configuration script so that each Pi get’s an unique hostname and a static IP address. You can skip the public key if you don not find it necessary, just make sure the configuration named “preventpass” is set to false in that case.

sudo nano config.sh

Now execute the script using the following command.

./kube.sh

Once the script is executed you are provided with 3 options.

1. Option adds a new user to the raspberry pi, using this command is a 2 step process you must enter a username and password thereafter login as that user and run the script again with option 1 will enable you to delete the default pi user.

2. Option adds a static IP address, hostname and applies a public key to the ssh connection if any is defined in the config.sh otherwise it skips the configuration of it. note that “preventpass” must be false when you do not use a public key otherwise leave it as true.

3. Option setup’s Kubernetes on the raspberry pi, either as a master or a worker, if you are configuring a working it is important to fill the Ip for the master node and the token it has to apply in order to connect.

the token can be found on the master node using the following command.

sudo cat /var/lib/rancher/k3s/server/node-token

You can see all your nodes using the following command on your master node

sudo kubectl get nodes

You can address a new node with a label using the following command

kubectl label node <NAME_OF_NODE> node-role.kubernetes.io/worker=worker

I hope this helps some of you guys out there that just want to get started with Kubernetes for a small home project, and don’t wanna use a lot of time on the setup process. Please leave a comment if this helped you out, it will much appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *