Merge "Scripts for Prometheus & cAdvisor installation"
authorkhemendra kumar <khemendra.kumar13@gmail.com>
Fri, 7 Jun 2019 09:20:54 +0000 (09:20 +0000)
committerGerrit Code Review <gerrit@akraino.org>
Fri, 7 Jun 2019 09:20:54 +0000 (09:20 +0000)
scripts/ci_management/cleanup_control.sh [new file with mode: 0755]
scripts/ci_management/cleanup_edge.sh [new file with mode: 0644]
scripts/ci_management/cleanup_edge_final.sh [moved from scripts/ci_management/cleanup.sh with 52% similarity]
scripts/ci_management/cleanup_master.sh [new file with mode: 0755]
scripts/ci_management/cleanup_prom_cadvisor.sh [new file with mode: 0755]
scripts/ci_management/uninstall_cadvisor.sh [new file with mode: 0755]
scripts/ci_management/uninstall_prometheus.sh [new file with mode: 0755]
scripts/setup.sh
scripts/src/config_kubeedge [changed mode: 0644->0755]
scripts/src/kubeedge_setup.sh
scripts/verifyk8s.sh [new file with mode: 0755]

diff --git a/scripts/ci_management/cleanup_control.sh b/scripts/ci_management/cleanup_control.sh
new file mode 100755 (executable)
index 0000000..574552b
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# constants
+
+TESTYAML="testk8s-nginx.yaml"
+
+# start
+
+source ../src/config_kubeedge
+cd
+kubectl delete -f $TESTYAML
+
+sshpass -p ${EDGENODEPASSWORD} \
+scp ${PATH_OF_ELIOTFOLDER}/scripts/ci_management/cleanup_edge.sh \
+${EDGENODEUSR}@${EDGENODEIP}:$HOME_EDGENODE
+
+sshpass -p ${EDGENODEPASSWORD} ssh ${EDGENODEUSR}@${EDGENODEIP} \
+source cleanup_edge.sh
+
+cd $PATH_OF_ELIOTFOLDER/scripts/ci_management
+source cleanup_master.sh
+
+sshpass -p ${EDGENODEPASSWORD} \
+scp ${PATH_OF_ELIOTFOLDER}/scripts/ci_management/cleanup_edge_final.sh \
+${EDGENODEUSR}@${EDGENODEIP}:$HOME_EDGENODE
+
+sshpass -p ${EDGENODEPASSWORD} ssh ${EDGENODEUSR}@${EDGENODEIP} \
+source cleanup_edge_final.sh
diff --git a/scripts/ci_management/cleanup_edge.sh b/scripts/ci_management/cleanup_edge.sh
new file mode 100644 (file)
index 0000000..646f5be
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# constants
+
+NGINX=$(sudo docker ps | grep nginx | wc -l)
+KUBEPROXY=$(sudo docker ps | grep k8s.gcr.io | wc -l)
+CONSTZERO="0"
+
+# start
+
+source config_kubeedge
+source ~/.profile
+
+cd
+
+if [ -d "/root/go/src/github.com/kubeedge/kubeedge/keadm" ]; then
+   cd $GOPATH/src/github.com/kubeedge/kubeedge/keadm
+   ./kubeedge reset --k8sserverip $MASTERNODEIP:8080
+fi
+
+cd /etc/kubeedge
+
+if [ -f "certs.tgz" ]; then
+   sudo rm -rf certs.tgz
+fi
+
+if [ -d "/etc/kubeedge/ca" ]; then
+   sudo rm -rf /etc/kubeedge/ca
+fi
+
+if [ -d "/etc/kubeedge/certs" ]; then
+   sudo rm -rf /etc/kubeedge/certs
+fi
+
+if [ -d "/root/go/src" ]; then
+   sudo rm -rf /root/go/src
+fi
+
+# stop binaries edge_core
+cd /usr/local/bin
+
+if [ -f "edge_core" ]; then
+   sudo rm edge_core
+fi
+
similarity index 52%
rename from scripts/ci_management/cleanup.sh
rename to scripts/ci_management/cleanup_edge_final.sh
index 3aa86e3..a42e875 100644 (file)
@@ -8,22 +8,21 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-# start
-
-kubeedge reset
+# constants
 
-reset="kubeedge reset --k8sserverip ${masternodeip}:8080"
+NGINX=$(sudo docker ps | grep nginx | wc -l)
+KUBEPROXY=$(sudo docker ps | grep k8s.gcr.io | wc -l)
+CONSTZERO="0"
 
-while read line
-do
-    nodeinfo="${line}"
-    nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
-    nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
-    nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
-    masternodeip=$(echo ${nodeinfo} | cut -d"|" -f3)
-
-    sshpass -p ${nodepaswd} \
-    kubeedge reset --k8sserverip ${masternodeip}:8080
+# start
 
-done < nodelist
+echo "nginx container stop"
+if [ $NGINX != $CONSTZERO ]; then
+   sudo docker kill $(docker ps -q --filter ancestor=nginx:1.15.12 )
+fi
 
+echo "kubeproxy container stop"
+if [ $KUBEPROXY != $CONSTZERO ]; then
+   sudo docker kill $(docker ps -q --filter ancestor=k8s.gcr.io/kube-proxy:v1.14.2 )
+fi
+echo "Finished"
diff --git a/scripts/ci_management/cleanup_master.sh b/scripts/ci_management/cleanup_master.sh
new file mode 100755 (executable)
index 0000000..636535d
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# constants
+
+TESTYAML="testk8s-nginx.yaml"
+SUPERUSER="root"
+value=$(whoami)
+
+# start
+
+# kubeedge reset internally undo the things done by ./kubeedge init
+
+if [ -d "/root/go/src/github.com/kubeedge/kubeedge/keadm" ]; then
+   cd /root/go/src/github.com/kubeedge/kubeedge/keadm
+   ./kubeedge reset
+fi
+
+# delete the previously existing certificates
+
+if [ -d "/etc/kubeedge/ca" ]; then
+   sudo rm -rf /etc/kubeedge/ca
+fi
+
+if [ -d "/etc/kubeedge/certs" ]; then
+   cd /etc/kubeedge
+   sudo rm -rf certs
+fi
+
+cd /etc/kubeedge
+if [ -f "certs.tgz" ]; then
+   sudo rm certs.tgz
+fi
+
+# delete the kubeedge code
+
+if [ -d "/root/go/src" ]; then
+   cd /root/go
+   sudo rm -rf src
+fi
+
+# stop binaries edge_core edgecontroller
+
+cd /usr/local/bin
+
+if [ -f "edge_core" ]; then
+   sudo rm edge_core
+fi
+
+if [ -f "edgecontroller" ]; then
+   sudo rm edgecontroller
+fi
+
+if [ $value != $SUPERUSER ]; then
+   sudo su
+fi
+
+cd
+
+if [ -f $TESTYAML ]; then
+   sudo rm $TESTYAML
+fi
+
diff --git a/scripts/ci_management/cleanup_prom_cadvisor.sh b/scripts/ci_management/cleanup_prom_cadvisor.sh
new file mode 100755 (executable)
index 0000000..223071f
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# The script is to stop and remove the prometheus and cadvisor containers from 
+# ELIOT Manager and ELIOT Edge Node respectively.
+
+# stop prometheus in ELIOT Manager
+source uninstall_prometheus.sh | tee uninstall_prometheus.log
+
+#stop cadvisor statement executed at ELIOT Edge Node
+stop_cadvisor_atedge="cd AfterRelease1/eliot/scripts/ci_management && source uninstall_cadvisor.sh"
+# 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} ${stop_cadvisor_atedge}
+done < ../nodelist > /dev/null 2>&1
+
diff --git a/scripts/ci_management/uninstall_cadvisor.sh b/scripts/ci_management/uninstall_cadvisor.sh
new file mode 100755 (executable)
index 0000000..78fc57a
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+
+#stop cadvisor statement executed at ELIOT Edge Node
+if [ $(sudo docker ps | grep cadvisor | wc -l) -gt 0 ];then
+ sudo docker stop $(sudo docker ps | grep cadvisor | awk '{ print $1 }')
+fi
+
+if [ $(sudo docker ps -a | grep cadvisor | wc -l) -gt 0 ];then
+  sudo docker rm $(sudo docker ps -a | grep cadvisor | awk '{ print $1 }')
+fi
diff --git a/scripts/ci_management/uninstall_prometheus.sh b/scripts/ci_management/uninstall_prometheus.sh
new file mode 100755 (executable)
index 0000000..63be6ad
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+
+# stop prometheus in ELIOT Manager
+
+if [ $(sudo docker ps | grep prometheus | wc -l) -gt 0 ];then 
+    echo "Stopping prometheus container id :- $(sudo docker ps | grep prometheus | awk '{ print $1 }')"
+    sudo docker stop $(sudo docker ps | grep prometheus | awk '{ print $1 }')
+fi
+if [ $(sudo docker ps -a | grep prometheus | wc -l) -gt 0 ];then
+    echo "Removing prometheus container id $(sudo docker ps -a | grep prometheus | awk '{ print $1 }')"
+    sudo docker rm $(sudo docker ps -a | grep prometheus | awk '{ print $1 }')
+fi
+
index e5da102..9efe547 100755 (executable)
@@ -74,6 +74,31 @@ setup_k8sworkers()
 }
 
 
+#verify kubernetes setup by deploying nginx server.
+
+verify_k8s_status(){
+  set -o xtrace
+  source verifyk8s.sh | tee verifyk8s.log
+}
+
+install_cadvisor_edge(){
+ set -o xtrace
+ SETUP_CADVISOR_ATEDGE="cd AfterRelease1/eliot/scripts/ && source cadvisorsetup.sh" 
+ 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_CADVISOR_ATEDGE} < /dev/null
+ done < nodelist
+}
+
+install_prometheus(){
+set -o xtrace
+source prometheus.sh | tee install_prometheus.log
+}
+
 # Start
 #
 
@@ -85,3 +110,11 @@ fi
 
 
 setup_k8smaster
+sleep 20
+verify_k8s_status
+
+install_cadvisor_edge
+sleep 10
+install_prometheus
+sleep 5 
+sudo docker ps | grep prometheus
old mode 100644 (file)
new mode 100755 (executable)
index 2d11960..3fa3fdc
@@ -1,6 +1,26 @@
-edgenodeusr="root"
-edgenodeip="10.10.0.54"
-edgenodepassword="Huawei@akraino"
-masternodeusr="root"
-masternodeip="10.10.0.45"
-masternodepassword="Huawei@akraino"
+# edge node user name
+EDGENODEUSR=""
+
+# edge node ip
+EDGENODEIP=""
+
+# edge node password
+EDGENODEPASSWORD=""
+
+# master node user name
+MASTERNODEUSR=""
+
+# master node ip
+MASTERNODEIP=""
+
+# master node password
+MASTERNODEPASSWORD=""
+
+# eliot source code path including eliot folder
+PATH_OF_ELIOTFOLDER=""
+
+# home path of edge node
+HOME_EDGENODE=""
+
+# edgenode id for kubeedge configuration
+EDGENODEID=""
index 6cfc2c3..e75c1be 100755 (executable)
@@ -14,23 +14,23 @@ take_keedge(){
    source ~/.profile
    cd $GOPATH/src/github.com/kubeedge/kubeedge/keadm
    make
-   #kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
-   #kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
 }
 
 source config_kubeedge
-common_steps="git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge && \
+
+common_steps="echo $GOPATH && \
+echo $HOME && \
+echo $(whoami) && \
+sudo git clone https://github.com/kubeedge/kubeedge.git $GOPATH/src/github.com/kubeedge/kubeedge && \
 source ~/.profile && \
+cd $GOPATH/src && \
+sudo chmod -R 777 github.com && \
 cd $GOPATH/src/github.com/kubeedge/kubeedge/keadm && \
-make && \
-chmod +x kubeedge"
-
-certif_copy="cd /etc/kubeedge &&\
-scp certs.tar.gz"
+make"
 
 edge_start="cd $GOPATH/src/github.com/kubeedge/kubeedge/keadm && \
-chmod +x kubeedge && \
-./kubeedge join --edgecontrollerip=$masternodeip --edgenodeid=eliotedge02 --k8sserverip=$masternodeip:8080"
+sudo chmod +x kubeedge && \
+sudo ./kubeedge join --edgecontrollerip=$MASTERNODEIP --edgenodeid=$EDGENODEID --k8sserverip=$MASTERNODEIP:8080"
 
 execute_keedge_controller(){
    cd $GOPATH/src/github.com/kubeedge/kubeedge/keadm
@@ -38,41 +38,46 @@ execute_keedge_controller(){
    ./kubeedge init
 }
 
-
 exec_edge(){
 
-   cd $HOME/eliot/scripts/src
-   sshpass -p ${edgenodepassword} scp $HOME/release/eliot/scripts/src/config_kubeedge ${edgenodeusr}@${edgenodeip}:/root
+   cd $PATH_OF_ELIOTFOLDER/scripts/src
 
-   sshpass -p ${edgenodepassword} ssh ${edgenodeusr}@${edgenodeip} \
+   sshpass -p ${EDGENODEPASSWORD} \
+   scp $PATH_OF_ELIOTFOLDER/scripts/src/config_kubeedge \
+   ${EDGENODEUSR}@${EDGENODEIP}:$HOME_EDGENODE
+
+   sshpass -p ${EDGENODEPASSWORD} ssh ${EDGENODEUSR}@${EDGENODEIP} \
    source config_kubeedge
-   
+
    source config_kubeedge
-   sshpass -p ${edgenodepassword} ssh ${edgenodeusr}@${edgenodeip} ${common_steps} < /dev/null
-echo "after common_steps"
-   sshpass -p ${edgenodepassword} scp /etc/kubeedge/certs.tgz ${edgenodeusr}@${edgenodeip}:/etc/kubeedge
+   sshpass -p ${EDGENODEPASSWORD} \
+   ssh ${EDGENODEUSR}@${EDGENODEIP} ${common_steps} < /dev/null
 
-   sshpass -p ${edgenodepassword} \
-   ssh ${edgenodeusr}@${edgenodeip} \
+   echo "After cloning the code in ELIOT edge node"
+   sshpass -p ${EDGENODEPASSWORD} \
+   scp /etc/kubeedge/certs.tgz ${EDGENODEUSR}@${EDGENODEIP}:/etc/kubeedge
+
+   sshpass -p ${EDGENODEPASSWORD} \
+   ssh ${EDGENODEUSR}@${EDGENODEIP} \
    tar -xvzf /etc/kubeedge/certs.tgz --directory /etc/kubeedge
-   
-   sshpass -p ${edgenodepassword} ssh ${edgenodeusr}@${edgenodeip} ${edge_start} < /dev/null
+
+   sshpass -p ${EDGENODEPASSWORD} \
+   ssh ${EDGENODEUSR}@${EDGENODEIP} ${edge_start} < /dev/null
 }
 
 # start
 
 source config_kubeedge
-#sample
-#return
+
 take_keedge
 
 execute_keedge_controller
 
-#sample
-#execute_edge
 exec_edge
-kubectl get nodes
 
-kubectl create -f deployment.yaml
+sleep 10
+sudo kubectl get nodes
+
+chmod +x $PATH_OF_ELIOTFOLDER/scripts/verifyk8s.sh
+source $PATH_OF_ELIOTFOLDER/scripts/verifyk8s.sh
 
-kubectl get pods
diff --git a/scripts/verifyk8s.sh b/scripts/verifyk8s.sh
new file mode 100755 (executable)
index 0000000..08fb3a9
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+NGINXDEP=~/testk8s-nginx.yaml
+
+cat <<EOF > "${NGINXDEP}"
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: nginx-deployment
+  labels:
+    app: nginx
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: nginx
+  template:
+    metadata:
+      labels:
+        app: nginx
+    spec:
+      containers:
+        - name: nginx
+          image: nginx:1.15.12
+          ports:
+            - containerPort: 80
+              hostPort: 80
+EOF
+
+#check if nginx is already deployed
+if ! kubectl get pods | grep nginx; then
+  kubectl create -f ~/testk8s-nginx.yaml
+fi
+
+#To check whether the deployment is succesesfull
+retry=10
+while [ $retry -gt 0 ]
+do
+  if [ 2 == "$(kubectl get pods | grep -c -e STATUS -e Running)" ]; then
+    break
+  fi
+  ((retry-=1)) 
+  sleep 10
+done
+[ $retry -gt 0 ] || exit 1