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