Step-by-Step Guide to Setting Up a Kubernetes Cluster with Docker, kubeadm, and Flannel
This tutorial walks through preparing three Linux VMs, disabling firewalls and swap, configuring sysctl, installing Docker and Kubernetes components, initializing the master node, joining worker nodes, deploying the Flannel CNI plugin, creating a test nginx pod, and accessing it via a NodePort service.
This article provides a practical, step‑by‑step guide for building a Kubernetes cluster on three CentOS VMs (master, node1, node2) with IPs 192.168.240.58, 192.168.240.57, and 192.168.240.59.
1. Prepare the VMs
Disable the firewall and SELinux, and turn off swap:
systemctl stop firewalld systemctl disable firewalld setenforce 0 swapoff -aConfigure kernel parameters for iptables bridging:
cat > /etc/sysctl.d/k8s.conf <
sysctl --system
2. Install Docker, kubeadm, kubelet, and kubectl
Install Docker from the Alibaba Cloud mirror:
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
Add the Kubernetes repository:
cat > /etc/yum.repos.d/kubernetes.repo <
Install the Kubernetes binaries:
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
3. Initialize the master node
kubeadm init \
--apiserver-advertise-address=192.168.240.58 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.18.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
Set up local kubeconfig:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
4. Join the worker nodes
The join command generated by
kubeadm init
should be run on each node (images illustrate the process).
5. Deploy the Flannel CNI network plugin
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get pods -n kube-system
6. Create a test nginx pod and expose it
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
Verify the service and access it via the NodePort (e.g., http://192.168.240.58:31343/).
For further details, refer to the screenshots included throughout the guide.Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
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.