How to Create a Vanilla Kubernetes Cluster on BareMetal

 Kubernetes (K8s) is a powerful open-source container orchestration system, and deploying it on bare metal provides high performance and direct control over hardware. This guide walks you through setting up a vanilla Kubernetes cluster on bare metal servers.

Prerequisites
  1. Hardware Requirements:
    • At least 3 machines (1 Control Plane Node and 2 Worker Nodes).
    • Minimum specifications:
      • Control Plane Node: 2 CPUs, 2 GB RAM, 20 GB disk space.
      • Worker Node: 1 CPU, 1 GB RAM, 10 GB disk space.
  2. Operating System:
    • Ubuntu 22.04 (recommended) or any other Linux distribution.
  3. Network Setup:
    • Unique hostname for each server.
    • Static IP addresses or DHCP reservations.
    • Disabled swap (required by Kubernetes).
  4. Tools:
    • SSH access to all nodes.
    • kubectl CLI tool.
    • kubeadm for Kubernetes initialization.
    • containerd or Docker as the container runtime.

Step 1: Prepare the Nodes

Update and Install Required Packages

Log into each node and execute the following commands:

sudo apt update && sudo apt upgrade -y
sudo apt install -y apt-transport-https curl

Disable Swap

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

Load Kernel Modules and Configure sysctl

sudo modprobe overlay
sudo modprobe br_netfilter

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


Step 2: Install Container Runtime (docker, containerd etc..)

Install Containerd 

sudo apt install -y containerd


# Configure containerd

sudo mkdir -p /etc/containerd

containerd config default | sudo tee /etc/containerd/config.toml

sudo systemctl restart containerd

sudo systemctl enable containerd

Step 3: Install Kubernetes Components

Add Kubernetes Repository

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list

deb https://apt.kubernetes.io/ kubernetes-xenial main

EOF


sudo apt update


Install kubeadm, kubelet, and kubectl

sudo apt install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

Step 4: Initialize the Control Plane

On the Control Plane Node, initialize the cluster:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Configure kubectl for the Control Plane Node

mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Deploy a Pod Network (e.g., Flannel or Calico)

kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml

Step 5: Join Worker Nodes to the Cluster

On the Control Plane Node, get the join command:

kubeadm token create --print-join-command

Run the output command on each Worker Node:

sudo kubeadm join <control-plane-ip>:6443 --token <token>  --discovery-token-ca-cert-hash sha256:<hash>

Step 6: Verify the Cluster

On the Control Plane Node, check the node statuses:
kubectl get node

You should see all nodes with the status Ready.

Comments

Popular posts from this blog

Managine Hadoop Cluster

VENOM Vulnerability

Logrotation in Linux/unix