setup-cni: Fix typo, allow absolute exec
[iec.git] / 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/scripts/ && source k8s_common.sh"
32
33   #Automatic deploy the K8s environments on Master node
34   SETUP_MASTER="cd iec/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/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/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/scripts && source setup-cni.sh"
49   sshpass -p ${K8S_MASTERPW} ssh ${HOST_USER}@${K8S_MASTER_IP} ${SETUP_CNI}
50 }
51
52
53 PASSWD=${4:-"123456"}
54 HOST_USER=${3:-"iec"}
55
56 K8S_MASTER_IP=${1:-"10.169.40.171"}
57 K8S_MASTERPW=${PASSWD}
58
59 K8S_WORKER01_IP=${2:-"10.169.41.172"}
60 K8S_WORKERPW=${PASSWD}
61
62 REPO_URL="https://gerrit.akraino.org/r/iec"
63 LOG_FILE="kubeadm.log"
64
65 if [ -f "./${LOG_FILE}" ]; then
66   rm "${LOG_FILE}"
67 fi
68
69 #
70 # Init
71 #
72 if [ $# -lt 4 ]
73 then
74   display_help
75   exit 0
76 fi
77
78
79 deploy_k8s