MicroK8s

Documentation about running a MicroK8s cluster

Node

Node

Hardware

There are a couple of considerations when choosing your hardware or virtual "hardware" for use as Kubernetes nodes.

Node

Operating system

This guide focuses on Fedora Server but should be applicable to many distributions with minor tweaks. CentOS or Ubuntu Server or would also work just as well.

Snap

Snap is a package manager that contains MicroK8s. It comes preinstalled on Ubuntu, but if you're on CentOS, Fedora or others, you'll need to install it on all your nodes: https://snapcraft.io/docs/installing-snap-on-centos

sudo dnf -y install epel-release
sudo dnf -y install snapd
sudo systemctl enable --now snapd
sudo ln -s /var/lib/snapd/snap /snap
Node

MicroK8s

MicroK8s is a lightweight, pre-packaged Kubernetes distribution which is easy to use and works well for small deployments.

Install

Install MicroK8s 1.19.1 or greater from Snap on all your nodes. https://microk8s.io/

# To install
sudo snap install microk8s --classic --channel=1.22/stable

# Or to upgrade
sudo snap refresh microk8s --classic --channel=1.22/stable

sudo usermod -a -G microk8s jonathan
sudo chown -f -R jonathan ~/.kube
microk8s status --wait-ready

Cluster

Enable microk8s HA mode on all nodes, which allows any of the worker nodes to also behave as a master, instead of just being a worker node. This must be enabled before nodes are joined to the master. https://microk8s.io/docs/high-availability

microk8s enable ha-cluster

Enable microk8s clustering, which allows you to add multiple worker nodes to your existing master node https://microk8s.io/docs/clustering

On the first node:

[jonathan@kube01 ~]$ microk8s add-node
From the node you wish to join to this cluster, run the following:
microk8s join 192.168.0.41:25000/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Then execute the join command on the other nodes, to join them to the master. Verify that they are correctly joined:

[jonathan@kube01 ~]$ microk8s kubectl get nodes
NAME                         STATUS   ROLES    AGE     VERSION
kube02.jonathangazeley.com   Ready    <none>   27m     v1.18.8-33+c9c9e3f85f05f9
kube01.jonathangazeley.com   Ready    <none>   6d16h   v1.18.8-33+c9c9e3f85f05f9
kube03.jonathangazeley.com   Ready    <none>   86s     v1.18.8-33+c9c9e3f85f05f9

Finally make sure that full HA mode is enabled:

[jonathan@kube01 ~]$ microk8s status
microk8s is running
high-availability: yes
  datastore master nodes: 192.168.0.41:19001 192.168.0.42:19001 192.168.0.43:19001
  datastore standby nodes: none
addons:
  enabled:
...

We've already checked that all 3 nodes are up. Now let's make sure pods are being scheduled on all nodes:

[jonathan@kube01 ~]$ kubectl get pods --all-namespaces -o wide
NAMESPACE     NAME                                                READY   STATUS              RESTARTS   AGE    IP             NODE                      
kube-system   calico-node-bqqqd                                   1/1     Running             0          112m   192.168.0.41   kube01.jonathangazeley.com
kube-system   calico-node-z4sxd                                   1/1     Running             0          110m   192.168.0.43   kube03.jonathangazeley.com
kube-system   calico-kube-controllers-847c8c99d-4qblz             1/1     Running             0          115m   10.1.58.1      kube01.jonathangazeley.com
kube-system   coredns-86f78bb79c-t2sgt                            1/1     Running             0          109m   10.1.111.65    kube02.jonathangazeley.com
kube-system   calico-node-t5skc                                   1/1     Running             0          111m   192.168.0.42   kube02.jonathangazeley.com
Node

Networking

Firewall

Create firewall rules for your nodes, so they can communicate with each other. Refer to the ports guide https://microk8s.io/docs/ports

sudo firewall-cmd --permanent --add-port=6443/tcp			# Kube API server
sudo firewall-cmd --permanent --add-port=2379-2380/tcp		# etcd
sudo firewall-cmd --permanent --add-port=10250/tcp			# kubelet
sudo firewall-cmd --permanent --add-port=10251/tcp			# kube-scheduler
sudo firewall-cmd --permanent --add-port=10252/tcp			# kube-controller-manager
sudo firewall-cmd --permanent --add-port=10255/tcp
sudo firewall-cmd --permanent --add-port=25000/tcp			# microk8s cluster
sudo firewall-cmd --permanent --add-port=19001/tcp
sudo firewall-cmd --permanent --add-port=4789/udp			# Calico with VXLAN 
sudo firewall-cmd --permanent --add-port=5473/tcp			# Calico with Typha
sudo firewall-cmd --permanent --add-port={8285,8472}/udp	# Flannel
sudo firewall-cmd --add-masquerade --permanent
sudo firewall-cmd --zone=trusted --add-interface=vxlan.calico --permanent
sudo firewall-cmd --permanent --add-port=30000-32767/tcp	# NodePorts on control plane IP
sudo firewall-cmd --reload

Or the cheat way:

# Fedora
sudo systemctl disable --now firewalld

# Ubuntu
sudo ufw disable

Cluster

Cluster config and services

Storage

How to configure storage backends for persistent data