K8S Verify script added
[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
73
74 }
75
76
77 # Start
78 #
79
80 if [ $1 == "--help" ] || [ $1 == "-h" ];
81 then
82   show_help
83   exit 0
84 fi
85
86
87 setup_k8smaster