We have covered the basic overview of Kubernetes. Now we will cover its installation on CentOS 8. Let us first cover what CentOS 8 is.
CentOS 8 is a Linux distribution which gives us a free and open source community and computing platform, released on 24 Sep 2019. It is compatible with Red Hat Enterprise Linux and with its upstream source. From version 8 it supports x86-64, ARM64, and POWER8 architectures.
The different ports which are used for access and communication are:
The minimum requirements for the Kubernetes server and for master and worker nodes are 2GB and CPUs. Kubernetes cannot be installed until these minimum requirements are met.
Before installing anything you need to update the servers using:
dnf -y upgrade
Disable SELinux enforcement.
1 2 3
setenforce 0 sed - i--follow - symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' etc / sysconfig / selinux
The IP masquerade at the firewall has to be enabled using:
1 2
firewall - cmd--add - masquerade--permanent firewall - cmd--reload
To traverse iptables rules we need to set bridged packets.
1 2 3 4
cat < /etc/sysctl.d / k8s.conf net.bridge.bridge - nf - call - ip6tables = 1 net.bridge.bridge - nf - call - iptables = 1 EOF
Then we need to load new rules.sysctl --system
To increase performance, disable all the memory swaps.swapoff -a
After the above mentioned steps we can now install Docker.
To install Docker add the repository for the Docker installation package.
1
dnf config - manager--add - repo = https: //download.docker.com/linux/centos/docker-ce.repo
Before installing Docker install container.io.
1
dnf install https: //download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
Install Docker from the repository.dnf install docker-ce --nobest -y
Now we need to start Docker service.systemctl start docker
To make Docker auto start when server is started:systemctl enable docker
To use systemd cgroup driver to make changes to Docker:
1 2 3 4
echo '{ "exec-opts": ["native.cgroupdriver=systemd"] } ' > /etc/docker/daemon.json
To apply the changes restart Docker.systemctl restart docker
Check the version of Docker using:docker version
After installing Docker now we will install Kubernetes.
Create the file to add the Kubernetes repository to the package.
1 2 3 4 5 6 7 8 9
cat < /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
Update the repository info.dnf upgrade -y
To install the necessary components for Kubernetes:dnf install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
Enable Kubernetes services to run at startup and start its services.
1 2
systemctl enable kubelet systemctl start kubelet
After its installation we will configure it to form a cluster.
Configure kubeadm.kubeadm config images pull
Open the ports which are used by Kubernetes.firewall-cmd --zone=public --permanent --add-port={6443,2379,2380,10250,10251,10252}/tcp
Replace the worker-IP-address to allow Docker access from another node.firewall-cmd -zon=public --permanent -add-rich-rule 'rule family=ipv4 source address=worker-IP-address/32 accept'
Mark the changes made and reload.firewall-cmd --reload
Install the plugin Container Network Interface (CNI) for Kubernetes.kubeadm init --pod-network-cidr 192.168.0.0/1
You will then get an output like shown below. Please make a note of the token as it is required to join worker nodes to the cluster.
Output:
Now make the configuration files and directory.
1 2 3 4
mkdir - p $HOME / .kube cp - i / etc / kubernetes / admin.conf $HOME / .kube / config chown $(id - u): $(id - g) $HOME / .kube / config kubectl apply - f https: //docs.projectcalico.org/manifests/calico.yaml
Check that the master node is enabled and is running.kubectl get nodes
After successful execution, we will get a node with ready status.
1
2
NAME STATUS ROLES AGE VERSION
master Ready master 91 s v1 .18 .0
For Kubernetes installation we should have at least one worker node because it runs the containerized applications. In this section we will configure only one worker node.
Open all the ports used by Kubernetes.firewall-cmd --zone=public --permanent --add-port={10250,30000-32767}/tcp
Mark the changes made and reload.firewall-cmd --reload
Now we need to join a cluster using the token we previously noted.
1 2
kubeadm join 94.237 .41 .193: 6443--token 4 xrp9o.v345aic7zc1bj8ba\ --discovery - token - ca - cert - hash sha256: b2e459930f030787654489ba7ccbc701c29b3b60e0aa4998706fe0052de8794c
Check if the worker node has joined or not.
Go to the Master node and issue the below command.
kubectl get nodes
1
2
3
NAME STATUS ROLES AGE VERSION
master Ready master 10 m v1 .18 .0
worker Ready 28 s v1 .18 .0
If it all went well, you will see two nodes with status Ready. If It does not happen, wait for a while and run the command again.
Now that it’s all done, you are all ready to work on Kubernetes installation having two nodes.