Install Kubernetes on Focal

Disable swap

systemctl disable swap.img.swap --now
sed -e '/swap/ s/^#*/#/' -i /etc/fstab
rm /swap.img

Set some sysctl’s

cat << EOF > /etc/modules-load.d/containerd.conf
modprobe overlay
modprobe br_netfilter
cat << EOF > /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl --system

Add containerd and k8s repos, install packages

echo "deb [arch=amd64] kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
echo "deb [arch=amd64] focal stable" > /etc/apt/sources.list.d/docker.list
curl -fsSL | apt-key add -
curl -fsSL | apt-key add -
apt-get update && apt-get -y install kubelet kubeadm kubectl && apt-mark hold kubelet kubeadm kubectl
containerd config default > /etc/containerd/config.toml
sed -i s'/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
systemctl restart containerd

Install Kubernetes control plane

For a single master:

kubeadm init --pod-network-cidr=

For multi-master:

kubeadm init --pod-network-cidr= --control-plane-endpoint "k8s-lb:6443" --upload-certs

Make a note of the output for joining other nodes to the cluster

Copy the kubeadmin config

mkdir ~/.kube
cp /etc/kubernetes/admin.conf ~/.kube/config

Install network plugin

kubectl apply -f

Join other nodes

Control plane nodes:

kubeadm join <LoadBalancer IP>:6443 \
    --token <token> \
    --discovery-token-ca-cert-hash sha256:<hash> \
    --control-plane \
    --certificate-key <key>

Worker nodes:

kubeadm join <Master Node IP>:6443 \
    --token <token> \
    --discovery-token-ca-cert-hash sha256:<hash>