Building a Kubernetes 1.21 Cluster with Kubeadm
Introduction
This lab will allow you to practice the process of building a new Kubernetes cluster. You will be given a set of Linux servers, and you will have the opportunity to turn these servers into a functioning Kubernetes cluster. This will help you build the skills necessary to create your own Kubernetes clusters in the real world.
Solution
Log in to the lab server using the credentials provided:
ssh cloud_user@<PUBLIC_IP_ADDRESS>
Install Packages
Log into the Control Plane Node (Note: The following steps must be performed on all three nodes.).
Create configuration file for containerd:
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf overlay br_netfilter EOFLoad modules:
sudo modprobe overlay sudo modprobe br_netfilterSet 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 EOFApply new settings:
sudo sysctl --systemInstall containerd:
sudo apt-get update && sudo apt-get install -y containerdCreate default configuration file for containerd:
sudo mkdir -p /etc/containerdGenerate default containerd configuration and save to the newly created default file:
sudo containerd config default | sudo tee /etc/containerd/config.tomlRestart containerd to ensure new configuration file usage:
sudo systemctl restart containerdVerify that containerd is running.
sudo systemctl status containerdDisable swap:
sudo swapoff -aDisable swap on startup in:
/etc/fstabsudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstabInstall dependency packages:
sudo apt-get update && sudo apt-get install -y apt-transport-https curlDownload 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 EOFUpdate package listings:
sudo apt-get updateInstall 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.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00Turn off automatic updates:
sudo apt-mark hold kubelet kubeadm kubectlLog into both Worker Nodes to perform previous steps.
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.21.0Set kubectl access:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/configTest 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.yamlCheck status of the control plane node:
kubectl get nodes
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 initcommand):kubeadm token create --print-join-commandIn 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