Skip to content

๐Ÿš€ Kubernetes Cluster Setup (kubeadm)

This document provides a comprehensive, step-by-step guide to provisioning a Kubernetes cluster using kubeadm. The target architecture consists of one control plane node and multiple worker nodes.


๐Ÿ–ฅ๏ธ 1. Cluster Architecture & Prerequisites

Node Details

Hostname Role IP Address OS Requirements
k8s-master Control Plane 192.168.29.111 Ubuntu 20.04/22.04+
k8s-worker1 Worker Node 192.168.29.3 Ubuntu 20.04/22.04+
k8s-worker2 Worker Node 192.168.29.12 Ubuntu 20.04/22.04+

Network Requirements

  • Full network connectivity between all machines in the cluster.
  • Proper DNS or /etc/hosts resolution.

โš™๏ธ 2. Common Node Preparation

(โš ๏ธ Run these commands on ALL nodes: Control Plane and Workers)

Disable Swap

Kubernetes requires swap to be disabled to ensure stable pod scheduling.

sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab

Load Kernel Modules

Enable necessary kernel modules for container networking.

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

Configure Sysctl Parameters

Apply sysctl network parameters required by Kubernetes.

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

Install Container Runtime (containerd)

sudo apt-get update
sudo apt-get install -y containerd

# Generate default configuration and apply
sudo mkdir -p /etc/containerd
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
sudo systemctl enable containerd

Install Kubernetes Components

Install kubeadm, kubelet, and kubectl. Ensure you have the Kubernetes apt repository configured if not using default repos. Basic installation:

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl


๐Ÿ‘‘ 3. Control Plane Initialization

(โš ๏ธ Run these commands ONLY on the Control Plane node: k8s-master)

Initialize the Cluster

Replace the pod-network-cidr if your chosen CNI requires a different subnet.

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

Setup Kubeconfig

Configure kubectl for the regular 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 Calico Network Plugin (CNI)

Install a Pod network add-on so your Pods can communicate with each other.

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml


๐Ÿ”— 4. Join Worker Nodes

(โš ๏ธ Run these commands ONLY on the Worker nodes: k8s-worker1, k8s-worker2)

Retrieve Join Command (If needed)

If you misplaced the join command from step 3, generate a new one on the Control Plane:

kubeadm token create --print-join-command

Execute Join Node

Run the generated join command on each worker node.

sudo kubeadm join 192.168.29.111:6443 \
  --token <your-token> \
  --discovery-token-ca-cert-hash sha256:<your-hash>


๐Ÿ› ๏ธ 5. Cluster Tools Installation

(Run on Control Plane or any configured admin machine)

Install Helm (Kubernetes Package Manager)

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

Install crictl (CLI for CRI-compatible container runtimes)

sudo apt-get install -y cri-tools

๐Ÿงช 6. Verification & Testing

Verify Cluster Status

Check if all nodes are successfully registered and in a Ready state.

kubectl get nodes
kubectl get pods --all-namespaces

Deploy a Sample Application (Native Kubernetes)

Deploy NGINX and expose it via NodePort to test cluster routing.

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --type=NodePort --port=80
kubectl get svc nginx
Access: Open a web browser or use curl: http://<NODE-IP>:<NODEPORT>

Deploy a Sample Application (via Helm)

Test Helm functionality using the Bitnami NGINX chart.

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install nginx-test bitnami/nginx

# Verify
helm list
kubectl get pods -l app.kubernetes.io/name=nginx


๐Ÿ”Ÿ 7. Summary

This document structures a robust, production-aligned approach to provisioning a Kubernetes cluster using kubeadm.

Key Outcomes Achieved

  • Infrastructure Setup: Provisioned 1 Control Plane node and 2 Worker nodes.
  • Node Configuration: Standardized system settings (Swap, Sysctl, Modules) for Kubernetes compatibility.
  • Container Runtime: Configured containerd with SystemdCgroup enabled.
  • Control Plane & Networking: Initialized cluster and deployed Calico CNI successfully.
  • Worker Integration: Secured entry of arbitrary compute nodes into the cluster ring.
  • Tooling: Enabled advanced package management and debugging operations via Helm and crictl.
  • Validation: Ensured correct operation through workload scheduling and cross-node Service exposure.

๐ŸŽฏ Final State

  • The Kubernetes cluster is fully operational and successfully scheduling workloads.
  • Ready for next steps:
  • CI/CD pipeline integration (e.g., ArgoCD, GitLab CI)
  • Monitoring and logging stack (Prometheus / Grafana / Loki)
  • Ingress Controller configuration
  • Persistent Storage layer configuration