Cloud Native 5 min read

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.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Step-by-Step Guide to Setting Up a Kubernetes Cluster with Docker, kubeadm, and Flannel

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 -a

Configure kernel parameters for iptables bridging:

cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
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 <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeLinuxCluster SetupFlannelkubeadm
Practical DevOps Architecture
Written by

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.

0 followers
Reader feedback

How this landed with the community

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.