Kubernetes Cluster Installation and Configuration
Cluster Installation and Configuration
This guide uses kubeadm to deploy a two-node cluster, with one node as the control-plane and the other as a worker-node, on virtual machines running a Debian/Ubuntu-based operating system.
Step 1: Virtual Machine Preparation (In Proxmox)
- Create two VMs: One control-plane (minimum 2 vCPUs, 2 GB RAM, 20 GB disk) and one worker-node (minimum 1 vCPU, 1 GB RAM, 10 GB disk).
- Assign static IPs to both nodes to prevent communication issues.
Step 2: Operating System Preparation (On Both Nodes)
Connect to each virtual machine separately and run the following commands.
-
Disable Swap:
-
Temporarily disable swap:
sudo swapoff -a -
Comment out the swap line in
/etc/fstabto make the change permanent:sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
-
-
Configure Kernel for Networking:
-
Immediately load the necessary kernel modules:
sudo modprobe overlay sudo modprobe br_netfilter -
Add the modules so they load automatically on reboot:
sudo tee /etc/modules-load.d/containerd.conf <<EOF overlay br_netfilter EOF -
Enable packet forwarding in the kernel. Open the
/etc/sysctl.conffile and ensure the following line exists and is uncommented (#):net.ipv4.ip_forward = 1 -
Apply all
sysctlchanges immediately:sudo sysctl --system
-
-
Install a Container Runtime (
containerd):-
Install the
containerdpackage:sudo apt-get update sudo apt-get install -y containerd -
Generate and configure the default configuration file to use the
systemdcgroup driver:sudo containerd config default | sudo tee /etc/containerd/config.toml sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml -
Restart the
containerdservice for the changes to take effect:sudo systemctl restart containerd
-
-
Install Kubernetes Components (
kubeadm,kubelet,kubectl):sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl gpg curl -fsSL [https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key](https://pkgs.k8s.io/core:/stable:/v1.28/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.28/deb/](https://pkgs.k8s.io/core:/stable:/v1.28/deb/) /' | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl
Step 3: Initialize the Control-Plane (On the control-plane node only)
-
Initialize the cluster:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16- Important! Save the complete
kubeadm joincommand that the terminal will show you when it finishes. You will need it for the worker-node.
- Important! Save the complete
-
Configure
kubectlfor your user:mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config -
Install a Container Network Interface (CNI) plugin, for example Flannel:
kubectl apply -f [https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml](https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml)
Step 4: Join the Worker-Node to the Cluster (On the worker-node only)
-
Connect to the worker-node and run the
kubeadm joincommand you saved in the previous step. It will look similar to this (but with your own details):sudo kubeadm join 192.168.1.200:6443 --token yma8cv.7pr4rvudkdzxdpgt \ --discovery-token-ca-cert-hash sha256:f2a0fe0f3775812f61ae380b2a20ec9fe745d9ac8f7fa80f71c037e54d6294e6
Step 5: Final Verification (On the control-plane node)
-
Verify that both nodes are in the
Readystate:kubectl get nodesThe output should show both nodes in the
Readystate.
You have now successfully deployed your basic Kubernetes cluster!