Step-by-Step Guide to Install CentOS, Docker, and Build a Kubernetes Cluster
This tutorial walks you through installing essential tools on CentOS, setting up Docker CE, configuring kubelet and kubeadm packages, initializing a Kubernetes master node, joining worker nodes, installing Flannel networking, and troubleshooting common issues, providing all commands and configuration steps needed for a functional cluster.
Install required CentOS packages
Install net-tools and disable the firewalld service.
# 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
Set up the Docker CE repository and install 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-ceStart Docker and run the hello‑world container to verify the installation.
# systemctl start docker
# docker run hello-worldInstall kubelet, kubeadm and kubectl packages
Configure the Kubernetes yum repository (Aliyun mirror) and install the required packages.
# 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-cniModify cgroup driver and cAdvisor port
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/modify: KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs
# Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=4194"Enable and start kubelet service
# 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 the control plane is ready, copy the admin kubeconfig for the regular user.
# mkdir -p $HOME/.kube
# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# chown $(id -u):$(id -g) $HOME/.kube/configAdd worker nodes
On each node run the join command generated by the master.
# kubeadm join --token 0696ed.7cd261f787453bd9 192.168.0.100:6443Install Flannel networking on the master
# 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.ymlVerify the cluster
# 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:
# export KUBECONFIG=/etc/kubernetes/admin.conf
# source ~/.bash_profileSigned-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.
