Kubernetes for Beginners
First steps in building a Kubernetes Cluster.
This is a follow up to my earlier post where I described how to install a stripped down Raspbian image on a set of 6 raspberry pi’s. In this post I want to describe what I finally ended up doing to get Kubernetes to run successfully on this cluster. So in the best traditions of TV cook shows, I will spare you the pain and the waiting and cut to what I ended up doing.
Installing Docker
First thing is to install Docker and thankfully it is very straightforward to install Docker. Docker needs iptables and buster messes with the defaults so first thing, switch the iptables to the legacy mode
sudo iptables -F
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
You will probably need to reboot at this point, but thankfully on a raspberry pi that takes about 10 seconds. Next let’s install docker and perform any post install config
curl -sSL https://get.docker.com | sh
sudo usermod -aG docker pi
You will need to log out and then log back in but at this point, once you have executed this on every node you will have docker installed and you are ready to move onto the fun part. Note if you just want to use docker and create a Docker Swarm, at this point you can stop and execute 1-2 commands and you have your own docker Swarm. I wanted to go to the next step and get Kubernetes to run.
Installing Kubernetes?
So after much effort I have discovered that installing and running Kubernetes in the k8s incarnation is a lesson in futility on a raspberry pi. The little raspberry pi’s that I have really do not have enough horsepower and memory and this results in frustrating timeouts, failed deployments and endless other pain that really detracts from the learning experience. Thankfully Rancher has developed a stripped down version of k8s called k3s that has a lot of the functionality including flannel network overlays and Traefik for building ingest rules all in a nice simple package
So given the purpose of this exercise, next install k3s on your master node (pi-proxy)
curl -sfL https://get.k3s.io | sh -
Once installed on the master node verify that it is up and running ( systemctl status k3s.service )before moving onto the next step.
On the master node get the token from /var/lib/rancher/k3s/server/node-token then on each of the other nodes in your pi-cluster install the agent, ensuring that it is using docker for it’s containers and also connect to the master node (pi-proxy in my case).
curl -sfL https://get.k3s.io|K3S_URL=https://pi-proxy:6443 K3S_TOKEN=<your token here> sh -s - --docker
Yes it is literally that simple, give it a minute or two then check that the nodes in the cluster are all up and running
pi@pi-proxy:~ $ k3s kubectl get nodes
NAME STATUS ROLES AGE VERSION
pi-proxy Ready master 3d1h v1.18.2+k3s1
pi-node1 Ready <none> 24h v1.18.2+k3s1
pi-node0 Ready <none> 24h v1.18.2+k3s1
pi-node3 Ready <none> 24h v1.18.2+k3s1
pi-node2 Ready <none> 24h v1.18.2+k3s1
pi-node4 Ready <none> 24h v1.18.2+k3s1
Congratulations you have a running and importantly stable Kubernetes cluster, in the next post I will start with some very simple first steps.
