Kubernetes was developed by google for orchestration of containers for docker and other such software. It will allow you to build/develop /scale/deploy containerized applications.

Kubernetes is an alternative to docker swarm and is suited for automation of most of the manual processes involved in deploying microservices/apps.

Our goal here is to get you to a point of understanding and knowledge of deploying kubernetes. We are going to use microK8s here on a raspberry pi4 with Ubuntu Server 21.04 installed as the os.

  • Deploy the OS on your Raspberry PI4
  • Pre-Configuration of the OS and Pi
  • Install microk8s on your pi.

1 - Burn the os with Raspberry Pi imager - Ubuntu Server 20.04.2/21.04
2 - Get IP of host # I use angry ip scanner
3 - create an ssh in the /boot of the drive (Only when using raspberry pi os) sudo touch /boot/ssh or /boot/firmware/ssh
4 - sudo nano -c /boot/firmware/cmdline.txt

note: Copy the following text into the /boot/firmware/cmdline.txt file (no line breaks & without the quotes) "cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1"

5 - ssh ubuntu@ip.of.server
6 - Change the ubuntu/pi user password - sudo passwd ubuntu/pi

change to static ip

7 - sudo nano -c /etc/netplan/50-cloud-init.yaml <- it could be 01- or 00- as well.

note: make sure you put your nic card and ip addresses in your config.

Set the proper timezone

8 - sudo timedatectl set-timezone America/New_York <- mine is EST U.S.

Change the hostname

9 - sudo nano -c /etc/hostname

Hosts IPs - Make sure the hosts are in here.

10 - sudo nano -c /etc/hosts

note: put your server name and ip in this file

xxx.xxx.xxx.xx0    kmaster.cfs.loc kmaster
xxx.xxx.xxx.xx1 knode1.cfs.loc knode1
xxx.xxx.xxx.xx2    knode2.cfs.loc knode2

Let's update the respositories & upgrade the system.

14 - sudo apt update
15 - sudo apt -y full-upgrade
16 - sudo reboot

We need to turn off swap for kubernetes

note: Having swap on allows system to use any resources it likes. swapoff -a will disable swap and give kubernetes all the resources available.

17 - sudo swapoff -a
18 - sudo ssh-keygen
19 - sudo ssh-copy-id ubuntu@ip.og.master/ip.of.worker

Install Kubernetes (master node)

20 - sudo snap install microk8s --classic --channel=1.21/stable
21 - sudo usermod -a -G microk8s
22 - sudo chown -f -R  ~/.kube
23 - sudo microk8s status
24 - sudo microk8s.add-node

Install Kubernetes on (worker node)

25 - sudo snap install microk8s --classic --channel=1.21 or .22/stable
26 - sudo microk8s status
27 - microk8s join

(Master Node)

28 - sudo microk8s.enable dashboard dns ingress storage helm3

If you are wanting to add a kubernetes endpoint to an existing install (Portainer) use the following command:

29 - curl -L https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; sudo microk8s.kubectl apply -f portainer-agent-k8s.yaml

Appendex:

note: STORAGE Alternative storage for NFS (Clusterwide) instead of openebs
a - sudo microk8s helm3 repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
b - sudo microk8s helm3 install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner
--set nfs.server=192.168.1.10
--set nfs.path=/export/extVol

note: Remove microk8s-hostpath as default storageclass
c - sudo microk8s kubectl patch storageclass microk8s-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
d - sudo microk8s kubectl get sc
e - sudo microk8s kubectl patch storageclass nfs-client -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
f - sudo microk8s kubectl get sc

That should do it you should be ready to enjoy kubernetes in a cluster format when done with this method.

Thanks for coming by.

I hope this has helped you understand the install of kubernetes on Ubuntu.