Kubernetes Installation and Configuration CentOS

Install Kubernets on CentOS 8

I have 3 CentOS 8 minimal install OS on the VMs.
Update the host-names and IP Addresses in the /etc/hosts file.

IP hostname master-node worker-node1 worker-node2

On all 3 nodes:

1. Update the system, Install some basic packages, Docker dependencies and Docker.

yum update -y

yum install epel-release mlocate tcpdump net-tools traceroute vim git wget curl yum-utils device-mapper-persistent-data lvm2 -y

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

yum install docker-ce && sudo systemctl enable docker

2. Disable firewalld, SELinux and swap:

systemctl disable –now firewalld

sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config

sed -i ‘/ swap / s/^/#/’ /etc/fstab

swapoff -a

3. Reboot the three nodes for the changes to take effect.


4. Add Kubernetes repo and install Kubelet, Kubeadm and Kubectl:

echo ‘[kubernetes]
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’ > /etc/yum.repos.d/kubernetes.repo

yum install -y kubelet kubeadm kubectl && systemctl enable kubelet

5. Add the IPs in /etc/hosts (highlited text will change according to your IP)

sed -i -e “\$a172.30.43.14 master-node” /etc/hosts
sed -i -e “\$a172.30.43.4 worker-node1″ /etc/hosts
sed -i -e “\$a172.30.43.5 worker-node2″ /etc/hosts

On master node:

6. We will now make the master-node become the master by running the following command.
At the end of the command we will obtain information together with the hash key to make the worker-nodes join the master-node.

kubeadm init

7. Now, we should configure the admin.conf for the user running Kubernetes.
In my case it is the root user. Therefore, run the following command:

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

On worker nodes:

8. Launch the following command to on both the worker-nodes to join the master-node:

kubeadm join –token mjm5s9.25tiqb5o11luaqce \
–discovery-token-ca-cert-hash sha256:221b63243f31c2658b30dc520fd8e4e6172dc83ea217436df95c52578438a43e

On master node:

9. Now we can detect if the workers have successfully joined with the following command:

kubectl get nodes

10. We also need to install the abstraction layer that build the network between the workers ad the masters:

kubectl apply -f “https://cloud.weave.works/k8s/net?k8s-version=$kubever

The highlighted part should be replaced with your kubectl version

This will create several containers within the environment.

11. Using the following commands, we can see all the pods:

kubectl get pods –all-namespaces

Leave a Reply

Your email address will not be published.