Step-by-Step Guide: Install CentOS, Docker CE, and Build a Kubernetes Cluster
This tutorial walks you through preparing a CentOS system, installing Docker CE, configuring Docker mirrors, setting up kubelet, kubeadm and kubectl packages, adjusting cgroup settings, initializing a Kubernetes master node, joining worker nodes, deploying Flannel networking, and troubleshooting common issues, all with exact command examples.
Prepare CentOS
Install net-tools and disable the firewall:
# yum install -y net-tools
# systemctl stop firewalld && systemctl disable firewalld
# setenforce 0
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configInstall Docker CE
Use the community edition of Docker.
# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum-config-manager --disable docker-ce-edge
# yum makecache fast
# yum -y install docker-ce
# systemctl start docker
# docker run hello-worldInstall Kubernetes Packages
Install kubelet, kubeadm, kubectl and kubernetes-cni from the Alibaba Cloud 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
EOF
# yum install -y kubectl kubelet kubeadm kubernetes-cniConfigure cgroups and cAdvisor
Change the kubelet cgroup driver to cgroupfs and set the cAdvisor port to 4194.
# vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# Add: Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
# Add: Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=4194"
# systemctl enable kubelet && systemctl start kubeletInitialize the Master Node
Reset any previous state and run kubeadm init with the desired API server address, Kubernetes version, and pod network CIDR.
# kubeadm reset && kubeadm init \
--apiserver-advertise-address=192.168.0.100 \
--kubernetes-version=v1.7.5 \
--pod-network-cidr=10.200.0.0/16After initialization, copy the admin kubeconfig for regular user access:
# mkdir -p $HOME/.kube
# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# chown $(id -u):$(id -g) $HOME/.kube/configDeploy Flannel Networking
Pull the Flannel image and apply the manifest files:
# docker pull quay.io/coreos/flannel:v0.8.0-amd64
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.8.0/Documentation/kube-flannel.yml
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.8.0/Documentation/kube-flannel-rbac.ymlJoin Worker Nodes
On each worker, run the join command printed by kubeadm init (example below):
# kubeadm join --token 0696ed.7cd261f787453bd9 192.168.0.100:6443Verify the Cluster
Check component health and node status:
# kubectl get cs
# kubectl get nodes
# kubectl get pods --all-namespacesTroubleshooting
If you encounter “The connection to the server localhost:8080 was refused”, set the kubeconfig environment variable:
# echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >> ~/.bash_profile
# source ~/.bash_profileAll steps above provide a complete, reproducible process to set up a functional Kubernetes cluster on CentOS.
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.
