Wednesday, May 27, 2020

Kubernetes on raspberry pi

There are quite a few articles (referenced at the bottom) which I used and here is the notes of my own installation.

The main difference is I do not want to interfere with the DHCP so I created a VLAN on the raspberry pi, so I can have the static IP and still be able to plug my pi into any network to get an IP address.

The other thing is I want to reduce the amount of devices on at the same time, so limiting to 1 node.

1. Install PI and setup networking.

I wanted to keep the DHCP and create a new VLAN for cluster communication so I can move the pi around without having to reconfigure the network.

$ sudo apt install vlan

add these lines to a new file /etc/network/interfaces.d/vlan

auto eth0.10
iface eth0.10 inet manual
  vlan-raw-device eth0


Add this to the end of the file /etc/dhcpcd.conf

interface eth0.10
static ip_address=10.0.10.1/24
static routers=10.0.10.1

As there are 2 hosts. change the IP addresses on the 2nd host.

interface eth0.10
static ip_address=10.0.10.2/24

Next to edit the hosts file on both servers so that each node can find each other

10.0.10.1 node1
10.0.10.2 node2



2. Install pre-requisites

  • Install Docker
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
$ sudo usermod -aG docker pi


  • Remove swapfile
$ sudo dphys-swapfile swapoff 
$ sudo dphys-swapfile uninstall
$ sudo update-rc.d dphys-swapfile remove
$ sudo systemctl disable dphys-swapfile.service



2. Install Kubernetes

$ sudo echo "deb http://apt.kubernetes.io/ kubernetes-xenial main"  | sudo tee /etc/apt/sources.list.d/kubernetes.list/etc/apt/sources.list.d/kubernetes.list
$ sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
$ sudo apt-get update
$ sudo apt-get install -y kubeadm


3. Configure Master

On the master node, e.g. node1

$ sudo kubeadm config images pull
$ sudo kubeadm init --token-ttl=0 --apiserver-advertise-address 10.0.10.1 --control-plane-endpoint node1 --node-name node1 --pod-network-cidr 10.1.10.0/24

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


4. Add additional nodes and test

login to node2

$ sudo sudo kubeadm join node1:6443 --token \
    --discovery-token-ca-cert-hash   \
    --apiserver-advertise-address 10.0.10.2 \
    --node-name node2 \
    --pod-network-cidr 10.1.10.0/24


$ mkdir -p $HOME/.kube
$ scp node1:/home/pi/.kube/config /home/pi/.kube/config


$ kubectl get nodes

NAME    STATUS     ROLES    AGE   VERSION
node1   NotReady   master   20h   v1.18.2
node2   Ready         20h   v1.18.2


5. Install a CNI and load balancer

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


  • MetalLB
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml
# On first install only
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"



6. Install Helm package manager 

$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm repo update

$ helm install bitnami/jenkins --generate-name



7. Enable this so that kubenetes starts after reboot.

$ sudo systemctl enable kubelet



No comments:

Splitting the home network

Who wouldn't want to separate the traffic at home for security reasons. The more common ones include wireless guest and wireless users. ...