A recent project required me to setup Kubernetes, learn the basics and also gets the hand dirty around experimenting. I looked into many options, google cloud, AWS, Katacoda, minikube, setting up a cluster on virtual machines. The cloud option did not provide the flexibility in free version also i didn’t own a credit card. While trying to setup on virtual machines i always messed up the networking between the machines and the cluster would never work fine. So scouting the internet i came across clusters build on raspberry-Pi. The whole project was quite appealing and also provided the flexibility of bare metal installation. This is how it was done.

The initial setup.

At least 2 Raspberry-pi 3 or upper version with flashed memory card and Linux running on them.

A WiFi router, or create a mobile host-spot using your phone or laptop.

USB cables to power the Raspberry-pi.

Bringing all devices on same network.

You need to bring all the pi’s and your laptop from where you want to monitor on same network. If you have created the hot-spot using your laptop then no issues or else connect your laptop to WiFi. To connect you pi boards to a WiFi network you need to edit the Wpa supplicant file. How read here( link ).

Check the IP address of all connected pi’s using fing or settings page of hot-spot and ssh into all the the pi’s.

Now we need to install docker on all pi’s

Installing Docker.

curl -sSL get.docker.com | sh && \

sudo usermod pi -aG docker && \

newgrp docker

Disable swap , for kubernetes to function properly you need to disable swap.

sudo dphys-swapfile swapoff && \

sudo dphys-swapfile uninstall && \

sudo update-rc.d dphys-swapfile remove

Setting-up static IP and hostname

Type sudo raspi-config in the pi sshed terminal. Go to Network>Hostname and then change the hostname to master, worker1, woker2 etc.

To setup static ip adress sudo vim etc/dhcpcd.config edit it to

interface wlan0

static ip_address=192.168.11.13

static routers=192.168.11.1

static domain_name_servers=8.8.8.8

Where 192.168.11.3 is the IP you want to give to the device. Also check the IP series your router is assigning using fing. Now reboot using sudo reboot.

The c-group and key setup.

This needs to be done for kubernetes installation and c-group permissions to work fine.

Add this to the end of file /boot/cmdline.txt

cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory

Add it in the last line of all other text not a new line or file. Now reboot.

Now we need to add kuberenetes dpg key and deb path for apt to install kubernetes, add this to the file /etc/apt/sources.list.d/kubernetes.list

deb http://apt.kubernetes.io/ kubernetes-xenial main

Now to add the key use curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

You will get OK if it worked fine

Installing Kubeadm

Now update sudo apt-get update

Install kubeadm sudo apt-get install -qy kubeadm

Master Node Setup

Above this all things need to be done on all nodes. Now we need to setup a networking on master i am using weave. I have tried flannel and calico but weave works the best for me.

Now you have come this far.. be patient an follow the further steps the final product will be highly rewarding. The further steps are easy.

Pull images sudo kubeadm config images pull -v3 Prevent token expiration, do not use in production sudo kubeadm init — token-ttl=0 Now run sudo kubeadm init

This might throw an error or warning, if swap is not off do sudo swapoff -a and a kubeadm reset do this reset and init untill you get an output similar to

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

Along with this you will also see a join token.

kubeadm join 192.168.137.35:6443 --token 8deg59.wxl8sp6wwrokpcfl \

--discovery-token-ca-cert-hash sha256:9731b2a1516c0c83a75d684b75db1c72ecbc94174a2b62522ab79b442ef15455

4. Now we setup weave network, install weave network driver.

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '

')"

5. Do a kubectl get pods --all-namespaces to get all running pods.

insert pod image