2 ######################################################################
4 # The script is to undo the changes on ELIOT Manager and ELIOT nodes #
5 # done by setup.sh file. #
6 # It uninstalls docker, kubernetes. #
7 # It releases the port used. #
8 # It deletes the files created for kubernetes in node machine #
9 # Script is tested in Ubuntu 16.04 version. #
10 ######################################################################
13 OSPLATFORM=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
17 echo "This script will remove docker and its related files from the master and node machines"
18 echo "This script will remove kubeadm kubectl kubelet kubernetes from the master and node machines"
19 echo "The changes will be first executed on manager machine and then node machines."
20 echo "It will pick the node machine details from nodelist file"
21 echo "This file supports Linux- Ubuntu version only"
24 # Rollbacking the changes on ELIOT Manager Node
27 if [ "$(id -u)" = 0 ]; then
28 sudo apt-get install iptables
29 sudo iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
30 sudo apt-get install ipvsadm
31 sudo fuser -k -n tcp 10250
32 sudo yes y | apt-get purge -y docker-engine
33 sudo yes y | apt-get purge -y docker
34 sudo yes y | apt-get purge -y docker.io
35 sudo yes y | apt-get purge -y docker-ce
36 sudo yes y | apt-get purge -y docker-ce-cli
37 sudo yes y | groupdel docker
38 sudo yes y | kubeadm reset
39 sudo yes y | apt-get purge kubeadm
40 sudo yes y | apt-get purge kubectl
41 sudo yes y | apt-get purge kubelet
42 sudo yes y | apt-get purge kube*
43 sudo yes y | apt-get purge kubernetes-cni
45 sudo yes y | apt-get autoremove
46 sudo yes y | apt-get autoclean
48 sudo fuser -k -n tcp 10250
49 sudo yes y | sudo apt-get purge -y docker-engine
50 sudo yes y | sudo apt-get purge -y docker
51 sudo yes y | sudo apt-get purge -y docker.io
52 sudo yes y | sudo apt-get purge -y docker-ce
53 sudo yes y | sudo apt-get purge -y docker-ce-cli
54 sudo yes y | sudo kubeadm reset
55 sudo yes y | sudo apt-get purge kubeadm
56 sudo yes y | sudo apt-get purge kubectl
57 sudo yes y | sudo apt-get purge kubelet
58 sudo yes y | sudo apt-get purge kube*
59 sudo yes y | sudo apt-get purge kubernetes-cni
67 #Rollbacking the changes on ELIOT Worker Node
70 if [ " $(id -u)" = 0]; then
71 INSTALL_IPVSADM="sudo apt-get install ipvsadm"
72 RESET_PORT="fuser -k -n tcp 10250"
73 #REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf !('manifests') "
74 REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf bootstrap-kubelet.conf kubelet.conf pki"
75 REMOVE_DOCKER1="sudo yes y | apt-get purge -y docker-engine"
76 REMOVE_DOCKER2="sudo yes y | apt-get purge -y docker"
77 REMOVE_DOCKER3="sudo yes y | apt-get purge -y docker.io"
78 REMOVE_DOCKER4="sudo yes y | apt-get purge -y docker-ce"
79 REMOVE_DOCKER5="sudo yes y | apt-get purge -y docker-ce-cli"
80 REMOVE_DOCKER6="sudo yes y | groupdel docker"
81 RESET_KUBEADM="sudo yes y | kubeadm reset"
82 REMOVE_KUBE_FILES1="sudo yes y | apt-get purge kubeadm"
83 REMOVE_KUBE_FILES2="sudo yes y | apt-get purge kubectl "
84 REMOVE_KUBE_FILES3="sudo yes y | apt-get purge kubelet "
85 REMOVE_KUBE_FILES4="sudo yes y | apt-get purge kube* "
86 REMOVE_KUBE_FILES5="sudo yes y | apt-get purge kubernetes-cni"
87 REMOVE_KUBE_FILES6="sudo rm -rf ~/.kube"
88 AUTO_REMOVE="sudo yes y | apt-get autoremove"
89 AUTO_CLEAN="sudo yes y | apt-get autoclean"
91 RESET_PORT="fuser -k -n tcp 10250"
92 REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf bootstrap-kubelet.conf kubelet.conf pki"
93 REMOVE_DOCKER1="sudo yes y | sudo apt-get purge -y docker-engine"
94 REMOVE_DOCKER2="sudo yes y | sudo apt-get purge -y docker"
95 REMOVE_DOCKER3="sudo yes y | sudo apt-get purge -y docker.io"
96 REMOVE_DOCKER4="sudo yes y | sudo apt-get purge -y docker-ce"
97 REMOVE_DOCKER5="sudo yes y | sudo apt-get purge -y docker-ce-cli"
98 REMOVE_DOCKER6="sudo yes y | sudo groupdel docker"
99 RESET_KUBEADM="sudo yes y | sudo kubeadm reset"
100 REMOVE_KUBE_FILES1="sudo yes y | sudo apt-get purge kubeadm"
101 REMOVE_KUBE_FILES2="sudo yes y | sudo apt-get purge kubectl "
102 REMOVE_KUBE_FILES3="sudo yes y | sudo apt-get purge kubelet "
103 REMOVE_KUBE_FILES4="sudo yes y | sudo apt-get purge kube* "
104 REMOVE_KUBE_FILES5="sudo yes y | sudo apt-get purge kubernetes-cni"
105 REMOVE_KUBE_FILES6="sudo rm -rf ~/.kube"
108 #Read all the Worker Node details from nodelist file.
112 nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
113 nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
114 nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
115 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${INSTALL_IPVSADM} < /dev/null
116 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_PORT} < /dev/null
117 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES} < /dev/null
118 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER1} < /dev/null
119 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER2} < /dev/null
120 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER3} < /dev/null
121 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER4} < /dev/null
122 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER5} < /dev/null
123 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER6} < /dev/null
124 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_KUBEADM} < /dev/null
125 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES1} < /dev/null
126 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES2} < /dev/null
127 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES3} < /dev/null
128 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES4} < /dev/null
129 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES5} < /dev/null
130 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES6} < /dev/null
131 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${AUTO_REMOVE} < /dev/null
132 sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${AUTO_CLEAN} < /dev/null
133 done < nodelist > /dev/null 2>&1
137 verify_reset_status()
142 if [ $1 == "--help" ] || [ $1 == "-h" ];
148 if [[ $OSPLATFORM = *Ubuntu* ]]; then
152 echo "Script only supports Ubuntu Version."