Cloud Native 15 min read

Step-by-Step Guide: Install CentOS, Docker, and Build a Kubernetes Cluster

This tutorial walks through installing net‑tools on CentOS, disabling firewalld, setting up Docker CE, pulling and tagging required Kubernetes images, configuring kubelet and kubeadm, initializing a master node, joining worker nodes, installing Flannel networking, and troubleshooting common kubectl issues.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Step-by-Step Guide: Install CentOS, Docker, and Build a Kubernetes Cluster

Install net-tools

# yum install -y net-tools

Disable firewalld and SELinux

# systemctl stop firewalld && systemctl disable firewalld
# setenforce 0
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

Install Docker CE

Docker has two editions: Docker‑CE (Community Edition, free) and Docker‑EE (Enterprise Edition, commercial). This guide uses Docker‑CE.
# 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-world

Install kubelet, kubeadm and related packages

Optionally use DaoCloud mirror to accelerate Docker image pulls.

# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://0d236e3f.m.daocloud.io
# docker version >= 1.12
# {"registry-mirrors": ["http://0d236e3f.m.daocloud.io"]}
# systemctl restart docker

Pull required Kubernetes component images and retag them for the Google container registry.

images=(kube-controller-manager-amd64 etcd-amd64 k8s-dns-sidecar-amd64 kube-proxy-amd64 kube-apiserver-amd64 kube-scheduler-amd64 pause-amd64 k8s-dns-dnsmasq-nanny-amd64 k8s-dns-kube-dns-amd64)
for imageName in ${images[@]}; do
  docker pull champly/$imageName
  docker tag champly/$imageName gcr.io/google_containers/$imageName
  docker rmi champly/$imageName
done

Modify image tags to specific versions.

# docker tag gcr.io/google_containers/etcd-amd64 gcr.io/google_containers/etcd-amd64:3.0.17 && \
  docker rmi gcr.io/google_containers/etcd-amd64
# docker tag gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.5 && \
  docker rmi gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64
# docker tag gcr.io/google_containers/k8s-dns-kube-dns-amd64 gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.5 && \
  docker rmi gcr.io/google_containers/k8s-dns-kube-dns-amd64
# docker tag gcr.io/google_containers/k8s-dns-sidecar-amd64 gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.2 && \
  docker rmi gcr.io/google_containers/k8s-dns-sidecar-amd64
# docker tag gcr.io/google_containers/kube-apiserver-amd64 gcr.io/google_containers/kube-apiserver-amd64:v1.7.5 && \
  docker rmi gcr.io/google_containers/kube-apiserver-amd64
# docker tag gcr.io/google_containers/kube-controller-manager-amd64 gcr.io/google_containers/kube-controller-manager-amd64:v1.7.5 && \
  docker rmi gcr.io/google_containers/kube-controller-manager-amd64
# docker tag gcr.io/google_containers/kube-proxy-amd64 gcr.io/google_containers/kube-proxy-amd64:v1.6.0 && \
  docker rmi gcr.io/google_containers/kube-proxy-amd64
# docker tag gcr.io/google_containers/kube-scheduler-amd64 gcr.io/google_containers/kube-scheduler-amd64:v1.7.5 && \
  docker rmi gcr.io/google_containers/kube-scheduler-amd64
# docker tag gcr.io/google_containers/pause-amd64 gcr.io/google_containers/pause-amd64:3.0 && \
  docker rmi gcr.io/google_containers/pause-amd64

Add Alibaba Cloud YUM repository for Kubernetes 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

Install kubelet, kubeadm, kubectl and kubernetes‑cni.

# yum install -y kubelet kubeadm kubectl kubernetes-cni

Enable and start kubelet

# systemctl enable kubelet && systemctl start kubelet

Initialize the master node

# kubeadm reset && kubeadm init \
    --apiserver-advertise-address=192.168.0.100 \
    --kubernetes-version=v1.7.5 \
    --pod-network-cidr=10.200.0.0/16

After 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/config

Configure cgroup driver

# vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# (replace "--cgroup-driver=systemd" with "--cgroup-driver=cgroupfs")

Set cAdvisor port to 4194.

# vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# add: Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=4194"

Join worker nodes to the cluster

Run the following command on each node (replace the token and IP with those shown after master initialization).

# kubeadm join --token 0696ed.7cd261f787453bd9 192.168.0.100:6443

Install 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.yml

Verify cluster status

# kubectl get cs
# kubectl get nodes
# kubectl get pods --all-namespaces

Troubleshooting

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_profile
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.

KuberneteslinuxCentOSFlannelkubeadm
MaGe Linux Operations
Written by

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.

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.