In this tutorial we will install one node kubernetes cluster using the k3s distribution on the raspberry pi 4.
Pre Checks
Ensure that cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
is in /boot/cmdline.txt
:
$ cat /boot/cmdline.txt
console=serial0,115200 console=tty1 root=PARTUUID=738a4d67-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
Install k3s
Install k3s with:
$ curl -sfL https://get.k3s.io | sh -
Once the installation is done, make the config readable by the pi user:
$ sudo chown pi:pi /etc/rancher/k3s/k3s.yaml
Interact with Kubernetes
Test your setup, to interact with kubernetes:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
rpi-06 Ready master 18h v1.18.2+k3s1
If you want to use the kubernetes outside the cluster, you need to replace the localhost ip in the kubecontext: /etc/rancher/k3s/k3s.yaml
:
$ cat /etc/rancher/k3s/k3s.yaml | sed "s/127.0.0.1/$(ifconfig eth0 | grep -w 'inet' | awk '{print $2}')/g" > /tmp/kubeconfig
Now outside the cluster copy the contents from the raspberry pi /tmp/kubeconfig
to ~/.kube/config
then run:
$ export KUBECONFIG=~/.kube/config
Then you will be able to access kubernetes outside the cluster.