Creating a Single-Node Kubernetes Cluster with kubeadm

Learn how to create a single-node Kubernetes cluster using kubeadm on an Ubuntu server.


Creating a single-node Kubernetes cluster using kubeadm on an Ubuntu server is straightforward. Here are the detailed steps:

Step 1: Prepare the Environment

  1. Update and upgrade the system:

    sudo apt update && sudo apt upgrade -y
    
  2. Install required dependencies:

    sudo apt install -y apt-transport-https ca-certificates curl
    
  3. Disable swap (required by Kubernetes):

    bash
    1sudo swapoff -a
    2sudo sed -i '/swap/d' /etc/fstab
  4. Configure kernel modules and sysctl settings:

    bash
    1sudo modprobe overlay
    2sudo modprobe br_netfilter
    3
    4cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
    5overlay
    6br_netfilter
    7EOF
    8
    9cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
    10net.bridge.bridge-nf-call-iptables  = 1
    11net.bridge.bridge-nf-call-ip6tables = 1
    12net.ipv4.ip_forward                 = 1
    13EOF
    14
    15sudo sysctl --system

Step 2: Install Docker or Container Runtime

  1. Install Docker (most common runtime):

    bash
    1sudo apt install -y docker.io
    2sudo systemctl enable docker
    3sudo systemctl start docker
  2. Set up the Docker daemon for Kubernetes:

    bash
    1cat <<EOF | sudo tee /etc/docker/daemon.json
    2{
    3  "exec-opts": ["native.cgroupdriver=systemd"],
    4  "log-driver": "json-file",
    5  "log-opts": {
    6    "max-size": "100m"
    7  },
    8  "storage-driver": "overlay2"
    9}
    10EOF
    11
    12sudo systemctl restart docker

Step 3: Install kubeadm, kubelet, and kubectl

  1. Add the Kubernetes repository:

    bash
    1echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    2curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
  2. Install Kubernetes components:

    bash
    1sudo apt update
    2sudo apt install -y kubeadm kubelet kubectl
    3sudo apt-mark hold kubeadm kubelet kubectl

Step 4: Initialize the Single-Node Cluster

  1. Run the kubeadm init command:

    sudo kubeadm init --pod-network-cidr=192.168.0.0/16
    
    • Use the --pod-network-cidr flag if you're using a specific CNI (e.g., Calico).
    • This command will output a kubeadm join command—save it in case you add more nodes later.
  2. Set up the kubeconfig for the user:

    bash
    1mkdir -p $HOME/.kube
    2sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    3sudo chown $(id -u):$(id -g) $HOME/.kube/config
  3. Allow the master node to schedule pods:

    kubectl taint nodes --all node-role.kubernetes.io/control-plane-
    

Step 5: Install a Pod Network Add-on

  1. Install a network plugin (e.g., Calico):
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Step 6: Verify the Cluster

  1. Check the status of the nodes:

    kubectl get nodes
    
  2. Check the status of pods in all namespaces:

    bash
    1# Check the status of pods in all namespaces
    2kubectl get pods -A
Follow us
All Rights Reserved
© 2011-2026
Progressive Innovation
LAB