A tutorial on how to build Kubernetes cluster on Raspberry Pi can be found here. However, there were problems when I follow it, possibly because it is little outdated. The solutions can be found in the comments of that tutorial. This post is a summary of the solution.
Master setup
Change hostname using raspi-config utility.
Set a staic IP address. I use WiFi and didn't set static address. The ip addresses of nodes usually don't change after reboot if the router is the same one used before the reboot.
Install Docker
# remove old version docker sudo apt-get purge docker-ce docker-ce-cli containerd.io # export VERSION=17.03 && curl -sSL get.docker.com | sh && \ # sudo usermod pi -aG docker $ curl -sSL get.docker.com | sh && \ sudo usermod pi -aG docker
Turn off swap:
$ sudo dphys-swapfile swapoff && \ sudo dphys-swapfile uninstall && \ sudo update-rc.d dphys-swapfile remove
Edit /boot/cmdline.txt. Add the following line to the end of the line, but don't create any new lines:
cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1
Reboot
sudo reboot
Install kubectl and kubeadm
# the following command not working after updating the system # curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \ # echo "deb https://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 kubelet=1.9.7-00 kubectl=1.9.7-00 kubeadm=1.9.7-00 kubernetes-cni=0.6.0-00 --allow-downgrades # the following commands work $ 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
Initialize your master node
sudo kubeadm init --token-ttl=0 # --apiserver-advertise-address=192.168.0.100 --ignore-preflight-errors=ALL
Install weave 1.6
# kubectl apply -f https://git.io/weave-kube-1.6 kubectl apply -f \ "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
After the init is complete run the snippet:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
The above command outputs a toekn which will be used for nodes to join the master. save the token somewhere. The token will be expired after 24 hours.
Join other nodes:
Change hostname using raspi-config
Join the cluster:
$ sudo kubeadm join --token 1fd0d8.67e7083ed7ec08f3 192.168.0.27:6443
Check the nodes on the cluster:
$ kubectl get nodes