Environment Overview
The following infrastructure is utilized for this deployment, featuring a single control plane node and two worker nodes. All systems run Ubuntu 22.04 LTS on identical hardware specifications.
| Role | Hostname | IP Address |
|---|---|---|
| Master | k8s-master | 192.168.2.216 |
| Worker | k8s-worker-1 | 192.168.2.215 |
| Worker | k8s-worker-2 | 192.168.2.217 |
System Specs: AMD Ryzen 7 5700X, 8GB RAM, 100GB Disk, Kernel 5.15.0-102-generic.
Configuring Containerd
Containerd serves as the Container Runtime Interface (CRI). Begin by downloading and extracting the binaries:
wget https://github.com/containerd/containerd/releases/download/v1.7.16/containerd-1.7.16-linux-amd64.tar.gz
sudo tar Cxzvf /usr/local containerd-1.7.16-linux-amd64.tar.gz
Install the systemd service unit and enable the daemon:
wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
sudo mv containerd.service /usr/lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now containerd
Deploy the runc OCI runtime and CNI network plugins:
wget https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.amd64
sudo install -m 755 runc.amd64 /usr/local/sbin/runc
wget https://github.com/containernetworking/plugins/releases/download/v1.4.1/cni-plugins-linux-amd64-v1.4.1.tgz
sudo mkdir -p /opt/cni/bin
sudo tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.4.1.tgz
Generate the default configuration and set the cgroup driver to systemd:
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
sudo systemctl restart containerd
Network Prerequisites
Load required kernel modules and configure IP forwarding for the cluster network:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
</code>
Initializing the Cluster
With the runtime ready, bootstrap the control plane using kubeadm. Specify the API server address and the Pod network CIDR:
kubeadm init --apiserver-advertise-address=192.168.2.216 --pod-network-cidr=192.168.2.0/24
Troubleshooting Swap Space
Initialization may fail if swap memory is active. The kubelet explicitly requires swap to be disabled. Verify the error logs and execute the following commands to permanently disable swap:
sudo swapoff -a
sudo sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab