upgrade rancher/k8s to 1.6.25
[logging-analytics.git] / deploy / aws / oom_cluster_host_install.sh
1 #!/bin/bash
2 #############################################################################
3 #
4 # Copyright © 2018 Amdocs.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #############################################################################
18 # v20181207
19 # Amazon AWS specific EFS/NFS share and rancher host join script for each cluster node
20 # https://wiki.onap.org/display/DW/Cloud+Native+Deployment
21 # source from https://jira.onap.org/browse/OOM-320
22 # Michael O'Brien
23 # LOG-806 upgrade for Rancher 1.6.22, kubernetes 1.11
24 # master/dublin - LOG-895
25 #     Rancher 1.6.25, Kubernetes 1.11.3, kubectl 1.11.3, Helm 2.9.2, Docker 17.03
26
27
28 usage() {
29 cat <<EOF
30 Usage: $0 [PARAMs]
31 example
32  master
33  sudo ./cluster.sh -n false -s cl.onap.info -e fs-00c0f00 -r us-east-2
34  clients
35  sudo ./cluster.sh -n true -s cl.onap.info -e fs-00c0f00 -r us-east-2 -t 23D4:15:qQ -c false -a host1.onap.info -v true
36  sudo ./oom_cluster_host_install.sh -n true -s cd.onap.cloud -e 1 -r us-east-2 -t token -c false -a 104.209.158.156 -v true
37 Prereq:
38   You must create an EFS (NFS wrapper) on AWS
39
40 -u                      : Display usage
41 -n [true|false]         : is node (non master)
42 -s [master server]      : target server (ip or FQDN only)
43 -e [AWS efs id]         : AWS Elastic File System ID prefix
44 -r [AWS region prefix]  : AWS Region prefix
45 -t [token]              : registration token
46 -h [agent ver]          : agent version (default 1.2.10 for 1.6.18
47 -c [true/false]         : use computed client address
48 -a [IP address]         : client address ip - no FQDN
49 -v [validate true/false]: optional
50 EOF
51 }
52
53 register_node() {
54     #constants
55     DOCKERDATA_NFS=dockerdata-nfs
56     DOCKER_VER=17.03
57     USERNAME=ubuntu
58     PORT=8880
59
60     if [[ "$IS_NODE" != false ]]; then
61         sudo curl https://releases.rancher.com/install-docker/$DOCKER_VER.sh | sh
62         sudo usermod -aG docker $USERNAME
63     fi
64     sudo apt-get install nfs-common -y
65     sudo mkdir /$DOCKERDATA_NFS
66     sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $AWS_EFS.efs.$AWS_REGION.amazonaws.com:/ /$DOCKERDATA_NFS
67     if [[ "$IS_NODE" != false ]]; then
68         echo "Running agent docker..."
69         if [[ "$COMPUTEADDRESS" != false ]]; then
70             echo "sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
71             sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
72         else
73             echo "sudo docker run -e CATTLE_AGENT_IP=\"$ADDRESS\" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
74             sudo docker run -e CATTLE_AGENT_IP="$ADDRESS" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
75         fi
76     fi
77 }
78
79 IS_NODE=false
80 MASTER=
81 TOKEN=
82 AWS_REGION=
83 AWS_EFS=
84 AGENT_VER=1.2.11
85 COMPUTEADDRESS=true
86 ADDRESS=
87 VALIDATE=
88 while getopts ":u:n:s:e:r:t:h:c:a:v" PARAM; do
89   case $PARAM in
90     u)
91       usage
92       exit 1
93       ;;
94     n)
95       IS_NODE=${OPTARG}
96       ;;
97     s)
98       MASTER=${OPTARG}
99       ;;
100     e)
101       AWS_EFS=${OPTARG}
102       ;;
103     r)
104       AWS_REGION=${OPTARG}
105       ;;
106     t)
107       TOKEN=${OPTARG}
108       ;;
109     h)
110       AGENT_VER=${OPTARG}
111       ;;
112     c)
113       COMPUTEADDRESS=${OPTARG}
114       ;;
115     a)
116       ADDRESS=${OPTARG}
117       ;;
118     v)
119       VALIDATE=${OPTARG}
120       ;;
121     ?)
122       usage
123       exit
124       ;;
125   esac
126 done
127
128 if [ -z $MASTER ]; then
129   usage
130   exit 1
131 fi
132
133 register_node  $IS_NODE $MASTER $AWS_EFS $AWS_REGION $TOKEN $AGENT_VER $COMPUTEADDRESS $ADDRESS $VALIDATE
134 echo "check dockerdata-nfs"
135 sudo ls /dockerdata-nfs
136 echo "if you get http://$MASTER:8880/v1 is not accessible (The requested URL returned error: 404 Not Found) - check your token"
137 printf "**** Success: Done ****\n"