Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame^] | 1 | #!/bin/bash -x |
| 2 | printenv |
| 3 | |
| 4 | mkdir -p /opt/config |
| 5 | echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt |
| 6 | echo `hostname -I` `hostname` >> /etc/hosts |
| 7 | mkdir -p /etc/docker |
| 8 | cat > /etc/docker/daemon.json <<EOF |
| 9 | { |
| 10 | "insecure-registries" : ["__docker_proxy__"] |
| 11 | } |
| 12 | EOF |
| 13 | cat > /etc/apt/apt.conf.d/30proxy<<EOF |
| 14 | Acquire::http { Proxy "http://__apt_proxy__"; }; |
| 15 | Acquire::https::Proxy "DIRECT"; |
| 16 | EOF |
| 17 | apt-get -y update |
| 18 | apt-get -y install jq |
| 19 | |
| 20 | cd ~ |
| 21 | |
| 22 | # install docker 1.12 |
| 23 | curl -s https://releases.rancher.com/install-docker/1.12.sh | sh |
| 24 | usermod -aG docker ubuntu |
| 25 | |
| 26 | # install kubernetes 1.8.6 |
| 27 | curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.6/bin/linux/amd64/kubectl |
| 28 | chmod +x ./kubectl |
| 29 | sudo mv ./kubectl /usr/local/bin/kubectl |
| 30 | mkdir ~/.kube |
| 31 | |
| 32 | # install helm 2.3 |
| 33 | wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.3.0-linux-amd64.tar.gz |
| 34 | tar -zxvf helm-v2.3.0-linux-amd64.tar.gz |
| 35 | sudo mv linux-amd64/helm /usr/local/bin/helm |
| 36 | |
| 37 | # Fix virtual memory allocation for onap-log:elasticsearch: |
| 38 | echo "vm.max_map_count=262144" >> /etc/sysctl.conf |
| 39 | sysctl -p |
| 40 | |
| 41 | # install rancher agent |
| 42 | echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc |
| 43 | source api-keys-rc |
| 44 | |
| 45 | sleep 50 |
| 46 | until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do |
| 47 | sleep 10 |
| 48 | done |
| 49 | OLD_PID=$(jq -r '.data[0].id' projects.json) |
| 50 | |
| 51 | curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys | tee apikeys.json |
| 52 | echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc |
| 53 | echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc |
| 54 | source api-keys-rc |
| 55 | |
| 56 | curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X DELETE -H 'Content-Type: application/json' "http://$RANCHER_IP:8080/v2-beta/projects/$OLD_PID" |
| 57 | |
| 58 | until [ ! -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) |
| 62 | done |
| 63 | |
| 64 | curl -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 |
| 65 | PID=`jq -r '.id' project.json` |
| 66 | echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc |
| 67 | source api-keys-rc |
| 68 | |
| 69 | until [ $(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 |
| 72 | done |
| 73 | |
| 74 | TID=$(curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationTokens | jq -r '.id') |
| 75 | touch token.json |
| 76 | while [ $(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 |
| 79 | done |
| 80 | CMD=$(jq -r .command token.json) |
| 81 | eval $CMD |
| 82 | |
| 83 | # download rancher CLI |
| 84 | wget -q https://github.com/rancher/cli/releases/download/v0.6.7/rancher-linux-amd64-v0.6.7.tar.xz |
| 85 | unxz rancher-linux-amd64-v0.6.7.tar.xz |
| 86 | tar xvf rancher-linux-amd64-v0.6.7.tar |
| 87 | |
| 88 | # Clone OOM: |
| 89 | cd ~ |
| 90 | git clone -b amsterdam http://gerrit.onap.org/r/oom |
| 91 | |
| 92 | # Update values.yaml to point to docker-proxy instead of nexus3: |
| 93 | cd ~/oom/kubernetes |
| 94 | perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml` |
| 95 | |
| 96 | KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0) |
| 97 | |
| 98 | # create .kube/config |
| 99 | cat > ~/.kube/config <<EOF |
| 100 | apiVersion: v1 |
| 101 | kind: Config |
| 102 | clusters: |
| 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" |
| 108 | contexts: |
| 109 | - context: |
| 110 | cluster: "oom" |
| 111 | user: "oom" |
| 112 | name: "oom" |
| 113 | current-context: "oom" |
| 114 | users: |
| 115 | - name: "oom" |
| 116 | user: |
| 117 | token: "$KUBETOKEN" |
| 118 | EOF |
| 119 | cat ~/.kube/config |
| 120 | |
| 121 | # Update ~/oom/kubernetes/kube2msb/values.yaml kubeMasterAuthToken to use the token from ~/.kube/config |
| 122 | sed -i "s/kubeMasterAuthToken:.*/kubeMasterAuthToken: $KUBETOKEN/" ~/oom/kubernetes/kube2msb/values.yaml |
| 123 | |
| 124 | export KUBECONFIG=/root/.kube/config |
| 125 | kubectl config view |
| 126 | |
| 127 | # wait for kubernetes to initialze |
| 128 | sleep 100 |
| 129 | until [ $(kubectl get pods --all-namespaces | tail -n +2 | grep -c Running) -ge 6 ]; do |
| 130 | sleep 10 |
| 131 | done |
| 132 | |
| 133 | # Put your onap_key ssh private key in ~/.ssh/onap_key |
| 134 | |
| 135 | # Create or edit ~/oom/kubernetes/config/onap-parameters.yaml |
| 136 | cp ~/oom/kubernetes/config/onap-parameters-sample.yaml ~/oom/kubernetes/config/onap-parameters.yaml |
| 137 | cat >> ~/oom/kubernetes/config/onap-parameters.yaml <<EOF |
| 138 | OPENSTACK_UBUNTU_14_IMAGE: "trusty" |
| 139 | OPENSTACK_PUBLIC_NET_ID: "024582bd-ef9b-48b9-9e70-e6732559d9df" |
| 140 | OPENSTACK_OAM_NETWORK_ID: "a899f36c-28e1-4aa9-9451-1b9f41feefa5" |
| 141 | OPENSTACK_OAM_SUBNET_ID: "b9627602-2908-4aee-94b5-4f1dc92017df" |
| 142 | OPENSTACK_OAM_NETWORK_CIDR: "172.16.1.0/24" |
| 143 | OPENSTACK_USERNAME: "demo" |
| 144 | OPENSTACK_API_KEY: "demo" |
| 145 | OPENSTACK_TENANT_NAME: "demo" |
| 146 | OPENSTACK_TENANT_ID: "__public_net_id__" |
| 147 | OPENSTACK_REGION: "RegionOne" |
| 148 | OPENSTACK_KEYSTONE_URL: "http://192.168.1.11:5000" |
| 149 | OPENSTACK_FLAVOUR_MEDIUM: "m1.medium" |
| 150 | OPENSTACK_SERVICE_TENANT_NAME: "service" |
| 151 | DMAAP_TOPIC: "AUTO" |
| 152 | DEMO_ARTIFACTS_VERSION: "1.1.0-SNAPSHOT" |
| 153 | EOF |
| 154 | |
| 155 | # Source the environment file: |
| 156 | cd ~/oom/kubernetes/oneclick/ |
| 157 | source setenv.bash |
| 158 | |
| 159 | # run the config pod creation |
| 160 | cd ~/oom/kubernetes/config |
| 161 | ./createConfig.sh -n onap |
| 162 | |
| 163 | # Wait until the config container completes. |
| 164 | sleep 200 |
| 165 | until [ $(kubectl get pods --namespace onap -a | tail -n +2 | grep -c Completed) -eq 1 ]; do |
| 166 | sleep 10 |
| 167 | done |
| 168 | |
| 169 | # Run ONAP: |
| 170 | cd ~/oom/kubernetes/oneclick/ |
| 171 | ./createAll.bash -n onap |
| 172 | |
| 173 | # Check ONAP status: |