Building a Kubernetes 1.20v Cluster with kubeadm
Kubeadm is a tool that can be used to build a minimal viable Kubernetes Cluster of production grade.
Step 1: Install Packages
ssh into each node and create containerd configuration file by executing the below command. This command will instruct the node to load overlay and br_netfilter kernal modules.
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
We have to restart nodes to load them. Instead of restarting, run the below commands to load modules immediately
sudo modprobe overlay
sudo modprobe br_netfilter
Then set these 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 those settings by executing the below command
sudo sysctl --system
Now install containerd
sudo apt-get update && sudo apt-get install -y containerd
Inside the /etc folder, create a configuration file for containerd and generate the default configuration file
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
Now restart containerd to ensure new configuration file usage
sudo systemctl restart containerd
Kubernetes does require to disable swap memory, because the Kubernetes scheduler determines the best available node on which to deploy newly created pods. If memory swapping is allowed to occur on a host system, this can lead to performance and stability issues within Kubernetes. For this reason, Kubernetes requires that you disable swap in the host system.
sudo swapoff -a
To disable swap after server restart, in other terms, to persist the swap disable in the node, execute bellow command as well
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Now, let’s install dependency packages
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
Then download and add the GPG key
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Add Kubernetes to the 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 few minutes before trying the command again)
sudo apt-get install -y kubelet=1.20.1-00 kubeadm=1.20.1-00 kubectl=1.20.1-00
Turn off automatic updates
sudo apt-mark hold kubelet kubeadm kubectl
Initialize the Cluster
This only needs to perform on the control plane node only. (If you have multiple control plane nodes, do the same)
sudo kubeadm init --pod-network-cidr 192.168.0.0/16
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 version
Install Calico Network Add-On
Calico provides a simple, high-performance, secure networking. Calico is trusted by the major cloud providers, with EKS, AKS, GKE, and IKS all having integrated Calico as part of their offerings.
On the control plane node, install Calico networking
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Check the status of calico components
kubectl get pods -n kube-system
Join the worker nodes to the Cluster
In the control plane node, create the token and copy the kubeadm join command (The join command can also be found in the output from kubeadm init command)
kubeadm token create --print-join-command
In worker nodes, paste the kubeadm join command to join the cluster
sudo kubeadm join <join command from previous command>
Now you can view the cluster status in the control plane node
kubectl get nodes
Hope you learned something. Read upgrading Kubernetes cluster using Kubeadm form here.