This article is retrieved from David Janes, link below.

https://faun.pub/single-node-kubernetes-on-a-raspberry-pi-cb93a4300305

Please note: your device must have at least 2GB of RAM to install Kubernetes and its dependencies.

The “magic” bit here is the Single Node part, most instructions are about creating multi-Node installations. It’s also worth noting that if you’re relatively new to Kubernetes, there’s a hell of a lot of configuration involved and lots of things that you might think are standard actually aren’t (e.g. Load Balancers).

The following online articles were used as references (plus hundreds of StackOverflow searches, you know how it works):

These notes are likely incomplete, as I can get my applications up and running but I’m having trouble port mapping and unfortunately I have to move on to other projects for a while.

Install Docker

curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh

Add a bridge (needed)

sudo ip link add name docker0 type bridge
sudo ip addr add dev docker0 172.17.0.1/16

Allow a normal user to run Docker (optional). Then reboot (logging in again is probably sufficient, but I’m weird this way)

sudo groupadd docker
sudo gpasswd -a $USER docker
sudo reboot

Install Kubernetes

Kubernetes will not work with swap enabled. Do this:

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove

Add cpu, memory into cgroup recouces (note this probably doesn’t want to be run multiple times).

orig="$(head -n1 /boot/cmdline.txt) cgroup_enable=cpuset cgroup_enable=memory"
echo $orig | sudo tee /boot/cmdline.txt
sudo reboot

The /boot/cmdline.txt will end up looking something like this:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=e6462c02–02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait cgroup_enable=cpuset cgroup_enable=memory

Install Kubernetes

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update -q

sudo apt-get install -qy kubeadm

This command is run only on the master, but since we’re only doing a single Node, this is OK.

sudo kubeadm init --token-ttl=0 --pod-network-cidr=10.244.0.0/16

There’s a bunch of stuff about clusters, but we’re not doing that. These instructions need to be followed:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

You have to install Flannel (not Weave, which never seemed to work) because Reasons (if you don’t the master node will stay NotReady)

sudo sysctl net.bridge.bridge-nf-call-iptables=1kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

At his point, it will look like it’s all up and running, but Kubernetes won’t let you run normal Pods on the Master Node. One command is needed:

kubectl taint nodes --all node-role.kubernetes.io/master-

And that’s it!

Leave a Reply

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