3 #Uninstall the k8s-master & k8s-worker node from Mgnt node
7 if grep -q -e rhel /etc/*-release; then
9 elif grep -q -e debian /etc/*-release; then
10 OS_ID_LIKE=${1:-debian}
18 KUBEADM_DESTROY_CMD="kubeadm reset -f"
20 for worker in "${K8S_WORKER_GROUP[@]}"
22 ip_addr="$(cut -d',' -f1 <<<${worker})"
23 passwd="$(cut -d',' -f2 <<<${worker})"
24 echo "Destroy k8s on ${ip_addr}. password:${passwd}"
26 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} ${KUBEADM_DESTROY_CMD}
30 #Destroy master k8s env
31 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} ${KUBEADM_DESTROY_CMD}
40 case ${OS_VERSION:-} in
42 UNINSTALL_CMD="sudo apt purge -y kubernetes-cni kubeadm kubectl kubelet kube* docker-ce --allow-change-held-packages &&\
43 sudo apt -y autoremove"
46 UNINSTALL_CMD="sudo yum remove -y kubeadm kubectl kubelet kubernetes-cni kube* docker-ce &&\
47 sudo yum -y autoremove"
50 echo 'Unsupported distribution detected!'
55 for worker in "${K8S_WORKER_GROUP[@]}"
57 ip_addr="$(cut -d',' -f1 <<<${worker})"
58 passwd="$(cut -d',' -f2 <<<${worker})"
59 echo "Destroy k8s on ${ip_addr}. password:${passwd}"
61 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "${UNINSTALL_CMD}"
66 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} "${UNINSTALL_CMD}"
71 # Recover system configuration.
75 REC_CMD="sudo swapon -a"
77 for worker in "${K8S_WORKER_GROUP[@]}"
79 ip_addr="$(cut -d',' -f1 <<<${worker})"
80 passwd="$(cut -d',' -f2 <<<${worker})"
81 echo "Destroy k8s on ${ip_addr}. password:${passwd}"
83 sshpass -p ${passwd} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${ip_addr} "${REC_CMD}"
88 sshpass -p ${K8S_MASTERPW} ssh -o StrictHostKeyChecking=no ${HOST_USER}@${K8S_MASTER_IP} "${REC_CMD}"
91 # Read the configuration file
94 Destroy_k8s ${OS_ID_LIKE}
96 Uninstall ${OS_ID_LIKE}
99 Recover_conf ${OS_ID_LIKE}