Merge "logs uCPE updated"
[eliot.git] / blueprints / iotgateway / scripts / src / kubeedge_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 #Constants
12 KUBEEDGE_SRC="$GOPATH/src/github.com/kubeedge/kubeedge"
13 KUBEEDGE_BIN="$GOPATH/src/github.com/kubeedge/kubeedge/keadm"
14 VERIFY_K8S="$PATH_OF_ELIOTFOLDER/scripts/verifyk8s.sh"
15
16 { set +x; } > /dev/null 2>&1
17
18 if [ -n "$1" ]; then
19
20 if [ "$1" != "--help" ]; then
21     echo ""
22     echo "Usage of the command is wrong.. Please type ./kubeedge_setup.sh --help for more details"
23     echo ""
24     exit 0
25 fi
26
27 fi
28
29 if [ "$1" == "--help" ]; then
30     echo ""
31     echo "This script will setup the kubeedge installation on Eliot master and Eliot edge"
32     echo "Before Executing this, add Eliot master and Eliot edge details in config_kubeedge file"
33     echo ""
34     exit 0; set -x;
35 fi
36
37 # take_keedge will download the source code of kubeedge in master and in edge
38
39 take_keedge(){
40
41     source ~/.profile
42     git clone https://github.com/kubeedge/kubeedge.git \
43     $KUBEEDGE_SRC
44     cd $KUBEEDGE_BIN
45     make
46 }
47
48 source config_kubeedge > /dev/null 2>&1
49
50 common_steps="echo $GOPATH && \
51 git clone https://github.com/kubeedge/kubeedge.git $KUBEEDGE_SRC && \
52 source ~/.profile && \
53 cd $GOPATH/src && \
54 sudo chmod -R 777 github.com && \
55 cd $KUBEEDGE_BIN && \
56 make"
57
58 edge_start="cd $KUBEEDGE_BIN && \
59 sudo chmod +x keadm && \
60 sudo ./keadm join --edgecontrollerip=$MASTERNODEIP --edgenodeid=$EDGENODEID \
61 --k8sserverip=$MASTERNODEIP:8080"
62
63 # Initialisation of ELIOT master with kubeedge
64
65 execute_keedge_controller(){
66     cd $KUBEEDGE_BIN
67     sudo chmod +x keadm
68     sudo ./keadm init
69 }
70
71 # Initialisation of Eliot edge with kubeedge
72
73 exec_edge(){
74
75     cd $PATH_OF_ELIOTFOLDER/scripts/src
76
77     sshpass -p ${EDGENODEPASSWORD} \
78     scp $PATH_OF_ELIOTFOLDER/scripts/src/config_kubeedge \
79     ${EDGENODEUSR}@${EDGENODEIP}:$HOME_EDGENODE
80
81     sshpass -p ${EDGENODEPASSWORD} ssh ${EDGENODEUSR}@${EDGENODEIP} \
82     source config_kubeedge
83
84     source config_kubeedge > /dev/null 2>&1
85     sshpass -p ${EDGENODEPASSWORD} \
86     ssh ${EDGENODEUSR}@${EDGENODEIP} ${common_steps}
87
88     echo "After cloning the code in ELIOT edge node"
89     sshpass -p ${EDGENODEPASSWORD} \
90     scp /etc/kubeedge/certs.tgz ${EDGENODEUSR}@${EDGENODEIP}:$HOME_EDGENODE
91
92     sshpass -p ${EDGENODEPASSWORD} \
93     ssh ${EDGENODEUSR}@${EDGENODEIP} \
94     sudo tar -xvzf $HOME/certs.tgz --directory /etc/kubeedge
95
96     sshpass -p ${EDGENODEPASSWORD} \
97     ssh ${EDGENODEUSR}@${EDGENODEIP} ${edge_start}
98 }
99
100 # start
101
102 source config_kubeedge > /dev/null 2>&1
103
104 take_keedge
105
106 execute_keedge_controller
107
108 exec_edge > /dev/null 2>&1
109
110 sleep 10
111 sudo kubectl get nodes
112
113 if [ "$(id -u)" = 0 ]; then
114     echo "export KUBECONFIG=/etc/kubernetes/admin.conf" | \
115 tee -a "${HOME}/.profile"
116     source "${HOME}/.profile"
117 else
118     mkdir -p "${HOME}/.kube"
119     sudo cp -i /etc/kubernetes/admin.conf "${HOME}/.kube/config"
120     sudo chown "$(id -u)":"$(id -g)" "${HOME}/.kube/config"
121 fi
122
123 chmod +x $VERIFY_K8S
124 source $VERIFY_K8S
125