Deploying a Kubernetes Cluster on CentOS 7

A Kubernetes cluster requires atleast three CentOS 7 servers.

  • One master node (hostname: master-k8s).
  • Two worker nodes (hostnames: worker-k8s-01, worker-k8s-02).

All steps in the Environment Preparation and Docker Installation sections must be executed on all three nodes: master-k8s, worker-k8s-01, and worker-k8s-02.

Environment Preparation

Configure static IP addresses for each server to ensure network consistency. Proceed with the standard Kubernetes prerequisites:

  • Disable SELinux.
  • Configure iptables to allow bridged network traffic.
  • Disable swap.
  • Ensure hostname resolution is configured correctly.

Installing Docker

Begin by installing required development tools.

yum install -y gcc gcc-c++

Remove any older Docker versions to avoid conflicts.

yum remove -y docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
                docker-logrotate \
                docker-engine

Install the yum-utils package, which provides the yum-config-manager utility.

yum install -y yum-utils

Set up the Docker YUM repository. Using a mirror like Alibaba Cloud is recommended for faster downloads in certain regions.

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

For servers with unrestricted internet access, you can use the official Docker repository instead.

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Refresh the YUM package metadata cache.

yum makecache fast

Install a specific, compatible version of Docker CE.

yum install -y docker-ce-18.06.1.ce-3.el7

Start the Docker service and enable it to launch on system boot.

systemctl start docker
systemctl enable docker

Docker is now installed on all cluster nodes.

Installing Kubernetes Components

Define the Kubernetes YUM repository on every node to prevent installation delays.

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=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 core Kubernetes tools: kubelet, kubeadm, and kubectl. Specify version 1.18.0 for consistency.

yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0

Enable the kubelet service so it starts automatically.

systemctl enable kubelet

Initializing the Master Node

Execute the following command only on the master node (master-k8s). Replace 192.168.1.136 with the master node's actual IP address.

kubeadm init \
    --apiserver-advertise-address=192.168.1.136 \
    --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

A successful initialization is indicated by a message containing a kubeadm join command for the worker nodes.

Tags: kubernetes CentOS 7 docker Cluster Deployment kubeadm

Posted on Thu, 25 Jun 2026 17:32:48 +0000 by solaris77