Kubernetes /K8s

Kubernetes (also known as "K8s") is an open-source platform for automating the deployment, scaling, and management of containerized applications. Containerized applications are packages of software that include all of the necessary code and dependencies required to run, which makes them easy to deploy and run consistently across different environments.

Kubernetes was designed to help developers and operations teams manage and scale containerized applications by providing a set of tools and APIs for deploying, managing, and scaling applications. It can run on top of various infrastructure platforms, such as bare metal servers, virtual machines, and public cloud providers.

Some of the key features of Kubernetes include:

Overall, Kubernetes is a powerful platform that can help developers and operations teams manage and scale containerized applications more effectively.




SD CARDS

To start let's use the Buster lite image from the Raspberry Pi Foundation 

Flash Buster lite to the micro sd cards. 

This is documented in many places the oficial guide is here https://www.raspberrypi.org/documentation/installation/installing-images/README.md

 

DOCKER

We need a container runtime interface

This is how we installed Docker (Buster Lite 2020-02-05-raspbian-buster-lite)

   curl -fSLs https://get.docker.com |sudo sh 


We want to use docker as a non root user

sudo usermod -aG docker pi


KUBEADM

Install kubeadm all nodes

We need the legacy binaries 

sudo apt install -y iptables arptables ebtables


After installing the legacy binaries we need to switch to them 

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy

sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

sudo update-alternatives --set arptables /usr/sbin/arptables-legacy

sudo update-alternatives --set ebtables /usr/sbin/ebtables-legacy


We will need curl and apt-transport-https  (enable deb https lines in sources file)

sudo apt install -y apt-transport-https curl


Now we setup the kuberneties repo

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

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list

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

EOF

sudo apt update && sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

sudo kubeadm config images pull


Master Node 

On the Master node only lets initiate K8s

sudo kubeadm init --pod-network-cidr=10.200.0.0/16

If you want a user other than root you need to give that user permissions 

mkdir -p $HOME/.kube

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

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


Install Flannel

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml



WORKER NODES

When you init the last few lines will be similar to the following 


You can now join any number of machines by running the following on each node

as root:

 kubeadm join 10.200.0.64:6443 --token <mytoken> --discovery-token-ca-cert-hash sha256:<myhash>


Verify that your node has joined by issuing the following command on the master 

kubectl get nodes


The output will look something like the following 


NAME       STATUS   ROLES    AGE     VERSION

11e9d2ef   Ready    <none>   19h     v1.17.3

2ebc89ea   Ready    <none>   22h     v1.17.3

31b81f1b   Ready    <none>   3h33m   v1.17.3

3386756e   Ready    master   23h     v1.17.3

33e9bb39   Ready    <none>   3h30m   v1.17.3

47227a70   Ready    <none>   22h     v1.17.3

77ab07f5   Ready    <none>   3h57m   v1.17.3

9fc14109   Ready    <none>   19h     v1.17.3

b837e9ca   Ready    <none>   4h9m    v1.17.3




kubectl get all -n kube-system


I have decided to go a different route than k8s, It has too much overhead for the pi's to run efficiently.  


References 

Raspberry Pi foundation Buster Lite 

https://www.raspberrypi.org/downloads/raspbian/


Kubernetes documentation: 

https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/


Alex Ellis : Docker on Buster Lite 

https://blog.alexellis.io/how-to-fix-docker-for-raspbian-buster/