Installing Kubernetes cluster on Centos 8.2
Master node
1) Install Kubernetes on Master node via below script.
__________________________________________________________________________________________
sudo su - # run it as root
useradd kubeadmin
passwd kubeadmin
#Adding the Docker repository
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
#Install Docker-ce (Container Engine) --> This has docker-ce-cli and containerd dependencies, installs the latest version
sudo yum install docker-ce -y
#Docker version 19.03.13
sudo yum update -y && sudo yum install -y containerd.io
#The following commands creates and gives permissions to the users who wants to execute Docker command
sudo groupadd docker
sudo usermod -aG docker kubeadmin
sudo chmod 666 /var/run/docker.sock
sudo systemctl restart docker
#Add Kubernetes Repository
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
sudo yum install jq -y
##Follow these steps before installing Kubeadm
#Install Kubelet, Kubeadm and Kubectl. This installs the laetst version
sudo yum install -y kubelet kubeadm kubectl
#Installed Version, kubelet=1.19.3, kubeadm=1.19.3, kubectl=1.19.3
# ONLY IN MASTER
kubeadm init --pod-network-cidr=10.1.0.0/16 # make sure your host CIDR is different
#To enable Master node to take workloads
kubectl taint nodes --all node-role.kubernetes.io/master-
sudo systemctl enable docker.service
sudo systemctl enable kubelet
mkdir -p /etc/systemd/system/docker.service.d
# Restart Docker
systemctl daemon-reload
systemctl restart docker
__________________________________________________________________________________________
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 10.0.1.4:6443 --token <XYZ> \
--discovery-token-ca-cert-hash sha256:<XYZ>
2) Once the above script completes you can is installed CNI pluggin
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Note :-
If kubectl command fails with below error please export admin.conf and try again.
[root@cset-master ~]# kubectl get pod
The connection to the server localhost:8080 was refused - did you specify the right host or port?
export KUBECONFIG=/etc/kubernetes/admin.conf
Now you can run below script on
Worker node
3) Run below script on worker node to install K8s
__________________________________________________________________________________________
sudo su - # run it as root
useradd kubeadmin
passwd kubeadmin
#Adding the Docker repository
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
#Install Docker-ce (Container Engine) --> This has docker-ce-cli and containerd dependencies, installs the latest version
sudo yum install docker-ce -y
#Docker version 19.03.13
sudo yum update -y && sudo yum install -y containerd.io
#The following commands creates and gives permissions to the users who wants to execute Docker command
sudo groupadd docker
sudo usermod -aG docker kubeadmin
sudo chmod 666 /var/run/docker.sock
sudo systemctl restart docker
#Add Kubernetes Repository
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
sudo yum install jq -y
##Follow these steps before installing Kubeadm
#Install Kubelet, Kubeadm and Kubectl. This installs the laetst version
sudo yum install -y kubelet kubeadm kubectl
__________________________________________________________________________________________
kubeadm join 10.0.1.4:6443 --token <XYZ> \
--discovery-token-ca-cert-hash sha256:<XYZ>
This is what you would see when K8S is up and running.
[kubeadmin@cset-master ~]$ k get nodes
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 4d3h v1.20.2
worker Ready <none> 4d3h v1.20.2
[kubeadmin@cset-master ~]$ k get pods
NAME READY STATUS RESTARTS AGE
busybox1 1/1 Running 80 3d8h
middle-layer-css-6f4d594945-5wc2j 1/1 Running 0 3d
portal-css-68cf9fc789-j4vml 1/1 Running 0 3d
mysql-6dc655975d-pbzqw 1/1 Running 0 3d8h
[kubeadmin@cset-master ~]$