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.

  1. Disable Swap:

    • Temporarily disable swap:

      sudo swapoff -a
    • Comment out the swap line in /etc/fstab to make the change permanent:

      sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
  2. 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.conf file and ensure the following line exists and is uncommented (#):

      net.ipv4.ip_forward = 1
    • Apply all sysctl changes immediately:

      sudo sysctl --system
  3. Install a Container Runtime (containerd):

    • Install the containerd package:

      sudo apt-get update
      sudo apt-get install -y containerd
    • Generate and configure the default configuration file to use the systemd cgroup 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 containerd service for the changes to take effect:

      sudo systemctl restart containerd
  4. 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)

  1. Initialize the cluster:

    sudo kubeadm init --pod-network-cidr=10.244.0.0/16
    • Important! Save the complete kubeadm join command that the terminal will show you when it finishes. You will need it for the worker-node.
  2. Configure kubectl for 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
  3. 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)

  1. Connect to the worker-node and run the kubeadm join command 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)

  1. Verify that both nodes are in the Ready state:

    kubectl get nodes

    The output should show both nodes in the Ready state.

You have now successfully deployed your basic Kubernetes cluster!