Cloud Native 7 min read

Build a Kubernetes Cluster with kubeadm: Step‑by‑Step Guide

This guide walks you through preparing Linux machines, configuring system settings, installing Docker and Kubernetes components with kubeadm, initializing a master node, deploying a pod network, joining worker nodes, and verifying the cluster, providing a complete step‑by‑step tutorial for building a Kubernetes cluster.

Architecture Development Notes
Architecture Development Notes
Architecture Development Notes
Build a Kubernetes Cluster with kubeadm: Step‑by‑Step Guide

Kubernetes is an open-source platform for automatically deploying, scaling, and managing containerized applications. The kubeadm tool helps initialize and configure a Kubernetes cluster. This article provides a detailed step-by-step guide to build a cluster with kubeadm on your machines.

Preparation

Before starting, prepare at least two machines (one master node and at least one worker node) that meet the following requirements:

Ubuntu 18.04+ (recommended), CentOS 7+ or Debian 9+ Linux distribution

At least 2 GB RAM per machine

Network configuration that allows inter-node communication

Master node with at least 2 CPU cores

Swap disabled (required by Kubernetes)

The examples use Ubuntu.

Environment Setup

Perform the following steps on all nodes.

Update the OS

<code>sudo apt-get update && sudo apt-get upgrade -y</code>

Install apt-transport-https

<code>sudo apt-get install -y apt-transport-https curl</code>

Disable Swap

<code>sudo swapoff -a</code>

Also comment out the swap line in /etc/fstab to prevent it from re-enabling after reboot.

Disable SELinux (CentOS only)

<code>setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config</code>

Adjust kernel parameters

<code>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</code>

Install Docker

<code>sudo apt-get install -y docker.io
sudo systemctl enable --now docker</code>

Ensure Docker is installed and enabled on all nodes.

Install kubeadm, kubelet and kubectl

Add the Kubernetes apt repository

<code>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</code>

Install the packages

<code>sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl</code>

kubelet runs on every node to manage containers, kubeadm initializes the cluster, and kubectl is the command-line tool for interacting with the cluster.

Cluster Initialization

Initialize the master

<code>sudo kubeadm init --pod-network-cidr=10.244.0.0/16</code>

The --pod-network-cidr must match the network plugin; this example uses Flannel.

Configure kubectl for the user

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

Install a pod network (Flannel)

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

Join Worker Nodes

After the master initialization finishes, the console outputs a kubeadm join command similar to:

<code>kubeadm join <MASTER_IP>:<PORT> --token <TOKEN> --discovery-token-ca-cert-hash sha256:<HASH></code>

Run this command on each worker node.

Validate the Cluster

Check node status

<code>kubectl get nodes</code>

All nodes should show the Ready status.

Run a test pod

<code>kubectl run hello-kubernetes --image=k8s.gcr.io/echoserver:1.4 --port=8080</code>

General Maintenance

Regularly update packages on all nodes

Monitor node and pod health

Periodically back up cluster state and data using kubectl or other tools

Conclusion

You now have a Kubernetes cluster built with kubeadm . From here you can start deploying applications and learn how to operate and maintain the cluster.

DockerKubernetesLinuxCluster Setupflannelkubeadm
Architecture Development Notes
Written by

Architecture Development Notes

Focused on architecture design, technology trend analysis, and practical development experience sharing.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.