K8s version update 1.17.2
[eliot.git] / blueprints / iotgateway / scripts / kubeedge / 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 echo "**********************************************************************"
12 echo "Kubeedge-v1.1.0 Installation------------------------------------------STARTED"
13
14 # constants
15
16 VERSION="v1.1.0"
17 OS="linux"
18 ARCH="amd64"
19
20 PATH_OF_EDGECORE="/etc/kubeedge-v1.1.0-linux-amd64/edge/edgecore"
21
22 initialize_k8s_cluster()
23 {
24    #cd ../
25    #./setup.sh
26    cp /etc/kubernetes/admin.conf /root/.kube/config
27    #source common.sh
28    #source k8smaster.sh
29 }
30
31 kubeedge_tar_untar()
32 {
33
34    curl -L "https://github.com/kubeedge/kubeedge/releases/download/${VERSION}/kubeedge-${VERSION}-${OS}-${ARCH}.tar.gz" \
35    --output kubeedge-${VERSION}-${OS}-${ARCH}.tar.gz && sudo tar -xf kubeedge-${VERSION}-${OS}-${ARCH}.tar.gz  -C /etc
36
37 }
38
39 generate_certs()
40 {
41    echo "generate_certs started"
42    wget -L https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/tools/certgen.sh
43
44    chmod +x certgen.sh
45    bash -x ./certgen.sh genCertAndKey edge
46
47    echo "generate_certs ended"
48
49 }
50
51 initialize_yaml()
52 {
53    echo "initalize_yaml started"
54    wget -L https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/crds/devices/devices_v1alpha1_devicemodel.yaml
55
56    chmod +x devices_v1alpha1_devicemodel.yaml
57
58    kubectl create -f devices_v1alpha1_devicemodel.yaml
59
60    wget -L https://raw.githubusercontent.com/kubeedge/kubeedge/master/build/crds/devices/devices_v1alpha1_device.yaml
61
62    chmod +x devices_v1alpha1_device.yaml
63    kubectl create -f devices_v1alpha1_device.yaml
64    echo "initialize_yaml ended"
65 }
66
67 # Run cloudcore
68
69 cloudcore_start()
70 {
71    echo "cloudcore_start started"
72    cp controller.yaml /etc/kubeedge-${VERSION}-${OS}-${ARCH}/cloud/cloudcore/conf/controller.yaml
73    cd /etc/kubeedge-${VERSION}-${OS}-${ARCH}/cloud/cloudcore
74    nohup ./cloudcore > cloudcore.log 2>&1 &
75    echo "cloudcore_start ended"
76 }
77
78 edge_modify()
79 {
80    sed "s/0.0.0.0/${MASTERNODEIP}/" /etc/kubeedge-${VERSION}-${OS}-${ARCH}/edge/conf/edge.yaml > /etc/kubeedge-${VERSION}-${OS}-${ARCH}/edge/conf/edge_new.yaml
81    #rm -rf /etc/kubeedge-${VERSION}-${OS}-${ARCH}/edge/conf/edge.yaml
82    mv /etc/kubeedge-${VERSION}-${OS}-${ARCH}/edge/conf/edge_new.yaml /etc/kubeedge-${VERSION}-${OS}-${ARCH}/edge/conf/edge.yaml
83
84 }
85
86 exec_edge()
87 {
88     echo "exec_edge started"
89
90     sshpass -p ${EDGENODEPASSWORD} \
91     scp -r $KUBEEDGE_ETC \
92     ${EDGENODEUSR}@${EDGENODEIP}:/etc
93
94     sshpass -p ${EDGENODEPASSWORD} \
95     scp -r $KUBEEDGE_VERSION_ETC \
96     ${EDGENODEUSR}@${EDGENODEIP}:/etc
97
98     sshpass -p ${EDGENODEPASSWORD} ssh ${EDGENODEUSR}@${EDGENODEIP} \
99     nohup $PATH_OF_EDGECORE > edgecore.log 2>&1 &
100     echo "exec_edge ended"
101 }
102
103 apply_node_json()
104 {
105    echo "apply_node_json started"
106    echo $(pwd)
107    cd ${PATH_OF_KUBEEDGE}
108    kubectl apply -f node.json
109    echo "apply_node_json ended"
110 }
111
112
113
114 # start
115 source config_kubeedge
116 initialize_k8s_cluster
117
118 # sleep added for k8s kube-system pods to be up
119
120 #sleep 240
121
122 kubeedge_tar_untar
123
124 generate_certs
125
126 initialize_yaml
127
128 cloudcore_start
129 edge_modify
130 exec_edge > /dev/null 2>&1
131
132 apply_node_json
133
134 echo "Kubeedge-v1.1.0 Installation------------------------------------------SUCCESS"
135 echo "************************************************************************"