Modified 2 files 45/1445/3
authorGarima Misra <garima.misra@calsoftinc.com>
Thu, 22 Aug 2019 04:23:53 +0000 (09:53 +0530)
committerGarima Misra <garima.misra@calsoftinc.com>
Thu, 22 Aug 2019 05:00:42 +0000 (10:30 +0530)
Change-Id: Ibbe2a23e86a6fa0b45842f7239cb71e604c7d1f0

scripts/k8smaster.sh
scripts/kubernetes_cleanup.sh [new file with mode: 0644]
scripts/kubernetes_reset.sh [new file with mode: 0644]
scripts/setup.sh

index 8fd511d..49e72be 100644 (file)
@@ -45,6 +45,7 @@ if ! kubectl get nodes; then
          --service-cidr="${K8s_SVC_CIDR}"
 
   if [ "$(id -u)" = 0 ]; then
+    KUBECONFIG=/etc/kubernetes/admin.conf
     echo "export KUBECONFIG=/etc/kubernetes/admin.conf" | \
       tee -a "${HOME}/.profile"
     source "${HOME}/.profile"
diff --git a/scripts/kubernetes_cleanup.sh b/scripts/kubernetes_cleanup.sh
new file mode 100644 (file)
index 0000000..04e6abf
--- /dev/null
@@ -0,0 +1,120 @@
+
+######################################################################
+#                                                                    #
+# The script is to undo the changes on ELIOT Manager and ELIOT nodes #
+# done by setup.sh file.                                             #
+# It uninstalls docker, kubernetes.                                  #
+# It releases the port used.                                         #
+# It deletes the files created for kubernetes in node machine        #
+# Script is tested in Ubuntu 16.04 version.                          #
+######################################################################
+
+# constants
+OSPLATFORM=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
+
+show_help()
+{
+  echo "This script will remove docker and its related files from the master and node machines"
+  echo "This script will remove kubeadm kubectl kubelet kubernetes from the master and node machines"
+  echo "The changes will be first executed on manager machine and then node machines."
+  echo "It will pick the node machine details from nodelist file"
+  echo "This file supports Linux- Ubuntu version only"
+}
+
+# Rollbacking the changes on ELIOT Manager Node
+rollback_k8smaster()
+{
+sudo apt-get install iptables
+sudo iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
+sudo apt-get install ipvsadm
+sudo fuser -k -n tcp 10250
+sudo yes y | apt-get purge -y docker-engine
+sudo yes y | apt-get purge -y docker
+sudo yes y | apt-get purge -y docker.io
+sudo yes y | apt-get purge -y docker-ce
+sudo yes y | apt-get purge -y docker-ce-cli
+sudo yes y | groupdel docker
+sudo yes y | kubeadm reset
+sudo yes y | apt-get purge kubeadm
+sudo yes y | apt-get purge kubectl
+sudo yes y | apt-get purge kubelet
+sudo yes y | apt-get purge kube*
+sudo yes y | apt-get purge kubernetes-cni
+sudo rm -rf ~/.kube
+sudo yes y | apt-get autoremove
+sudo yes y | apt-get autoclean
+
+rollback_k8sworkers
+
+}
+
+#Rollbacking the changes on ELIOT Worker Node
+rollback_k8sworkers()
+{
+INSTALL_IPVSADM="sudo apt-get install ipvsadm"
+RESET_PORT="fuser -k -n tcp 10250"
+#REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf !('manifests') "
+REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf bootstrap-kubelet.conf kubelet.conf pki"
+REMOVE_DOCKER1="sudo yes y | apt-get purge -y docker-engine"
+REMOVE_DOCKER2="sudo yes y | apt-get purge -y docker"
+REMOVE_DOCKER3="sudo yes y | apt-get purge -y docker.io"
+REMOVE_DOCKER4="sudo yes y | apt-get purge -y docker-ce"
+REMOVE_DOCKER5="sudo yes y | apt-get purge -y docker-ce-cli"
+REMOVE_DOCKER6="sudo yes y | groupdel docker"
+RESET_KUBEADM="sudo yes y | kubeadm reset"
+REMOVE_KUBE_FILES1="sudo yes y | apt-get purge kubeadm"
+REMOVE_KUBE_FILES2="sudo yes y | apt-get purge kubectl "
+REMOVE_KUBE_FILES3="sudo yes y | apt-get purge kubelet "
+REMOVE_KUBE_FILES4="sudo yes y | apt-get purge kube* "
+REMOVE_KUBE_FILES5="sudo yes y | apt-get purge kubernetes-cni"
+REMOVE_KUBE_FILES6="sudo rm -rf ~/.kube"
+AUTO_REMOVE="sudo yes y | apt-get autoremove"
+AUTO_CLEAN="sudo yes y | apt-get autoclean"
+
+
+#Read all the Worker Node details from nodelist file.
+ while read line
+ do
+     nodeinfo="${line}"
+     nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
+     nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
+     nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${INSTALL_IPVSADM} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_PORT} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER1} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER2} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER3} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER4} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER5} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_DOCKER6} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_KUBEADM} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES1} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES2} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES3} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES4} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES5} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES6} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${AUTO_REMOVE} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${AUTO_CLEAN} < /dev/null
+ done < nodelist > /dev/null 2>&1
+
+}
+
+verify_reset_status()
+{
+echo "Success!!"
+}
+
+if [ $1 == "--help" ] || [ $1 == "-h" ];
+then
+  show_help
+  exit 0
+fi
+
+if [[ $OSPLATFORM = *Ubuntu* ]]; then
+   rollback_k8smaster
+   verify_reset_status
+else
+   echo "Script only supports Ubuntu Version."
+fi
diff --git a/scripts/kubernetes_reset.sh b/scripts/kubernetes_reset.sh
new file mode 100644 (file)
index 0000000..187355b
--- /dev/null
@@ -0,0 +1,78 @@
+########################################################################################
+#                                                                                      #
+# The script is to reset the settings on ELIOT Manager and ELIOT nodes                 #
+# before running the setup.sh file again on the same setup.                            #
+# It resets the settings of kubeadm and restarts its service                           #
+# It releases the ports used.                                                          #
+# It deletes the files created for kubernetes on node machine                          #
+# Script is tested in Ubuntu 16.04 version.                                            #
+########################################################################################
+
+# constants
+OSPLATFORM=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
+
+show_help()
+{
+  echo "The script is to reset the settings on ELIOT Manager and ELIOT nodes which "
+  echo "needs to be done before executing the setup.sh file again."
+  echo "The changes will be first executed on manager machine and then on the node machines."
+  echo "It will pick the node machine details from nodelist file"
+}
+
+# Resetting ELIOT Manager Node
+reset_k8smaster()
+{
+ sudo yes y | kubeadm reset
+ sudo apt-get install iptables
+ sudo iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
+ sudo apt-get install ipvsadm
+ sudo systemctl restart kubelet
+ sudo fuser -k -n tcp 10250
+
+reset_k8sworkers
+}
+
+#Resetting ELIOT Worker Node
+reset_k8sworkers()
+{
+RESET_KUBEADM="sudo yes y | kubeadm reset"
+INSTALL_IPVSADM="sudo apt-get install ipvsadm"
+RESTART_KUBELET="sudo systemctl restart kubelet"
+RESET_PORT="sudo fuser -k -n tcp 10250"
+#REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf !('manifests') "
+REMOVE_KUBE_FILES="cd /etc/kubernetes && sudo rm -rf bootstrap-kubelet.conf kubelet.conf pki"
+REMOVE_CADVISOR_FILES="docker rm cadvisor-iot-node1"
+
+#Read all the Worker Node details from nodelist file.
+ while read line
+ do
+     nodeinfo="${line}"
+     nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
+     nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
+     nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_KUBEADM} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${INSTALL_IPVSADM} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESTART_KUBELET} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${RESET_PORT} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_KUBE_FILES} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${REMOVE_CADVISOR_FILES} < /dev/null
+ done < nodelist > /dev/null 2>&1
+}
+
+verify_reset_status()
+{
+echo "Success!!"
+}
+
+if [ $1 == "--help" ] || [ $1 == "-h" ];
+then
+  show_help
+  exit 0
+fi
+
+if [[ $OSPLATFORM = *Ubuntu* ]]; then
+   reset_k8smaster
+   verify_reset_status
+else
+   echo "The script supports only Linux - Ubuntu"
+fi
index 4062c7e..a619e86 100755 (executable)
@@ -56,8 +56,8 @@ setup_k8sworkers()
   # Install Docker on ELIOT Node
   SETUP_WORKER_COMMON="sudo rm -rf ~/eliot &&\
                        git clone ${ELIOT_REPO} &&\
-                       cd eliot/scripts && source common.sh"
-  #SETUP_WORKER_COMMON="cd eliot/scripts && source common.sh"
+                       cd eliot/scripts/ && source common.sh"
+  #SETUP_WORKER_COMMON="cd eliot/scripts/ && source common.sh"
   SETUP_WORKER="cd eliot/scripts/ && source k8sworker.sh"
 
   KUBEADM_JOIN=$(grep "kubeadm join" ./kubeadm.log)
@@ -70,9 +70,9 @@ setup_k8sworkers()
      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
-     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON} < /dev/null 2>&1
-     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER} < /dev/null 2>&1
-     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN} < /dev/null 2>&1
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER} < /dev/null
+     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN} < /dev/null
  done < nodelist > /dev/null 2>&1
 
 }
@@ -100,9 +100,9 @@ setup_k8sworkers_centos()
 
   SETUP_WORKER_COMMON_CENTOS="sudo rm -rf ~/eliot &&\
                               git clone ${ELIOT_REPO} &&\
-                              cd eliot/scripts && source common_centos.sh"
+                              cd eliot/scripts/ && source common_centos.sh"
 
-  # SETUP_WORKER_COMMON_CENTOS="cd /root/eliot/scripts && source common_centos.sh"
+  # SETUP_WORKER_COMMON_CENTOS="cd /root/eliot/scripts/ && source common_centos.sh"
 
   KUBEADM_TOKEN=$(sudo kubeadm token create --print-join-command)
   KUBEADM_JOIN_CENTOS="sudo ${KUBEADM_TOKEN}"
@@ -110,11 +110,11 @@ setup_k8sworkers_centos()
   while read line
   do
       nodeinfo="${line}" < /dev/null 2>&1
-      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1) < /dev/null 2>&1
-      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)  < /dev/null 2>&1
-      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3) < /dev/null 2>&1
-      sudo sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON_CENTOS} < /dev/null 2>&1
-      sudo sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN_CENTOS} < /dev/null 2>&1
+      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1) < /dev/null
+      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)  < /dev/null
+      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3) < /dev/null
+      sudo sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON_CENTOS} < /dev/null
+      sudo sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN_CENTOS} < /dev/null
   done < nodelist > /dev/null 2>&1
 
 }