Kubernetes(K8s) - An opensource production grade container orchestration tool that helps to automate deploying, scaling, managing containerized applications.In this blog we will how to install latest Kubernetes(v1.16) in CentOS 8.

Requirements :

Two Servers,

Master : 192.168.56.135 , k8smaster-centos8.com
Node : 192.168.56.136 , k8snode-centos8.com

OS : Centos 8

Sudo access

Step 1 :

Disable Selinux, Firewall and Swap memory in both servers,

For Selinux,

# setenforce 0
# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

For Swap memory,

# swapoff -a 

Open fstab file and comment the swap line.

# vi /etc/fstab

/dev/mapper/cl-swap     swap                    swap    defaults        0 0

For Firewall,


# chkconfig firewalld off

# service firewalld stop

Step 2 :

Update the hostname in hosts file in both servers,

# vi /etc/hosts

192.168.56.135 k8smaster-centos8.com
192.168.56.136 k8snode-centos8.com

Step 3 :

Add IP forwarding in both servers,

Open k8s.conf(new file) and add below two lines,

# vi /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

Open sysctl.conf and add below line,


# vi /etc/sysctl.conf

net.ipv4.ip_forward = 1

Then run,

#  sysctl -p

Step 4 :

Add docker repos and install docker in both servers,

# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
# dnf install --nobest docker-ce -y

Start docker service,
systemctl daemon-reload
# systemctl start docker
# systemctl enable docker

Step 5 :

Add repo and install kubectl,kubeadm,kubelet in both servers,

Execute below command to add Kubernetes repos,

# cat <<EOF > /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
EOF

Now install Kubernetes packages,

# dnf install --nobest -y kubelet kubeadm kubectl



Enable kubelet systemctl,


# systemctl enable kubelet


Step 6 :

Configure Kubernetes in Master server,

# kubeadm init --pod-network-cidr=10.244.0.0/16

Note : if you want to choose specific network card use this below tag in above command,

--apiserver-advertise-address=K8s-Master-IP

here am using Flannel network.

Output,


Once its ran successfully then execute the required commands,

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

Step 7 :

Join Kubernetes Node server by using the above generated token,

Go to node server and run the below join command,

ex : 
# kubeadm join 192.168.56.135:6443 --token l4zrvi.rtcnay0p8ar1nxwr \
    --discovery-token-ca-cert-hash sha256:3c020920f35135428a6e65fde6f4d2546a65a24b6b47b0fb81122b03cc5d2b04



Step 8 :

Install Flannel network in Master server and verify the Kubernetes status,

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Now check the nodes status,

kubectl get nodes



Here you can see both the servers status shown as Ready state and it should be in that state.

Check all pods status,

# kubectl get pods --all-namespaces



Here you can see all the pods status are in Running state and it means everything is fine here.

Thats all, Kubernetes latest version v1.16.2 has been installed in CentOS 8 successfully.


Troubleshooting: 

You may face coredns pod status show as Pending, to fix this issue change the cni version as '0.2.0' in /etc/cni/net.d/10-flannel.conflist in both servers.

Post a Comment

Previous Post Next Post