AIO and MUNO mode upgrade for EG 1.5.0 version
[eliot.git] / scripts / kubernetes_reset.sh
1 ########################################################################################
2 #                                                                                      #
3 # The script is to reset the settings on ELIOT Manager and ELIOT nodes                 #
4 # before running the setup.sh file again on the same setup.                            #
5 # It resets the settings of kubeadm and restarts its service                           #
6 # It releases the ports used.                                                          #
7 # It deletes the files created for kubernetes on node machine                          #
8 # Script is tested in Ubuntu 16.04 version.                                            #
9 ########################################################################################
10
11 # constants
12 OSPLATFORM=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
13
14 show_help()
15 {
16   echo "The script is to reset the settings on ELIOT Manager and ELIOT nodes which "
17   echo "needs to be done before executing the setup.sh file again."
18   echo "The changes will be first executed on manager machine and then on the node machines."
19   echo "It will pick the node machine details from nodelist file"
20 }
21
22 # Resetting ELIOT Manager Node
23 reset_k8smaster()
24 {
25  sudo yes y | kubeadm reset
26  sudo apt-get install iptables
27  sudo iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
28  sudo apt-get install ipvsadm
29  sudo systemctl restart kubelet
30  sudo fuser -k -n tcp 10250
31
32 reset_k8sworkers
33 }
34
35 #Resetting ELIOT Worker Node
36 reset_k8sworkers()
37 {
38 RESET_KUBEADM="sudo yes y | kubeadm reset"
39 INSTALL_IPVSADM="sudo apt-get install ipvsadm"
40 RESTART_KUBELET="sudo systemctl restart kubelet"
41 RESET_PORT="sudo fuser -k -n tcp 10250"
42 #REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf !('manifests') "
43 REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf bootstrap-kubelet.conf kubelet.conf pki"
44 REMOVE_CADVISOR_FILES="docker rm cadvisor-iot-node1"
45
46 #Read all the Worker Node details from nodelist file.
47  while read line
48  do
49      nodeinfo="${line}"
50      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
51      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
52      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
53      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_KUBEADM} < /dev/null
54      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${INSTALL_IPVSADM} < /dev/null
55      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESTART_KUBELET} < /dev/null
56      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_PORT} < /dev/null
57      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES} < /dev/null
58      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_CADVISOR_FILES} < /dev/null
59  done < nodelist > /dev/null 2>&1
60 }
61
62 verify_reset_status()
63 {
64 echo "Success!!"
65 }
66
67 if [ $1 == "--help" ] || [ $1 == "-h" ];
68 then
69   show_help
70   exit 0
71 fi
72
73 if [[ $OSPLATFORM = *Ubuntu* ]]; then
74    reset_k8smaster
75    verify_reset_status
76 else
77    echo "The script supports only Linux - Ubuntu"
78 fi