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 gitsudo su
vi /etc/hostnamesudo su
vi /etc/hostnamevi /etc/hosts192.168.100.208 master
192.168.100.209 workerMake the system to sudo without password so when script is running, the script is not asking for the password (master node)
sudo su
sudo visudoScroll 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:ALLsudo su
git clone https://github.com/daus2936/kubeadm-script.gitGive 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.shEdit 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.shsudo su
./docker.shdocker loginsudo su
./kubernetes.shAfter 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.shkubectl get nodesUse 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:b44d3ac51430f7e7dad4639e4a8eeb5f3f03769ed8319c26e437ff49915659d7kubeadm token create --print-join-command