Merge "add the jenkins job yaml and scripts"
authorwutianwei <wutianwei1@huawei.com>
Thu, 26 Sep 2019 03:53:56 +0000 (03:53 +0000)
committerGerrit Code Review <gerrit@akraino.org>
Thu, 26 Sep 2019 03:53:56 +0000 (03:53 +0000)
scripts/common_centos.sh
scripts/k8smaster.sh
scripts/k8smaster_centos.sh
scripts/kubernetes_cleanup.sh [new file with mode: 0644]
scripts/kubernetes_reset.sh [new file with mode: 0644]
scripts/setup.sh
scripts/src/kubeedge_setup.sh

index 5532ac2..1fb51b3 100755 (executable)
@@ -52,6 +52,13 @@ gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
         https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
 EOF
 
+# Set SELinux in permissive mode (effectively disabling it)
+setenforce 0
+sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
+
+yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
+systemctl enable --now kubelet
+
 sudo yum install -y kubeadm-${KUBE_VERSION}
 sudo systemctl start docker && sudo systemctl enable docker
 
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"
index 2681b6e..c78bc0d 100755 (executable)
@@ -25,12 +25,6 @@ rm hostname.tmp
 sudo yum install -y kubelet-${KUBE_VERSION} kubectl-${KUBE_VERSION} \
 kubernetes-cni-${KUBERNETES_CNI}
 
-sudo systemctl start kubelet #&& sudo systemctl enable kubelet
-
-sudo docker info | grep -i cgroup
-sudo sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' \
-/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
-
 sudo systemctl daemon-reload
 sudo systemctl restart kubelet
 
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 07cecd3..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)
@@ -87,9 +87,9 @@ setup_k8smaster_centos()
   # Setup ELIOT Node
   setup_k8sworkers_centos
 
-  cd cni/calico
-  kubectl apply -f rbac.yaml
-  kubectl apply -f calico.yaml
+  kubectl apply -f cni/calico/rbac.yaml
+  kubectl apply -f cni/calico/calico.yaml
+
 }
 
 
@@ -100,26 +100,26 @@ 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"
 
   KUBEADM_TOKEN=$(sudo kubeadm token create --print-join-command)
   KUBEADM_JOIN_CENTOS="sudo ${KUBEADM_TOKEN}"
-
- # 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} ${SETUP_WORKER_COMMON_CENTOS} < /dev/null
-     #sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_CENTOS} < /dev/null
-     sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN_CENTOS} < /dev/null
- done < nodelist
+  # Read all the Worker Node details from nodelist file.
+  while read line
+  do
+      nodeinfo="${line}" < /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
 
 }
 
-#verify kubernetes setup by deploying nginx server.
+# verify kubernetes setup by deploying nginx server.
 
 verify_k8s_status(){
   set -o xtrace
@@ -128,7 +128,7 @@ verify_k8s_status(){
 
 install_cadvisor_edge(){
  set -o xtrace
- SETUP_CADVISOR_ATEDGE="cd eliot/scripts/ && source cadvisorsetup.sh" 
+ SETUP_CADVISOR_ATEDGE="cd eliot/scripts/ && source cadvisorsetup.sh"
  while read line
  do
      nodeinfo="${line}"
index 4d6b606..86f6bbc 100755 (executable)
@@ -11,6 +11,7 @@
 #Constants
 KUBEEDGE_SRC="$GOPATH/src/github.com/kubeedge/kubeedge"
 KUBEEDGE_BIN="$GOPATH/src/github.com/kubeedge/kubeedge/keadm"
+VERIFY_K8S="$PATH_OF_ELIOTFOLDER/scripts/verifyk8s.sh"
 
 { set +x; } > /dev/null 2>&1
 
@@ -119,6 +120,6 @@ else
     sudo chown "$(id -u)":"$(id -g)" "${HOME}/.kube/config"
 fi
 
-chmod +x $PATH_OF_ELIOTFOLDER/scripts/verifyk8s.sh
-source $PATH_OF_ELIOTFOLDER/scripts/verifyk8s.sh
+chmod +x $VERIFY_K8S
+source $VERIFY_K8S