Kubernetes 2 min read

Configure Kubernetes cluster - A Step by Step Guide

Prerequisites - A host machine (Linux, macOS, or Windows) with at least 4 GB RAM and 20 GB free disk space. - kubectl, kubeadm, and kubelet installed on the host. - docker or another…

Prerequisites

  • A host machine (Linux, macOS, or Windows) with at least 4 GB RAM and 20 GB free disk space.
  • kubectl, kubeadm, and kubelet installed on the host.
  • docker or another container runtime (containerd, cri-o) available and running.
  • A static IP address assigned to the host; DNS is optional but recommended.
  • The host’s firewall opened for ports 6443 (API), 2379‑2380 (etcd), 10250 (kubelet), 10255 (read‑only kubelet), and 10256 (kube-scheduler).

1. Prepare the Host

  1. Update the system
    sudo apt-get update && sudo apt-get upgrade -y
    
  2. Disable swap – Kubernetes requires swap off.
    sudo swapoff -a
    sudo sed -i '/ swap / s/^/#/' /etc/fstab
    
  3. Enable kernel modules – Open the file /etc/modules-load.d/k8s.conf and add:
    overlay
    br_netfilter
    
    Then load them:
    sudo modprobe overlay
    sudo modprobe br_netfilter
    
  4. Configure sysctl – Add /etc/sysctl.d/k8s.conf with:
    net.bridge.bridge-nf-call-iptables  = 1
    net.ipv4.ip_forward                 = 1
    net.bridge.bridge-nf-call-ip6tables = 1
    
    Apply: sudo sysctl --system

2. Install Docker (or another CRI)

sudo apt-get install -y docker.io
sudo systemctl enable --now docker

Verify: docker run hello-world

3. Install Kubernetes Binaries

sudo apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL 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-get update
sudo apt-get install -y kubeadm kubelet kubectl
sudo apt-mark hold kubeadm kubelet kubectl

4. Initialize the Control Plane

Choose a static IP, e.g., 192.168.1.10.
kubeadm init will generate a configuration file; we’ll use the defaults and tweak later.

sudo kubeadm init --apiserver-advertise-address=192.168.1.10 --pod-network-cidr=10.244.0.0/16

After completion, set up local admin access:

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

5. Deploy a Pod Network

A pod network is required for inter‑pod communication. Flannel is simple for a single‑node cluster.

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

Wait until all kube-system pods are Running.

6. Join the Worker Node

Even though we’re using the same host, we still need to run kubelet as a worker. First, get the join command from the output of kubeadm init. It looks like:

kubeadm join 192.168.1.10:6443 --token abcdef.0123456789abcdef \
  --discovery-token-ca-cert-hash sha256:1234567890abcdef...

Run that on the same host:

sudo kubeadm join 192.168.1.10:6443 --token abcdef.0123456789abcdef \
  --discovery-token-ca-cert-hash sha256:1234567890abcdef...

Because the host already has kubelet installed, the command will register the node as a worker. Verify:

kubectl get nodes

You should see two nodes:

  • k8s-control-plane (role: master)
  • k8s-worker-1 (role: worker)

7. Verify Cluster Health

kubectl get componentstatuses
kubectl top nodes
kubectl top pods --all-namespaces

All components should report Healthy. If any are not, check the logs in /var/log/.

8. Optional: Enable Dashboard and Dashboard Access

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
kubectl create token admin-user

Use the token to log in via https://<IP>:<DashboardPort>.

9. Clean Up

If you need to reset the cluster:

sudo kubeadm reset
sudo systemctl stop kubelet
sudo rm -rf /etc/kubernetes
sudo rm -rf ~/.kube
sudo systemctl restart docker

10. Summary

You now have a single‑host Kubernetes cluster with one control plane and one worker node. This setup is ideal for learning, testing, or small demos. For production workloads, consider a multi‑node cluster with dedicated masters, workers, and a more robust networking plugin.

Single‑Host Kubernetes Architecture

PB
Written by

Parul Bedi

Part of the Azure Gravy writing team.

Conversation

0 comments

No comments yet. Start the conversation below.

Leave a comment

Replying to a comment.
Be kind. Markdown is not supported in comments.
Keep reading

Related posts

All posts