e1b04a4db7040e2080c4970f1600804b0fb38f2d
[eliot.git] / scripts / setup.sh
1 #!/bin/bash -ex
2 ##############################################################################
3 # Copyright (c) 2019 Huawei Tech and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 ########################################################################################
12 #                                                                                      #
13 # The script is to setup the ELIOT Manager and ELIOT nodes.                            #
14 # It installs Docker in both ELIOT Manager and ELIOT node.                             #
15 # It installs Kubernetes. In the ELIOT Manager kubeadm, kubelet, kubectl is installed. #
16 # In ELIOT Edge Node it will install kubeadn, kubelet.                                 #
17 # Script is tested in Ubuntu 16.04 version.                                            #
18 # sshpass needs to be installed before executing this script.                          #
19 ########################################################################################
20
21 show_help()
22 {
23   echo "The script helps in setting up the ELIOT Toplogy Infrastrucutre"
24   echo "The setup installs Docker, K8S Master and K8S worker nodes in  "
25   echo "ELIOT Manager and ELIOT Workder Nodes respectively "
26   echo "After completion of script execution execute command: "
27   echo "kubectl get nodes to check whether the connection between "
28   echo "ELIOT Manager and ELIOT Nodes are established"
29   echo ""
30   echo "Nodelist file should have the details of Worker Nodes in the format of:"
31   echo "EliotNodeUserName|EliotNodeIP|EliotNodePasswor"
32   echo "Each line should have detail of one ELIOT Node only"
33 }
34
35 # Setting up ELIOT Manager Node.
36 # Installing Docker, K8S and Initializing K8S Master
37 setup_k8smaster()
38 {
39   set -o xtrace
40   sudo rm -rf ~/.kube
41   source common.sh | tee eliotcommon.log
42   source k8smaster.sh | tee kubeadm.log
43   # Setup ELIOT Node
44   setup_k8sworkers
45 }
46
47 setup_k8sworkers()
48 {
49   set -o xtrace
50
51   # Install Docker on ELIOT Node
52   ELIOT_REPO="https://gerrit.akraino.org/r/eliot"
53   SETUP_WORKER_COMMON="sudo rm -rf ~/eliot &&\
54                        git clone ${ELIOT_REPO} &&\
55                        cd eliot/scripts && source common.sh"
56   #SETUP_WORKER_COMMON="cd eliot/scripts && source common.sh"
57   SETUP_WORKER="cd eliot/scripts/ && source k8sworker.sh"
58
59   KUBEADM_JOIN=$(grep "kubeadm join " ./kubeadm.log)
60   KUBEADM_JOIN="sudo ${KUBEADM_JOIN}"
61
62  # Read all the Worker Node details from nodelist file.
63  while read line
64  do
65      nodeinfo="${line}"
66      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
67      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
68      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
69      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER_COMMON} < /dev/null
70      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_WORKER} < /dev/null
71      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${KUBEADM_JOIN} < /dev/null
72  done < nodelist > /dev/null 2>&1
73
74 }
75
76
77 #verify kubernetes setup by deploying nginx server.
78
79 verify_k8s_status(){
80   set -o xtrace
81   source verifyk8s.sh | tee verifyk8s.log
82 }
83
84 install_cadvisor_edge(){
85  set -o xtrace
86  SETUP_CADVISOR_ATEDGE="cd eliot/scripts/ && source cadvisorsetup.sh" 
87  while read line
88  do
89      nodeinfo="${line}"
90      nodeusr=$(echo ${nodeinfo} | cut -d"|" -f1)
91      nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
92      nodepaswd=$(echo ${nodeinfo} | cut -d"|" -f3)
93      sshpass -p ${nodepaswd} ssh ${nodeusr}@${nodeip} ${SETUP_CADVISOR_ATEDGE} < /dev/null
94  done < nodelist > /dev/null 2>&1
95 }
96
97 install_prometheus(){
98 set -o xtrace
99 source prometheus.sh | tee install_prometheus.log
100 }
101
102 # Start
103 #
104
105 if [ $1 == "--help" ] || [ $1 == "-h" ];
106 then
107   show_help
108   exit 0
109 fi
110
111
112 setup_k8smaster
113 sleep 20
114 verify_k8s_status
115
116 install_cadvisor_edge
117 sleep 10
118 install_prometheus
119 sleep 5 
120 sudo docker ps | grep prometheus