How to Install a Kubernetes Cluster on CentOS 7

Kubernetes is a popular open-source platform for managing containerized applications in a clustered environment. If you're looking to install Kubernetes on CentOS 7, this guide will take you through the process step-by-step. We'll cover everything you need to know to get a cluster up and running, including setting up the environment, installing the necessary components, and configuring your nodes.


Before we get started, you'll need a few things −

  • A CentOS 7 server with at least 2GB of RAM and 2 CPUs.

  • Root access to the server.

  • A basic understanding of Linux command-line usage.

Setting up the Environment

To start, we need to set up our environment. This involves disabling SELinux and configuring our firewall.

Disabling SELinux

SELinux is a security enhancement for Linux that can sometimes interfere with Kubernetes. To disable it, open the /etc/selinux/config file in your text editor of choice and change the value of SELINUX to disabled. Save and close the file.

$ sudo vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#  enforcing - SELinux security policy is enforced.
#  permissive - SELinux prints warnings instead of enforcing.
#  disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these two values:
#  targeted - Targeted processes are protected,
#  mls - Multi Level Security protection.

Configuring Firewall

Next, we need to configure our firewall to allow the necessary traffic for Kubernetes. We'll use firewalld to manage our firewall.

$ sudo systemctl enable firewalld
$ sudo systemctl start firewalld

Next, we need to open the following ports −

  • TCP port 6443 − This is the Kubernetes API server port.

  • TCP port 2379-2380 − This is the etcd server client API port.

  • TCP and UDP port 8472 − This is the overlay network port for Flannel.

  • TCP and UDP port 10250 − This is the Kubelet API port.

$ sudo firewall-cmd --permanent --add-port=6443/tcp
$ sudo firewall-cmd --permanent --add-port=2379-2380/tcp
$ sudo firewall-cmd --permanent --add-port=8472/udp
$ sudo firewall-cmd --permanent --add-port=10250/tcp
$ sudo firewall-cmd --reload

Installing the Necessary Components

Now that our environment is set up, we can start installing the necessary components for our Kubernetes cluster. We'll need to install Docker, Kubernetes, and kubeadm.

Installing Docker

Docker is the container runtime that Kubernetes uses. To install it, run the following commands −

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
$ sudo yum-config-manager --add-repo
$ sudo yum install -y docker-ce docker-ce-cli
$ sudo systemctl enable docker
$ sudo systemctl start docker

Installing Kubernetes and Kubeadm

We'll install Kubernetes and kubeadm from the official Kubernetes repository. Run the following commands −

$ sudo vi /etc/yum.repos.d/kubernetes.repo


$ sudo yum install -y kubelet kubeadm kubectl
$ sudo systemctl enable kubelet
$ sudo systemctl start kubelet

Configuring the Nodes

Now that we have all the necessary components installed, we can start configuring our nodes.

Initializing the Control Plane Node

The first node we need to configure is the control plane node. This is the node that will host the Kubernetes API server and etcd. To initialize the control plane node, run the following command −

$ sudo kubeadm init --pod-network-cidr=

This command will take a few minutes to complete. Once it's done, you'll see a message that looks something like this −

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user −

mkdir -p $HOME/.kube
   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
   sudo chown $(id -u):$(id -g) $HOME/.kube/config

You can now join any number of the control-plane node running the following command on each as root −

kubeadm join --token abcdef.1234567890abcdef \
   --discovery-token-ca-cert-hash sha256:1234567890abcdef1234567890abcdef

Make a note of the join command at the end of the output, as we'll need it later. We also need to run the commands in the message to configure kubectl on our control plane node.

$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

Joining Worker Nodes to the Cluster

With our control plane node configured, we can start adding worker nodes to the cluster. To do this, we need to run the join command that we saved earlier on each worker node.

$ sudo kubeadm join --token abcdef.1234567890abcdef \
   --discovery-token-ca-cert-hash sha256:1234567890abcdef1234567890abcdef

Once the join command has been run on each worker node, you can verify that they are part of the cluster by running the following command on the control plane node −

$ kubectl get nodes

This command should show all the nodes in the cluster, including the control plane node and any worker nodes that have been joined.

Installing a Network Add-on

Finally, we need to install a network add-on to enable communication between pods across different nodes. We'll use Flannel as our network add-on.

$ kubectl apply -f

Once the network add-on has been installed, you can verify that it's working by creating a pod on one of your worker nodes and verifying that it can communicate with a pod on another worker node.

While this guide covers the basics of setting up a Kubernetes cluster on CentOS 7, it's worth noting that there are many additional configuration options and customizations you can make. For example, you can configure Kubernetes to use a different container runtime, or you can set up a high-availability control plane by adding multiple master nodes.

Additionally, it's important to note that running a Kubernetes cluster can be resource-intensive, and you may need to consider scaling up your infrastructure as your workload grows. You may also want to consider using a managed Kubernetes service like Google Kubernetes Engine or Amazon Elastic Kubernetes Service, which can take care of many of the administrative tasks for you.

Finally, it's worth noting that Kubernetes is a complex platform, and it can take some time to become proficient with it. If you're new to Kubernetes, it's a good idea to start with some basic tutorials and work your way up to more complex configurations.


In this guide, we've covered everything you need to know to install a Kubernetes cluster on CentOS 7. We've covered setting up the environment, installing the necessary components, and configuring the nodes. With this guide, you should be able to get a cluster up and running quickly and easily.

Updated on: 28-Apr-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started