setup Kubernetes Version 1.21.0 cluster on CentOS 7.
1 master node (IP = 192.168.100.208)
1 worker node (IP = 192.168.100.209)
sudo su
yum -y update
yum -y install git
sudo su
vi /etc/hostname
sudo su
vi /etc/hostname
vi /etc/hosts
192.168.100.208 master
192.168.100.209 worker
Make the system to sudo without password so when script is running, the script is not asking for the password (master node)
sudo su
sudo visudo
Scroll down to the end of the file and add the following line that will allow the user “centos” to run any command with sudo without being asked for a password (master node):
centos ALL=(ALL) NOPASSWD:ALL
sudo su
git clone https://github.com/daus2936/kubeadm-script.git
Give execute permission to the script file on master node and worker node (master node and worker node)
cd kubeadm-script
chmod +x ccluster.sh kubernetes.sh variable.sh docker.sh
Edit the variable,change the the variable of MASTER_IP to your master node IP address,and make sure to change the other variable (master node and worker node)
sudo su
vi variable.sh
sudo su
./docker.sh
docker login
sudo su
./kubernetes.sh
After the script of kubernetes.sh is finish,create kubernetes cluster,run ccluster.sh on master node (Run it as root) (master node)
sudo su
./ccluster.sh
kubectl get nodes
Use this command so the worker node can join the cluster,the token will be different in your cluster (use your token),type this on worker node:
kubeadm join 192.168.100.208:6443 --token 4niztf.rc6y0xfbnih81jxv \
--discovery-token-ca-cert-hash sha256:b44d3ac51430f7e7dad4639e4a8eeb5f3f03769ed8319c26e437ff49915659d7
kubeadm token create --print-join-command