2 #############################################################################
4 # Copyright © 2018 Amdocs, Bell.
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
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.
17 #############################################################################
19 # This installation is for a rancher managed install of kubernetes
20 # after this run the standard oom install
21 # this installation can be run on amy ubuntu 16.04 VM or physical host
22 # https://wiki.onap.org/display/DW/Cloud+Native+Deployment
23 # source from https://jira.onap.org/browse/LOG-320
26 # Rancher 1.6.10, Kubernetes 1.7.7, Kubectl 1.7.7, Helm 2.3.0, Docker 1.12
28 # Rancher 1.6.14, Kubernetes 1.8.10, Kubectl 1.8.10, Helm 2.8.2, Docker 17.03
30 # Rancher 1.6.18, Kubernetes 1.10.3, Kubectl 1.10.3, Helm 2.9.2, Docker 17.03
36 sudo ./oom_rancher_setup.sh -b master -s cd.onap.cloud -e onap -c false -a 104.209.168.116 -v true
38 -b [branch] : branch = master or beijing or amsterdam (required)
39 -s [server] : server = IP or DNS name (required)
40 -e [environment] : use the default (onap)
41 -c [true/false] : use computed client address (default true)
42 -a [IP address] : client address ip - no FQDN
43 -v [true/false] : validate
52 if [ "$BRANCH" == "amsterdam" ]; then
53 RANCHER_VERSION=1.6.10
58 elif [ "$BRANCH" == "beijing" ]; then
59 RANCHER_VERSION=1.6.14
60 KUBECTL_VERSION=1.8.10
65 RANCHER_VERSION=1.6.18
66 KUBECTL_VERSION=1.10.3
72 echo "Installing on ${SERVER} for ${BRANCH}: Rancher: ${RANCHER_VERSION} Kubectl: ${KUBECTL_VERSION} Helm: ${HELM_VERSION} Docker: ${DOCKER_VERSION}"
73 sudo echo "127.0.0.1 ${SERVER}" >> /etc/hosts
75 echo "If you must install as non-root - comment out the docker install below - run it separately, run the user mod, logout/login and continue this script"
76 curl https://releases.rancher.com/install-docker/$DOCKER_VERSION.sh | sh
77 sudo usermod -aG docker $USERNAME
79 echo "install make - required for beijing+"
80 sudo apt-get install make -y
82 sudo docker run -d --restart=unless-stopped -p $PORT:8080 --name rancher_server rancher/server:v$RANCHER_VERSION
83 sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/v$KUBECTL_VERSION/bin/linux/amd64/kubectl
84 sudo chmod +x ./kubectl
85 sudo mv ./kubectl /usr/local/bin/kubectl
87 wget http://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-linux-amd64.tar.gz
88 sudo tar -zxvf helm-v${HELM_VERSION}-linux-amd64.tar.gz
89 sudo mv linux-amd64/helm /usr/local/bin/helm
91 # create kubernetes environment on rancher using cli
93 KUBE_ENV_NAME=$ENVIRON
94 wget https://releases.rancher.com/cli/v${RANCHER_CLI_VER}/rancher-linux-amd64-v${RANCHER_CLI_VER}.tar.gz
95 sudo tar -zxvf rancher-linux-amd64-v${RANCHER_CLI_VER}.tar.gz
96 sudo cp rancher-v${RANCHER_CLI_VER}/rancher .
97 sudo chmod +x ./rancher
101 echo "wait for rancher server container to finish - 3 min"
108 echo "get public and private tokens back to the rancher server so we can register the client later"
109 API_RESPONSE=`curl -s 'http://127.0.0.1:8880/v2-beta/apikey' -d '{"type":"apikey","accountId":"1a1","name":"autoinstall","description":"autoinstall","created":null,"kind":null,"removeTime":null,"removed":null,"uuid":null}'`
110 # Extract and store token
111 echo "API_RESPONSE: $API_RESPONSE"
112 KEY_PUBLIC=`echo $API_RESPONSE | jq -r .publicValue`
113 KEY_SECRET=`echo $API_RESPONSE | jq -r .secretValue`
114 echo "publicValue: $KEY_PUBLIC secretValue: $KEY_SECRET"
116 export RANCHER_URL=http://${SERVER}:$PORT
117 export RANCHER_ACCESS_KEY=$KEY_PUBLIC
118 export RANCHER_SECRET_KEY=$KEY_SECRET
120 echo "wait 60 sec for rancher environments can settle before we create the onap kubernetes one"
123 echo "Creating kubernetes environment named ${KUBE_ENV_NAME}"
124 ./rancher env create -t kubernetes $KUBE_ENV_NAME > kube_env_id.json
125 PROJECT_ID=$(<kube_env_id.json)
126 echo "env id: $PROJECT_ID"
127 export RANCHER_HOST_URL=http://${SERVER}:$PORT/v1/projects/$PROJECT_ID
128 echo "you should see an additional kubernetes environment usually with id 1a7"
130 # optionally disable cattle env
132 # add host registration url
133 # https://github.com/rancher/rancher/issues/2599
134 # wait for REGISTERING to ACTIVE
135 echo "sleep 90 to wait for REG to ACTIVE"
138 echo "check on environments again before registering the URL response"
145 REG_URL_RESPONSE=`curl -X POST -u $KEY_PUBLIC:$KEY_SECRET -H 'Accept: application/json' -H 'ContentType: application/json' -d '{"name":"$SERVER"}' "http://$SERVER:8880/v1/projects/$PROJECT_ID/registrationtokens"`
146 echo "REG_URL_RESPONSE: $REG_URL_RESPONSE"
147 echo "wait for server to finish url configuration - 5 min"
151 # see registrationUrl in
152 REGISTRATION_TOKENS=`curl http://127.0.0.1:$PORT/v2-beta/registrationtokens`
153 echo "REGISTRATION_TOKENS: $REGISTRATION_TOKENS"
154 REGISTRATION_URL=`echo $REGISTRATION_TOKENS | jq -r .data[0].registrationUrl`
155 REGISTRATION_DOCKER=`echo $REGISTRATION_TOKENS | jq -r .data[0].image`
156 REGISTRATION_TOKEN=`echo $REGISTRATION_TOKENS | jq -r .data[0].token`
157 echo "Registering host for image: $REGISTRATION_DOCKER url: $REGISTRATION_URL registrationToken: $REGISTRATION_TOKEN"
158 HOST_REG_COMMAND=`echo $REGISTRATION_TOKENS | jq -r .data[0].command`
159 echo "Running agent docker..."
160 if [[ "$COMPUTEADDRESS" != false ]]; then
161 echo "sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher $REGISTRATION_DOCKER $RANCHER_URL/v1/scripts/$REGISTRATION_TOKEN"
162 sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher $REGISTRATION_DOCKER $RANCHER_URL/v1/scripts/$REGISTRATION_TOKEN
164 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_VERSION http://$SERVER:$PORT/v1/scripts/$TOKEN"
165 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_VERSION http://$SERVER:$PORT/v1/scripts/$REGISTRATION_TOKEN
167 echo "waiting 8 min for host registration to finish"
171 #read -p "wait for host registration to complete before generating the client token....."
173 # base64 encode the kubectl token from the auth pair
174 # generate this after the host is registered
175 KUBECTL_TOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
176 echo "KUBECTL_TOKEN base64 encoded: ${KUBECTL_TOKEN}"
177 # add kubectl config - NOTE: the following spacing has to be "exact" or kubectl will not connect - with a localhost:8080 error
178 cat > ~/.kube/config <<EOF
184 insecure-skip-tls-verify: true
185 server: "https://$SERVER:$PORT/r/projects/$PROJECT_ID/kubernetes:6443"
189 cluster: "${ENVIRON}"
192 current-context: "${ENVIRON}"
196 token: "$KUBECTL_TOKEN"
200 echo "run the following if you installed a higher kubectl version than the server"
201 echo "helm init --upgrade"
202 echo "Verify all pods up on the kubernetes system - will return localhost:8080 until a host is added"
203 echo "kubectl get pods --all-namespaces"
204 kubectl get pods --all-namespaces
205 echo "upgrade server side of helm in kubernetes"
209 sudo helm init --upgrade
212 echo "verify both versions are the same below"
214 echo "start helm server"
218 echo "add local helm repo"
219 sudo helm repo add local http://127.0.0.1:8879
221 echo "To enable grafana dashboard - do this after running cd.sh which brings up onap - or you may get a 302xx port conflict"
222 echo "kubectl expose -n kube-system deployment monitoring-grafana --type=LoadBalancer --name monitoring-grafana-client"
223 echo "to get the nodeport for a specific VM running grafana"
224 echo "kubectl get services --all-namespaces | grep graf"
225 kubectl get pods --all-namespaces
236 while getopts ":b:s:e:u:c:a:v" PARAM; do
252 COMPUTEADDRESS=${OPTARG}
267 if [[ -z $BRANCH ]]; then
272 install_onap $BRANCH $SERVER $ENVIRON $COMPUTEADDRESS $ADDRESS $VALIDATE