In this article, we will have explained the necessary steps to install and configure Kubernetes Cluster on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Kubernetes is a free and open-source container management system that provides a platform for deployment automation, scaling, and operations of application containers across clusters of host computers. With Kubernetes, you can freely make use of the hybrid, on-premise, and public cloud infrastructure in order to run deployment tasks of your organization.
Install Kubernetes Cluster on CentOS 8
Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.
sudo dnf update
Step 2. Set Up Hostname, Firewall, and SELinux.
Now set the system hostname and update DNS in your /etc/hosts
file:
$ hostnamectl set-hostname master-node # cat <> /etc/hosts 192.168.0.46 master-node 192.168.0.47 node-1 worker-node-1 192.168.0.48 node-2 worker-node-2 EOF
Next, disable SELinux enforcement:
setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
Next, you need to open up the proper firewall ports with the following commands:
firewall-cmd --permanent --add-port=6443/tcp firewall-cmd --permanent --add-port=2379-2380/tcp firewall-cmd --permanent --add-port=10250/tcp firewall-cmd --permanent --add-port=10251/tcp firewall-cmd --permanent --add-port=10252/tcp firewall-cmd --permanent --add-port=10255/tcp firewall-cmd –reload modprobe br_netfilter echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
Step 3. Install Docker-CE.
The first thing to do is to install an older version of docker-ce with the command:
sudo dnf install docker-ce-3:18.09.1-3.el7
Start and enable the Docker daemon with the command:
sudo systemctl enable --now docker
Step 4. Install Kubernetes on CentOS 8.
Now we can install Kubernetes on CentOS. First, we must create a new repository file with the command:
sudo nano /etc/yum.repos.d/kubernetes.repo
[kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 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
Then, install the necessary Kubernetes packages with the command:
sudo dnf install kubelet kubeadm kubectl --disableexcludes=kubernetes
Start and enable the service with the command:
sudo systemctl enable --now kubelet
Now we’re going to have to su to the root user and then create a new file (to help configure iptables) with the command:
nano /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1
Save and close the file. Load the new configuration with the command:
sysctl --system
Next step, we must disable swap. Do that with the command:
sudo swapoff -a
Step 5. Create a Daemon File.
Finally, we have to create a daemon file. Do that by first issuing the command su and then creating the new daemon file with the command:
nano /etc/docker/daemon.json
{ "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "storage-opts": [ "overlay2.override_kernel_check=true" ] }
Then, create a new systemd directory with the command:
mkdir -p /etc/systemd/system/docker.service.d
Next, reload and restart the Docker daemon with the commands:
systemctl daemon-reload systemctl restart docker
Step 6. Initialize the Cluster.
This is only done on the Kubernetes master. To initialize the cluster, issue the command:
sudo kubeadm init
The above will initialize the cluster and report to you the necessary command used to join the nodes to your master.
Congratulation, you have learned how to install and configure Kubernetes on CentOS 8. If you have any question, please leave a comment below.