2 #Install the k8s-master & k8s-worker node from Mgnt node
7 # Displays the help menu.
12 echo "This script can help you to deploy a simple iec testing"
14 echo "Firstly, the master node and worker node information must"
15 echo "be added into config file which will be used for deployment."
17 echo "Secondly, there should be an user on each node which will be"
18 echo "used to install the corresponding software on master and"
19 echo "worker nodes. At the same time, this user should be enable to"
20 echo "run the sudo command without input password on the hosts."
22 echo "Example usages:"
29 # Deploy k8s with calico.
34 INSTALL_SOFTWARE="sudo apt-get update && sudo apt-get install -y git &&\
35 sudo rm -rf ~/.kube ~/iec &&\
36 git clone ${REPO_URL} &&\
37 cd iec/src/foundation/scripts/ && source k8s_common.sh"
39 #Automatic deploy the K8s environments on Master node
40 SETUP_MASTER="cd iec/src/foundation/scripts/ && source k8s_master.sh ${K8S_MASTER_IP}"
41 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${INSTALL_SOFTWARE}
42 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_MASTER} | tee ${LOG_FILE}
44 KUBEADM_JOIN_CMD=$(grep "kubeadm join " ./${LOG_FILE})
47 #Automatic deploy the K8s environments on each worker-node
48 SETUP_WORKER="cd iec/src/foundation/scripts/ && source k8s_worker.sh"
50 for worker in "${K8S_WORKER_GROUP[@]}"
52 ip_addr="$(cut -d',' -f1 <<<${worker})"
53 passwd="$(cut -d',' -f2 <<<${worker})"
54 echo "Install & Deploy on ${ip_addr}. password:${passwd}"
56 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} ${INSTALL_SOFTWARE}
57 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "echo \"sudo ${KUBEADM_JOIN_CMD}\" >> ./iec/src/foundation/scripts/k8s_worker.sh"
59 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "swapon -a"
60 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} ${SETUP_WORKER}
65 #Deploy etcd & CNI from master node
66 #There may be more options in future. e.g: Calico, Contiv-vpp, Ovn-k8s ...
67 SETUP_CNI="KUBECONFIG=/etc/kubernetes/admin.conf && cd iec/src/foundation/scripts && source setup-cni.sh"
68 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_CNI}
69 SETUP_HELM="KUBECONFIG=/etc/kubernetes/admin.conf && cd iec/src/foundation/scripts && source helm.sh"
70 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_HELM}
75 # Check the K8s environments
80 VERIFY_K8S="cd iec/src/foundation/scripts/ && source nginx.sh"
81 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${VERIFY_K8S}
90 if [ $1 == "--help" ] || [ $1 == "-h" ];
97 # Read the configuration file
100 echo "The number of K8s-Workers:${#K8S_WORKER_GROUP[@]}"