Install Kubernetes on CentOS 85 min read


Table of Contents
Introduction
Kubernetes is a popular open-source container orchestration platform that allows you to deploy and manage multi-container applications at scale. Kubernetes can be used with a wide range of container systems among which Docker is the most used. For this reason, we will be looking at how to install docker first. Later In this article, we will learn how to install Kubernetes on CentOS 8.
Note: If you are using Ubuntu, then refer to our article How to install Kubernetes on Ubuntu 20.04.
Pre-requisites
- 2 or more Linux servers running CentOS8
- Access to a user account on each system with sudo or root privileges
- Your nodes should have at least two CPUs, each with at least 2GB of RAM. This isn’t a hard and fast rule, but it is essentially determined by the requirements of the application you’ll be running.
- All of your nodes should be able to communicate with one another, either via a private or public network, depending on what’s available.
Install Docker on CentOS 8
Before installing Kubernetes, we have to install Docker. Follow the below steps to install Docker.
1. Execute the below commands on both master and worker nodes
sudo su dnf -y upgrade swapoff -a dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo dnf install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm


2. Install docker
dnf install docker-ce --nobest -y


3. Start docker with the below command
systemctl start docker
4. Enable docker service with the below command so that the docker service starts as soon as you start your machine
systemctl enable docker
5. Check docker version and docker images with the below commands
docker version docker images


We have successfully installed Docker. Now, we can proceed with installing Kubernetes.
Install Kubernetes on CentOS 8
Follow the below steps to install Kubernetes
1. Execute the below commands on both master and worker nodes
(copy-paste the below lines till EOF directly in the terminal)
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg exclude=kubelet kubeadm kubectl EOF


2. Execute the below commands to install and start kubernetes service
dnf upgrade -y dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes systemctl enable kubelet systemctl start kubelet
3. Execute the below command only on master
kubeadm init --apiserver-advertise-address=10.128.0.2 --pod-network-cidr=192.168.0.0/16
In the above command, change the –apiserver-advertise-address IP address as per your instance. The IP address should be the private IP of your instance. In my case, the private IP is 10.128.0.2


The above command will generate kubeadm join command, copy that command because we will execute it later in the worker node.
4. Execute the below commands only on master
exit mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config


5. Deploy a POD network to the cluster. A Pod Network is a way for various nodes in a cluster to communicate with one another. Here, we’re using a calico network. Execute the below command in the Master node,
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml


6. Go to the worker node and execute the kubeadm join command which you noted down earlier.


7. Execute the below command on master to check the node status
kubectl get nodes


Done. We have successfully installed Kubernetes on CentOS 8.
Note: If the nodes are not in READY state, then wait for some time and then execute the kubectl get nodes command again.