Building a Kubernetes 1.23 Cluster with Kubeadm
Published: 2022-04-06 16:33:21




Log into the Control Plane Node (Note: The following steps must be performed on all 


1. __Create configuration file for containerd:__

cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
2. __Load modules:__
sudo modprobe overlay
sudo modprobe br_netfilter

Set system configurations for Kubernetes networking:
cat <<EOF | sudo tee /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
EOF

__Apply new settings:__

sudo sysctl --system

__Install containerd:__

sudo apt-get update && sudo apt-get install -y containerd

__Create default configuration file for containerd:__

sudo mkdir -p /etc/containerd

__Generate default containerd configuration and save to the newly created default file:__

sudo containerd config default | sudo tee /etc/containerd/config.toml

__Restart containerd to ensure new configuration file usage:__

sudo systemctl restart containerd

__Verify that containerd is running.__

sudo systemctl status containerd

__Disable swap:__

sudo swapoff -a

__Disable swap on startup in /etc/fstab:__

sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

__Install dependency packages:__

sudo apt-get update && sudo apt-get install -y apt-transport-https curl

__Download and add GPG key:__

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

__Add Kubernetes to repository list:__

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

__Update package listings:__

sudo apt-get update

__Install Kubernetes packages (Note: If you get a dpkg lock message, just wait a minute or two before trying the command again):__

sudo apt-get install -y kubelet=1.23.0-00 kubeadm=1.23.0-00 kubectl=1.23.0-00

__Turn off automatic updates:__

sudo apt-mark hold kubelet kubeadm kubectl

Log into both Worker Nodes to perform previous steps.

3. __Initialize the Cluster__

Initialize the Kubernetes cluster on the control plane node using kubeadm (Note: This is only performed on the Control Plane Node):

sudo kubeadm init --pod-network-cidr 192.168.0.0/16 --kubernetes-version 1.23.0

__Set kubectl access:__

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

__Test access to cluster:__

kubectl get nodes

__Install the Calico Network Add-On__

On the Control Plane Node, install Calico Networking:
kubectl apply -f 
https://docs.projectcalico.org/manifests/calico.yaml

__Check status of the control plane node:__

kubectl get nodes

4. __Join the Worker Nodes to the Cluster__
In the Control Plane Node, create the token and copy the kubeadm join command (NOTE:The join command can also be found in the output from kubeadm init command):
kubeadm token create --print-join-command

In both Worker Nodes, paste the kubeadm join command to join the cluster. Use sudo to run it as root:

sudo kubeadm join ...

In the Control Plane Node, view cluster status (Note: You may have to wait a few moments to allow all nodes to become ready):
kubectl get nodes
`