[scripts] Cleanup intermediate files
[iec.git] / src / foundation / scripts / startup.sh
1 #!/bin/bash
2 #Install the k8s-master & k8s-worker node from Mgnt node
3 #
4 set -e
5
6 #
7 # Displays the help menu.
8 #
9 display_help () {
10   echo "Usage: $0 [master ip] [worker ip] [user] [password] "
11   echo " "
12   echo "There should be an user which will be used to install the "
13   echo "corresponding software on master & worker node. This user can "
14   echo "run the sudo command without input password on the hosts."
15   echo " "
16   echo "Example usages:"
17   echo "   ./startup.sh 10.169.40.171 10.169.41.172 iec 123456"
18 }
19
20
21
22 #
23 # Deploy k8s with calico.
24 #
25 deploy_k8s () {
26   set -o xtrace
27
28   INSTALL_SOFTWARE="sudo apt-get update && sudo apt-get install -y git &&\
29            sudo rm -rf ~/.kube ~/iec &&\
30            git clone ${REPO_URL} &&\
31            cd iec/src/foundation/scripts/ && source k8s_common.sh"
32
33   #Automatic deploy the K8s environments on Master node
34   SETUP_MASTER="cd iec/src/foundation/scripts/ && source k8s_master.sh ${K8S_MASTER_IP}"
35   sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${INSTALL_SOFTWARE}
36   sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_MASTER} | tee kubeadm.log
37
38   KUBEADM_JOIN_CMD=$(grep "kubeadm join " ./kubeadm.log)
39
40   #Automatic deploy the K8s environments on Worker node
41   SETUP_WORKER="cd iec/src/foundation/scripts/ && source k8s_worker.sh"
42   sshpass -p ${K8S_WORKERPW} ssh ${HOST_USER}@${K8S_WORKER01_IP} ${INSTALL_SOFTWARE}
43   sshpass -p ${K8S_WORKERPW} ssh ${HOST_USER}@${K8S_WORKER01_IP} "echo \"sudo ${KUBEADM_JOIN_CMD}\" >> ./iec/src/foundation/scripts/k8s_worker.sh"
44   sshpass -p ${K8S_WORKERPW} ssh ${HOST_USER}@${K8S_WORKER01_IP} ${SETUP_WORKER}
45
46   #Deploy etcd & CNI from master node
47   #There may be more options in future. e.g: Calico, Contiv-vpp, Ovn-k8s ...
48   SETUP_CNI="cd iec/src/foundation/scripts && source setup-cni.sh"
49   sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_CNI}
50 }
51
52 #
53 # Check the K8s environments
54 #
55 check_k8s_status(){
56   set -o xtrace
57
58   VERIFY_K8S="cd iec/src/foundation/scripts/ && source nginx.sh"
59   sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${VERIFY_K8S}
60
61   sleep 30
62 }
63
64
65 PASSWD=${4:-"123456"}
66 HOST_USER=${3:-"iec"}
67
68 K8S_MASTER_IP=${1:-"10.169.40.171"}
69 K8S_MASTERPW=${PASSWD}
70
71 K8S_WORKER01_IP=${2:-"10.169.41.172"}
72 K8S_WORKERPW=${PASSWD}
73
74 REPO_URL="https://gerrit.akraino.org/r/iec"
75 LOG_FILE="kubeadm.log"
76
77 if [ -f "./${LOG_FILE}" ]; then
78   rm "${LOG_FILE}"
79 fi
80
81 #
82 # Init
83 #
84 if [ $# -lt 4 ]
85 then
86   display_help
87   exit 0
88 fi
89
90
91 deploy_k8s
92
93 check_k8s_status