blob: db2428ba927c680cbdbb793871485dbd3e235108 [file] [log] [blame]
Gary Wu1ff56672018-01-17 20:51:45 -08001#!/bin/bash -x
2printenv
3
4mkdir -p /opt/config
5echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt
6echo `hostname -I` `hostname` >> /etc/hosts
7mkdir -p /etc/docker
8cat > /etc/docker/daemon.json <<EOF
9{
10 "insecure-registries" : ["__docker_proxy__"]
11}
12EOF
13cat > /etc/apt/apt.conf.d/30proxy<<EOF
14Acquire::http { Proxy "http://__apt_proxy__"; };
15Acquire::https::Proxy "DIRECT";
16EOF
17apt-get -y update
18apt-get -y install jq
19
20cd ~
21
22# install docker 1.12
23curl -s https://releases.rancher.com/install-docker/1.12.sh | sh
24usermod -aG docker ubuntu
25
26# install kubernetes 1.8.6
27curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.6/bin/linux/amd64/kubectl
28chmod +x ./kubectl
29sudo mv ./kubectl /usr/local/bin/kubectl
30mkdir ~/.kube
31
32# install helm 2.3
33wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.3.0-linux-amd64.tar.gz
34tar -zxvf helm-v2.3.0-linux-amd64.tar.gz
35sudo mv linux-amd64/helm /usr/local/bin/helm
36
37# Fix virtual memory allocation for onap-log:elasticsearch:
38echo "vm.max_map_count=262144" >> /etc/sysctl.conf
39sysctl -p
40
41# install rancher agent
42echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
43source api-keys-rc
44
45sleep 50
46until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
47 sleep 10
48done
49OLD_PID=$(jq -r '.data[0].id' projects.json)
50
51curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys | tee apikeys.json
52echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
53echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
54source api-keys-rc
55
Gary Wu60dd0d82018-01-18 14:54:47 -080056curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID"
Gary Wu1ff56672018-01-17 20:51:45 -080057
58until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
59 sleep 5
60 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes | tee projectTemplatesKubernetes.json
61 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
62done
63
Gary Wu60dd0d82018-01-18 14:54:47 -080064curl -s -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X POST -H 'Content-Type: application/json' -d '{ "name":"oom", "projectTemplateId":"'$TEMPLATE_ID'" }' "http://$RANCHER_IP:8080/v2-beta/projects" | tee project.json
Gary Wu1ff56672018-01-17 20:51:45 -080065PID=`jq -r '.id' project.json`
66echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
67source api-keys-rc
68
69until [ $(jq -r '.state' project.json) == "active" ]; do
70 sleep 5
71 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID | tee project.json
72done
73
74TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
75touch token.json
76while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
77 sleep 5
78 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID | tee token.json
79done
80CMD=$(jq -r .command token.json)
81eval $CMD
82
83# download rancher CLI
84wget -q https://github.com/rancher/cli/releases/download/v0.6.7/rancher-linux-amd64-v0.6.7.tar.xz
85unxz rancher-linux-amd64-v0.6.7.tar.xz
86tar xvf rancher-linux-amd64-v0.6.7.tar
87
88# Clone OOM:
89cd ~
90git clone -b amsterdam http://gerrit.onap.org/r/oom
91
92# Update values.yaml to point to docker-proxy instead of nexus3:
93cd ~/oom/kubernetes
Gary Wuc98156d2018-01-18 12:03:26 -080094perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml` oneclick/setenv.bash
Gary Wu1ff56672018-01-17 20:51:45 -080095
96KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
97
98# create .kube/config
99cat > ~/.kube/config <<EOF
100apiVersion: v1
101kind: Config
102clusters:
103- cluster:
104 api-version: v1
105 insecure-skip-tls-verify: true
106 server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
107 name: "oom"
108contexts:
109- context:
110 cluster: "oom"
111 user: "oom"
112 name: "oom"
113current-context: "oom"
114users:
115- name: "oom"
116 user:
117 token: "$KUBETOKEN"
118EOF
Gary Wu1ff56672018-01-17 20:51:45 -0800119
120export KUBECONFIG=/root/.kube/config
121kubectl config view
122
Gary Wuc98156d2018-01-18 12:03:26 -0800123# Update ~/oom/kubernetes/kube2msb/values.yaml kubeMasterAuthToken to use the token from ~/.kube/config
124sed -i "s/kubeMasterAuthToken:.*/kubeMasterAuthToken: $KUBETOKEN/" ~/oom/kubernetes/kube2msb/values.yaml
Gary Wu1ff56672018-01-17 20:51:45 -0800125
126# Put your onap_key ssh private key in ~/.ssh/onap_key
127
128# Create or edit ~/oom/kubernetes/config/onap-parameters.yaml
129cp ~/oom/kubernetes/config/onap-parameters-sample.yaml ~/oom/kubernetes/config/onap-parameters.yaml
130cat >> ~/oom/kubernetes/config/onap-parameters.yaml <<EOF
Gary Wu60dd0d82018-01-18 14:54:47 -0800131
132####################################
133# Overridden by k8s_vm_entrypoint.sh
134####################################
135
Gary Wuc98156d2018-01-18 12:03:26 -0800136OPENSTACK_UBUNTU_14_IMAGE: "__ubuntu_1404_image__"
Gary Wu60dd0d82018-01-18 14:54:47 -0800137OPENSTACK_UBUNTU_16_IMAGE: "__ubuntu_1604_image__"
138OPENSTACK_CENTOS_7_IMAGE: "__centos_7_image__"
Gary Wuc98156d2018-01-18 12:03:26 -0800139OPENSTACK_PUBLIC_NET_ID: "__public_net_id__"
Gary Wu60dd0d82018-01-18 14:54:47 -0800140OPENSTACK_PUBLIC_NET_NAME: "__public_net_name__"
Gary Wuc98156d2018-01-18 12:03:26 -0800141OPENSTACK_OAM_NETWORK_CIDR: "__oam_network_cidr__"
142OPENSTACK_TENANT_NAME: "__openstack_tenant_name__"
143OPENSTACK_TENANT_ID: "__openstack_tenant_id__"
144OPENSTACK_USERNAME: "__openstack_username__"
145OPENSTACK_API_KEY: "__openstack_api_key__"
146OPENSTACK_KEYSTONE_URL: "__keystone_url__"
Gary Wu60dd0d82018-01-18 14:54:47 -0800147DCAE_IP_ADDR: "__dcae_ip_addr__"
Gary Wu7b416392018-01-19 13:16:49 -0800148DCAE_KEYSTONE_URL: "__dcae_keystone_url__"
149DNS_LIST: "__dns_forwarder__"
Gary Wu60dd0d82018-01-18 14:54:47 -0800150DNS_FORWARDER: "__dns_forwarder__"
Gary Wu7b416392018-01-19 13:16:49 -0800151EXTERNAL_DNS: "__external_dns__"
152DNSAAS_PROXY_ENABLE: "__dnsaas_proxy_enable__"
153DNSAAS_KEYSTONE_URL: "__dnsaas_keystone_url__"
154DNSAAS_REGION: "__dnsaas_region__"
155DNSAAS_TENANT_NAME: "__dnsaas_tenant_name__"
156DNSAAS_USERNAME: "__dnsaas_username__"
157DNSAAS_PASSWORD: "__dnsaas_password__"
Gary Wu60dd0d82018-01-18 14:54:47 -0800158
Gary Wu1ff56672018-01-17 20:51:45 -0800159EOF
Gary Wuc98156d2018-01-18 12:03:26 -0800160cat ~/oom/kubernetes/config/onap-parameters.yaml
161
162
163# wait for kubernetes to initialze
164sleep 100
165until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
166 sleep 10
167done
Gary Wu1ff56672018-01-17 20:51:45 -0800168
169# Source the environment file:
170cd ~/oom/kubernetes/oneclick/
171source setenv.bash
172
173# run the config pod creation
174cd ~/oom/kubernetes/config
175./createConfig.sh -n onap
176
177# Wait until the config container completes.
178sleep 200
179until [ $(kubectl get pods --namespace onap -a | tail -n +2 | grep -c Completed) -eq 1 ]; do
180 sleep 10
181done
182
Gary Wu60dd0d82018-01-18 14:54:47 -0800183# version control the config to see what's happening
184cd /dockerdata-nfs/
185git init
186git config user.email "root@k8s"
187git config user.name "root"
188git add -A
189git commit -m "initial commit"
190
Gary Wu1ff56672018-01-17 20:51:45 -0800191# Run ONAP:
192cd ~/oom/kubernetes/oneclick/
193./createAll.bash -n onap
194
195# Check ONAP status:
Gary Wu60dd0d82018-01-18 14:54:47 -0800196sleep 3
Gary Wuc98156d2018-01-18 12:03:26 -0800197kubectl get pods --all-namespaces