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.
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
sudo apt-get update && sudo apt-get upgrade -yInstall apt-transport-https
sudo apt-get install -y apt-transport-https curlDisable Swap
sudo swapoff -aAlso comment out the swap line in /etc/fstab to prevent it from re-enabling after reboot.
Disable SELinux (CentOS only)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/configAdjust kernel parameters
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 --systemInstall Docker
sudo apt-get install -y docker.io
sudo systemctl enable --now dockerEnsure Docker is installed and enabled on all nodes.
Install kubeadm, kubelet and kubectl
Add the Kubernetes apt 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
EOFInstall the packages
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl kubeletruns 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
sudo kubeadm init --pod-network-cidr=10.244.0.0/16The --pod-network-cidr must match the network plugin; this example uses Flannel.
Configure kubectl for the user
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/configInstall a pod network (Flannel)
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlJoin Worker Nodes
After the master initialization finishes, the console outputs a kubeadm join command similar to:
kubeadm join <MASTER_IP>:<PORT> --token <TOKEN> --discovery-token-ca-cert-hash sha256:<HASH>Run this command on each worker node.
Validate the Cluster
Check node status
kubectl get nodesAll nodes should show the Ready status.
Run a test pod
kubectl run hello-kubernetes --image=k8s.gcr.io/echoserver:1.4 --port=8080General 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architecture Development Notes
Focused on architecture design, technology trend analysis, and practical development experience sharing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
