There are plenty of websites where Kubernetes is explained, why how etc, if you want to know more or if you’re just curious I suggest you head over there : Kubernetes
If you want to do the same, you will need
- 2 Raspberry Pi at least
- and that’s it
I won’t detail the Raspberry installation and configuration, we will use Raspbian 64bit lite up to date and accessing it through SSH
Install Kubernetes cluster
Here we go
first we need to edit the cmdline.txt file
sudo nano /boot/cmdline.txt
and add cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 at the end of the first line
Save the file and close then reboot the Pi
Once backup, just run this command on your chosen master Pi :
curl -sfL https://get.k3s.io | sh -
you should see something similar :
[INFO] Finding release for channel stable
[INFO] Using v1.22.5+k3s1 as release
[INFO] Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.22.5+k3s1/sha256sum-arm64.txt
[INFO] Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.22.5+k3s1/k3s-arm64
[INFO] Verifying binary download
[INFO] Installing k3s to /usr/local/bin/k3s
[INFO] Skipping installation of SELinux RPM
[INFO] Creating /usr/local/bin/kubectl symlink to k3s
[INFO] Creating /usr/local/bin/crictl symlink to k3s
[INFO] Creating /usr/local/bin/ctr symlink to k3s
[INFO] Creating killall script /usr/local/bin/k3s-killall.sh
[INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s.service
[INFO] systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO] systemd: Starting k3s
that’s it, you’re up and running !
If you want to check what’s going on you can run the following command :
kubectl get pods -A
which will give you something similar
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system metrics-server-9cf544f65-46hln 1/1 Running 0 2m43s
kube-system local-path-provisioner-64ffb68fd-7smmx 1/1 Running 0 2m43s
kube-system coredns-85cb69466-kq98w 1/1 Running 0 2m43s
kube-system helm-install-traefik-crd--1-cr9mz 0/1 Completed 0 2m43s
kube-system helm-install-traefik--1-x7b8m 0/1 Completed 2 2m43s
kube-system svclb-traefik-m8r4h 2/2 Running 0 82s
kube-system traefik-786ff64748-djb2b 1/1 Running 0 82s
Add node to the cluster
Now we need to add node to the existing cluster. Before that we need to get the token to identify the primary master of the universe node by running this command on the Pi where K3S is running :
sudo cat /var/lib/rancher/k3s/server/token
you’ll get a token that we will use to add node to the cluster, this token looks like that :
K10ac054c3c9514d6f2baa5e4bf59b04df0cc4be73fde287141002e6638ea1a42df::server:cb2a8de367271765289249805bffd662
curl -sfL https://get.k3s.io | K3S_URL=https://yourPiMasterIPAddress:6443 K3S_TOKEN=yourToken sh -
If you want to name your node you can also add KS3_NAME=NameOfyourNodeInTheCluster in this command line
You should see something like that :
[INFO] Finding release for channel stable
[INFO] Using v1.22.5+k3s1 as release
[INFO] Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.22.5+k3s1/sha256sum-arm64.txt
[INFO] Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.22.5+k3s1/k3s-arm64
[INFO] Verifying binary download
[INFO] Installing k3s to /usr/local/bin/k3s
[INFO] Skipping installation of SELinux RPM
[INFO] Creating /usr/local/bin/kubectl symlink to k3s
[INFO] Creating /usr/local/bin/crictl symlink to k3s
[INFO] Creating /usr/local/bin/ctr symlink to k3s
[INFO] Creating killall script /usr/local/bin/k3s-killall.sh
[INFO] Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh
[INFO] env: Creating environment file /etc/systemd/system/k3s-agent.service.env
[INFO] systemd: Creating service file /etc/systemd/system/k3s-agent.service
[INFO] systemd: Enabling k3s-agent unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s-agent.service → /etc/systemd/system/k3s-agent.service.
[INFO] systemd: Starting k3s-agent
To check if all nodes are online you can verify by using this command lin :
sudo kubectl get nodes -o wide
and you should see :
NAME STATUS ROLES AGE VERSION
rpi4-cl1 Ready control-plane,master 7m13s v1.22.5+k3s1
rpi4-cl3 Ready <none> 9s v1.22.5+k3s1
rpi4-cl2 Ready <none> 35s v1.22.5+k3s1
Which means you’re all good 🙂
- rpi4-cl1 is the master
- rpi4-cl2 is a node
- rpi4-cl3 is a node
Next steps would be to understand why kubernetes is a technology that can bring something to certain use cases