blob: 07ef2c3710915ecc4abb9ffc55423a3c39b78d5d [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
Gary Wu374498a2018-02-06 17:31:04 -08008if [ ! -z "__docker_proxy__" ]; then
9 cat > /etc/docker/daemon.json <<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080010{
11 "insecure-registries" : ["__docker_proxy__"]
12}
13EOF
Gary Wu374498a2018-02-06 17:31:04 -080014fi
15if [ ! -z "__apt_proxy__" ]; then
16 cat > /etc/apt/apt.conf.d/30proxy<<EOF
Gary Wu1ff56672018-01-17 20:51:45 -080017Acquire::http { Proxy "http://__apt_proxy__"; };
18Acquire::https::Proxy "DIRECT";
19EOF
Gary Wu374498a2018-02-06 17:31:04 -080020fi
Gary Wu1ff56672018-01-17 20:51:45 -080021apt-get -y update
Gary Wub5529a62018-04-03 14:57:17 -070022apt-get -y install linux-image-extra-$(uname -r) jq make
Gary Wu1ff56672018-01-17 20:51:45 -080023
24cd ~
25
Gary Wu57abb1a2018-03-09 13:38:28 -080026# install docker 17.03
27curl -s https://releases.rancher.com/install-docker/17.03.sh | sh
Gary Wu1ff56672018-01-17 20:51:45 -080028usermod -aG docker ubuntu
29
30# install kubernetes 1.8.6
31curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.6/bin/linux/amd64/kubectl
32chmod +x ./kubectl
33sudo mv ./kubectl /usr/local/bin/kubectl
34mkdir ~/.kube
35
Gary Wu57abb1a2018-03-09 13:38:28 -080036# install helm
37wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.6.1-linux-amd64.tar.gz
38tar -zxvf helm-v2.6.1-linux-amd64.tar.gz
Gary Wu1ff56672018-01-17 20:51:45 -080039sudo mv linux-amd64/helm /usr/local/bin/helm
Gary Wu57abb1a2018-03-09 13:38:28 -080040# verify version
41helm version
42# Rancher 1.6.14 installs 2.6.1 - if you upgrade to 2.8.0 - you will need to upgrade helm on the server to the version to level of client
43helm init --upgrade
Gary Wu1ff56672018-01-17 20:51:45 -080044
45# Fix virtual memory allocation for onap-log:elasticsearch:
46echo "vm.max_map_count=262144" >> /etc/sysctl.conf
47sysctl -p
48
49# install rancher agent
50echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc
51source api-keys-rc
52
53sleep 50
54until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do
55 sleep 10
56done
57OLD_PID=$(jq -r '.data[0].id' projects.json)
58
Gary Wu52dfdcb2018-01-25 11:02:48 -080059curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json
Gary Wu1ff56672018-01-17 20:51:45 -080060echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc
61echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc
62source api-keys-rc
63
Gary Wu60dd0d82018-01-18 14:54:47 -080064curl -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 -080065
66until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do
67 sleep 5
Gary Wu52dfdcb2018-01-25 11:02:48 -080068 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json
Gary Wu1ff56672018-01-17 20:51:45 -080069 TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json)
70done
71
Gary Wu52dfdcb2018-01-25 11:02:48 -080072curl -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" > project.json
Gary Wu1ff56672018-01-17 20:51:45 -080073PID=`jq -r '.id' project.json`
74echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc
75source api-keys-rc
76
77until [ $(jq -r '.state' project.json) == "active" ]; do
78 sleep 5
Gary Wu52dfdcb2018-01-25 11:02:48 -080079 curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json
Gary Wu1ff56672018-01-17 20:51:45 -080080done
81
82TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id')
83touch token.json
84while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do
85 sleep 5
Gary Wu52dfdcb2018-01-25 11:02:48 -080086 curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json
Gary Wu1ff56672018-01-17 20:51:45 -080087done
Gary Wu52dfdcb2018-01-25 11:02:48 -080088RANCHER_AGENT_CMD=$(jq -r .command token.json)
89eval $RANCHER_AGENT_CMD
Gary Wu1ff56672018-01-17 20:51:45 -080090
91# download rancher CLI
92wget -q https://github.com/rancher/cli/releases/download/v0.6.7/rancher-linux-amd64-v0.6.7.tar.xz
93unxz rancher-linux-amd64-v0.6.7.tar.xz
94tar xvf rancher-linux-amd64-v0.6.7.tar
95
96# Clone OOM:
97cd ~
Gary Wu57abb1a2018-03-09 13:38:28 -080098git clone -b master http://gerrit.onap.org/r/oom
Gary Wu1ff56672018-01-17 20:51:45 -080099
100# Update values.yaml to point to docker-proxy instead of nexus3:
101cd ~/oom/kubernetes
Gary Wub5529a62018-04-03 14:57:17 -0700102perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml`
Gary Wu1ff56672018-01-17 20:51:45 -0800103
104KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0)
105
106# create .kube/config
107cat > ~/.kube/config <<EOF
108apiVersion: v1
109kind: Config
110clusters:
111- cluster:
112 api-version: v1
113 insecure-skip-tls-verify: true
114 server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443"
115 name: "oom"
116contexts:
117- context:
118 cluster: "oom"
119 user: "oom"
120 name: "oom"
121current-context: "oom"
122users:
123- name: "oom"
124 user:
125 token: "$KUBETOKEN"
126EOF
Gary Wu1ff56672018-01-17 20:51:45 -0800127
128export KUBECONFIG=/root/.kube/config
129kubectl config view
130
Gary Wuc98156d2018-01-18 12:03:26 -0800131# Update ~/oom/kubernetes/kube2msb/values.yaml kubeMasterAuthToken to use the token from ~/.kube/config
132sed -i "s/kubeMasterAuthToken:.*/kubeMasterAuthToken: $KUBETOKEN/" ~/oom/kubernetes/kube2msb/values.yaml
Gary Wu1ff56672018-01-17 20:51:45 -0800133
134# Put your onap_key ssh private key in ~/.ssh/onap_key
135
136# Create or edit ~/oom/kubernetes/config/onap-parameters.yaml
Gary Wu52dfdcb2018-01-25 11:02:48 -0800137cat > ~/oom/kubernetes/config/onap-parameters.yaml <<EOF
Gary Wu57abb1a2018-03-09 13:38:28 -0800138OPENSTACK_UBUNTU_14_IMAGE: "__ubuntu_1404_image__"
139OPENSTACK_PUBLIC_NET_ID: "__public_net_id__"
Gary Wu52dfdcb2018-01-25 11:02:48 -0800140OPENSTACK_OAM_NETWORK_ID: "__oam_network_id__"
Gary Wu57abb1a2018-03-09 13:38:28 -0800141OPENSTACK_OAM_SUBNET_ID: "__oam_subnet_id__"
142OPENSTACK_OAM_NETWORK_CIDR: "__oam_network_cidr__"
Gary Wu52dfdcb2018-01-25 11:02:48 -0800143OPENSTACK_USERNAME: "__openstack_username__"
Gary Wu57abb1a2018-03-09 13:38:28 -0800144OPENSTACK_API_KEY: "__openstack_api_key__"
Gary Wuc98156d2018-01-18 12:03:26 -0800145OPENSTACK_TENANT_NAME: "__openstack_tenant_name__"
146OPENSTACK_TENANT_ID: "__openstack_tenant_id__"
Gary Wu52dfdcb2018-01-25 11:02:48 -0800147OPENSTACK_REGION: "RegionOne"
Gary Wuc98156d2018-01-18 12:03:26 -0800148OPENSTACK_KEYSTONE_URL: "__keystone_url__"
Gary Wu57abb1a2018-03-09 13:38:28 -0800149OPENSTACK_FLAVOUR_MEDIUM: "m1.medium"
Gary Wu52dfdcb2018-01-25 11:02:48 -0800150OPENSTACK_SERVICE_TENANT_NAME: "service"
Gary Wu57abb1a2018-03-09 13:38:28 -0800151DMAAP_TOPIC: "AUTO"
152DEMO_ARTIFACTS_VERSION: "1.1.1"
Gary Wu1ff56672018-01-17 20:51:45 -0800153EOF
Gary Wuc98156d2018-01-18 12:03:26 -0800154cat ~/oom/kubernetes/config/onap-parameters.yaml
155
156
157# wait for kubernetes to initialze
158sleep 100
159until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do
160 sleep 10
161done
Gary Wu1ff56672018-01-17 20:51:45 -0800162
Gary Wu1ff56672018-01-17 20:51:45 -0800163# run the config pod creation
164cd ~/oom/kubernetes/config
165./createConfig.sh -n onap
166
167# Wait until the config container completes.
Gary Wu52dfdcb2018-01-25 11:02:48 -0800168sleep 20
Gary Wu1ff56672018-01-17 20:51:45 -0800169until [ $(kubectl get pods --namespace onap -a | tail -n +2 | grep -c Completed) -eq 1 ]; do
170 sleep 10
171done
172
Gary Wu60dd0d82018-01-18 14:54:47 -0800173# version control the config to see what's happening
174cd /dockerdata-nfs/
175git init
176git config user.email "root@k8s"
177git config user.name "root"
178git add -A
179git commit -m "initial commit"
180
Gary Wu1ff56672018-01-17 20:51:45 -0800181# Run ONAP:
Gary Wub5529a62018-04-03 14:57:17 -0700182cd ~/oom/kubernetes/
183helm init --client-only
184helm serve &
185sleep 3
186helm repo add local http://127.0.0.1:8879
187make all
188helm install local/onap --name dev --namespace onap
Gary Wu1ff56672018-01-17 20:51:45 -0800189
190# Check ONAP status:
Gary Wu60dd0d82018-01-18 14:54:47 -0800191sleep 3
Gary Wuc98156d2018-01-18 12:03:26 -0800192kubectl get pods --all-namespaces