How to Build a Fully Functional Kubernetes Cluster on CentOS 7 in Minutes
This guide walks through preparing three CentOS 7.6 servers, configuring system settings, installing Docker and Kubernetes components, initializing the master node, deploying a pod network, adding worker nodes, and setting up the Kubernetes dashboard, providing all necessary commands and troubleshooting tips.
Installation requirements and environment preparation for a Kubernetes cluster on CentOS 7.6.
# System: centos7.6
# Hardware: 2 CPU, 2G RAM
# Internet access, swap disabled
# Docker pre-installedPrepare three servers
Server IPs and names:
192.168.106.102 – k8s-master
192.168.106.103 – k8s-node01
192.168.106.104 – k8s-node02
Initialize system environment (run on all three servers)
1.1 Disable firewall
systemctl stop firewalld
systemctl disable firewalld1.2 Disable SELinux and swap
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
swapoff -a # temporary; permanent requires editing fstab1.3 Set hostnames and update /etc/hosts
hostnamectl set-hostname K8S-master # on master (102)
hostnamectl set-hostname K8S-node01 # on node01 (103)
hostnamectl set-hostname K8S-node02 # on node02 (104)
cat >> /etc/hosts <<EOF
192.168.106.102 K8S-master
192.168.106.103 K8S-node01
192.168.106.104 K8S-node02
EOF1.4 Enable bridge traffic to iptables
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system1.5 Sync time
ntpdate time.windows.com
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime1.6 Configure Alibaba Cloud yum repo and install Kubernetes packages
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
systemctl enable kubeletDeploy Kubernetes master node
kubeadm init \
--apiserver-advertise-address=192.168.106.102 \
--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/16Copy the kubeadm join command shown at the end of the init output to add worker nodes.
Install pod network plugin (Flannel)
wget http://120.78.77.38/file/kube-flannel.yaml
kubectl apply -f kube-flannel.yaml
# Alternatively pull the image first
docker pull lizhenliang/flannel:v0.11.0-amd64
kubectl apply -f kube-flannel.yaml
kubectl get pods -n kube-systemAdd worker nodes to the master
kubeadm join 192.168.106.102:6443 --token 7w0oxu.drdkjuzirow3dvj7 \
--discovery-token-ca-cert-hash sha256:e30452be8217affa2f11229e45cb2ed9dfa4424c82d5f354d9813ce789f58fdbVerify cluster
kubectl get nodes
kubectl get pods -n kube-systemInstall Kubernetes dashboard
wget http://120.78.77.38/file/kubernetes-dashboard.yaml
kubectl apply -f kubernetes-dashboard.yaml
kubectl get pods -n kubernetes-dashboard
kubectl get pod -n kubernetes-dashboard -o wideAccess the dashboard at https://192.168.106.104:30001 using Firefox, create a service account and cluster role binding to obtain a token, then log in.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
