2 # shellcheck disable=SC1073,SC1072,SC1039,SC2059,SC2046
3 #Install the k8s-master & k8s-worker node from Mgnt node
8 # Displays the help menu.
13 echo "This script can help you to deploy a simple iec testing"
15 echo "Firstly, the master node and worker node information must"
16 echo "be added into config file which will be used for deployment."
18 echo "Secondly, there should be an user on each node which will be"
19 echo "used to install the corresponding software on master and"
20 echo "worker nodes. At the same time, this user should be enable to"
21 echo "run the sudo command without input password on the hosts."
23 echo "In the end, some optional parameters could be directly passed"
24 echo "to startup.sh by shell for easy customizing your own IEC"
26 echo "-k|--kube: ---- The version of k8s"
27 echo "-c|--cni-ver: ---- Kubernetes-cni version"
28 echo "-C|--cni: ---- CNI type: calico/flannel"
30 echo "Example usages:"
31 echo " ./startup.sh #Deploy with default parameters"
32 echo " #Deploy the flannel with 1.15.2 K8s"
33 echo " ./startup.sh -C flannel -k 1.15.2 -c 0.7.5"
38 # Setup system configuration before invoke setup-cni.sh
40 k8s_worker_preconfigure() {
43 if [ -n "${DEV_NAME[$ip_addr]}" ]
45 CONTIVPP_CONFIG="cd iec/src/foundation/scripts/cni/contivpp && sudo ./contiv-update-config.sh ${DEV_NAME[$ip_addr]}"
46 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} $CONTIVPP_CONFIG
50 DANM_CONFIG="cd iec/src/foundation/scripts/cni/danm && sudo ./danm_install.sh"
51 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} $DANM_CONFIG
54 CILIUM_CONFIG="cd iec/src/foundation/scripts/cni/cilium && sudo ./cilium_install.sh"
55 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} $CILIUM_CONFIG
58 OVN_KUBERNETES_PRECONFIG="cd iec/src/foundation/scripts/cni/ovn-kubernetes && ./clean_old_ovs.sh"
59 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} $OVN_KUBERNETES_PRECONFIG
72 INSTALL_SOFTWARE="sudo apt-get update && sudo apt-get install -y git &&\
73 sudo rm -rf ~/.kube ~/iec &&\
74 git clone ${REPO_URL} &&\
75 cd iec/src/foundation/scripts/ && source k8s_common.sh $KUBE_VERSION $CNI_VERSION"
77 #Automatic deploy the K8s environments on Master node
78 SETUP_MASTER="cd iec/src/foundation/scripts/ && source k8s_master.sh ${K8S_MASTER_IP} ${POD_NETWORK_CIDR} ${SVC_CIDR}"
79 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${INSTALL_SOFTWARE}
80 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_MASTER} | tee ${LOG_FILE}
82 TOKEN=$(grep "\--token " ./${LOG_FILE})
83 TOKEN_ID=$(echo ${TOKEN#*"token "}|cut -f1 -d' ')
85 SH256=$(grep "\--discovery-token-ca-cert-hash " ./${LOG_FILE})
86 TOKEN_CA_SH256=${SH256#*"sha256:"}
88 KUBEADM_JOIN_CMD="kubeadm join ${K8S_MASTER_IP}:6443 --token ${TOKEN_ID} --discovery-token-ca-cert-hash sha256:${TOKEN_CA_SH256}"
90 #Automatic deploy the K8s environments on each worker-node
91 SETUP_WORKER="cd iec/src/foundation/scripts/ && source k8s_worker.sh"
93 for worker in "${K8S_WORKER_GROUP[@]}"
95 ip_addr="$(cut -d',' -f1 <<<${worker})"
96 passwd="$(cut -d',' -f2 <<<${worker})"
97 echo "Install & Deploy on ${ip_addr}. password:${passwd}"
99 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} ${INSTALL_SOFTWARE}
100 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "echo \"sudo ${KUBEADM_JOIN_CMD}\" >> ./iec/src/foundation/scripts/k8s_worker.sh"
102 k8s_worker_preconfigure
104 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} ${SETUP_WORKER}
105 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "sudo swapon -a"
109 #Deploy etcd & CNI from master node
110 SETUP_CNI="cd iec/src/foundation/scripts && source setup-cni.sh $CNI_TYPE $POD_NETWORK_CIDR $K8S_MASTER_IP $SVC_CIDR $CLUSTER_IP"
111 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_CNI}
112 SETUP_HELM="cd iec/src/foundation/scripts && source helm.sh"
113 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_HELM}
118 # Check the K8s environments
123 VERIFY_K8S="cd iec/src/foundation/scripts/ && source nginx.sh"
124 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${VERIFY_K8S}
131 echo "K8S_MASTER_IP:${K8S_MASTER_IP}"
132 echo "HOST_USER:${HOST_USER}"
133 echo "REPO_URL:${REPO_URL}"
135 echo "The number of K8s-Workers:${#K8S_WORKER_GROUP[@]}"
136 for worker in "${K8S_WORKER_GROUP[@]}"
138 ip_addr="$(cut -d',' -f1 <<<${worker})"
139 passwd="$(cut -d',' -f2 <<<${worker})"
140 echo "Install & Deploy on ${ip_addr}. password:${passwd}"
143 echo "KUBE_VERSION: ${KUBE_VERSION}"
144 echo "CNI_TPYE: ${CNI_TYPE}"
145 echo "CLUSTER_IP: ${CLUSTER_IP}"
146 echo "POD_NETWORK_CIDR: ${POD_NETWORK_CIDR}"
149 # Read the configuration file
154 ARGS=`getopt -a -o C:k:c:h -l cni:,kube:,cni-ver:,help -- "$@"`
155 eval set -- "${ARGS}"
165 echo "This is config kube version:$2"
170 echo "This is config cni version:$2"
175 echo "this is help case"