Building a Kubernetes 1.27 Cluster with kubeadm
Install Packages
Control Pane Node
Create the configuration file for containerd:
cat << EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
Load the modules:
sudo modprobe overlay
sudo modprobe br_netfilterSet the 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 the new settings:
sudo sysctl --systemInstall containerd:
sudo apt-get update && sudo apt-get install -y containerd.ioCreate the default configuration file for containerd:
sudo mkdir -p /etc/containerdGenerate the default containerd configuration, and save it to the newly created default file:
sudo containerd config default | sudo tee /etc/containerd/config.tomlRestart containerd to ensure the new configuration file is used:
sudo systemctl restart containerdVerify that containerd is running:
sudo systemctl status containerd
Disable swap:
sudo swapoff -aInstall the dependency packages:
sudo apt-get update && sudo apt-get install -y apt-transport-https curlDownload 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
EOFUpdate the package listings:
sudo apt-get updateInstall Kubernetes packages:
Note: If you get a
dpkg lockmessage, just wait a minute or two before trying the command again.
sudo apt-get install -y kubelet=1.27.0-00 kubeadm=1.27.0-00 kubectl=1.27.0-00Turn off automatic updates:
sudo apt-mark hold kubelet kubeadm kubectl
Worker Node
Create the configuration file for containerd:
cat << EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
Load the modules:
sudo modprobe overlay
sudo modprobe br_netfilterSet the 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 the new settings:
sudo sysctl --systemInstall containerd:
sudo apt-get update && sudo apt-get install -y containerd.ioCreate the default configuration file for containerd:
sudo mkdir -p /etc/containerdGenerate the default containerd configuration, and save it to the newly created default file:
sudo containerd config default | sudo tee /etc/containerd/config.tomlRestart containerd to ensure the new configuration file is used:
sudo systemctl restart containerdVerify that containerd is running:
sudo systemctl status containerd
Disable swap:
sudo swapoff -aInstall the dependency packages:
sudo apt-get update && sudo apt-get install -y apt-transport-https curlDownload 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
EOFUpdate the package listings:
sudo apt-get updateInstall Kubernetes packages:
Note: If you get a
dpkg lockmessage, just wait a minute or two before trying the command again.
sudo apt-get install -y kubelet=1.27.0-00 kubeadm=1.27.0-00 kubectl=1.27.0-00Turn off automatic updates:
sudo apt-mark hold kubelet kubeadm kubectl
Initialize the Cluster
Control Pane Node
Initialize the Kubernetes cluster on the control plane node using kubeadm:
sudo kubeadm init --pod-network-cidr 192.168.0.0/16 --kubernetes-version 1.27.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 the cluster:
kubectl get nodes
Install the Calico Network Add-On
Control Pane Node
On the control plane node, install Calico Networking:
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yamlCheck the status of the control plane node:
kubectl get nodes
Join the Worker Nodes to the Cluster
Control Pane Node
In the control plane node, create the token and copy the kubeadm join command:
kubeadm token create --print-join-command
Worker Node
You can just copy the output from the previous command on the Control Pane Node but add sudo first and it will look similar to this:
kubeadm join 10.0.1.101:6443 --token $token --discovery-token-ca-cert-hash $discovery-token-ca-cert-hashIn both worker nodes, paste the full kubeadm join command to join the cluster. Use sudo to run it as root:
sudo kubeadm joinControl Pane Node
In the control plane node, view the cluster status:
kubectl get nodes
Last updated