Kubernetes cluster installation guide
1 - Getting the server ready
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.32/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.32/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
2 - Disable swap memory
sudo swapoff -a
sudo sed -i '/swap.img/ s/^\(.*\)$/#\1/g' /etc/fstab
sudo sed -i '/swap/ s/^\(.*\)$/#\1/g' /etc/fstab
3 - Configure network and modules
3.1 Configure persistent loading of modules
sudo tee /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
3.2 Load at runtime
sudo modprobe overlay
sudo modprobe br_netfilter
3.3 Ensure sysctl params are set
sudo tee /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
3.4 Reload configs
sudo sysctl --system
4 - Install and configure Containerd
4.1 Add docker repository
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
4.2 Install containerd
sudo apt update
sudo apt install -y containerd.io
4.3 Configure containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
4.4 Start/restart containerd
sudo systemctl restart containerd
sudo systemctl enable containerd
5 - Master node configuration
5.1 Enable and start kubelet
sudo systemctl enable kubelet
sudo kubeadm config images pull
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
Note: If 192.168.0.0/16 is already in use within your network you must select a different pod network CIDR, replacing 192.168.0.0/16 in the above command.
Other options of the init command, but we are not going to use right now are:
--cri-socket ==> Use if have more than one container runtime to set runtime socket path
--apiserver-advertise-address ==> Set advertise address for this particular control-plane node's API server
If everything is ok, you will able to read a message saying "Your Kubernetes control-plane has initialized successfully!". If so, you need to run the following:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
6 - Installing Calico
6.1 Installing Calico
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml
kubectl get nodes
6.2 Check kubernetes nodes
kubectl get nodes
7 - Joining other nodes
7.1 For joining other nodes execute the following command
sudo kubeadm token create --print-join-command
7.2 Example of join token
kubeadm join 192.168.122.40:6443 --token r705ed.7d47ya6a6f3eecr4 --discovery-token-ca-cert-hash sha256:0c740869ea8a0e833a0163c5246fb74daed12baf7207e8a4a7f37dda40aaee4e
8 - Untaint master node
8.1 Check node name
kubectl get nodes
NAME STATUS ROLES AGE VERSION
soffid-ubuntu-24-04-pc-q35-ich9-2009 Ready control-plane 15m v1.32.13
8.2 Enable the master node to execute pods
kubectl taint node NODE_NAME node-role.kubernetes.io/master:NoSchedule-
-Example-
kubectl taint node soffid-ubuntu-24-04-pc-q35-ich9-2009 node-role.kubernetes.io/control-plane:NoSchedule-
8.3 Check master node taints
kubectl describe node NODE_NAME | grep Taints
-Example-
kubectl describe node soffid-ubuntu-24-04-pc-q35-ich9-2009 | grep Taints