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 | |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 56 | curl -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 Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 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 | |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 64 | curl -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 Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 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 |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 94 | perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml` oneclick/setenv.bash |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 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 |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 119 | |
| 120 | export KUBECONFIG=/root/.kube/config |
| 121 | kubectl config view |
| 122 | |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 123 | # Update ~/oom/kubernetes/kube2msb/values.yaml kubeMasterAuthToken to use the token from ~/.kube/config |
| 124 | sed -i "s/kubeMasterAuthToken:.*/kubeMasterAuthToken: $KUBETOKEN/" ~/oom/kubernetes/kube2msb/values.yaml |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 125 | |
| 126 | # Put your onap_key ssh private key in ~/.ssh/onap_key |
| 127 | |
| 128 | # Create or edit ~/oom/kubernetes/config/onap-parameters.yaml |
| 129 | cp ~/oom/kubernetes/config/onap-parameters-sample.yaml ~/oom/kubernetes/config/onap-parameters.yaml |
| 130 | cat >> ~/oom/kubernetes/config/onap-parameters.yaml <<EOF |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 131 | |
| 132 | #################################### |
| 133 | # Overridden by k8s_vm_entrypoint.sh |
| 134 | #################################### |
| 135 | |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 136 | OPENSTACK_UBUNTU_14_IMAGE: "__ubuntu_1404_image__" |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 137 | OPENSTACK_UBUNTU_16_IMAGE: "__ubuntu_1604_image__" |
| 138 | OPENSTACK_CENTOS_7_IMAGE: "__centos_7_image__" |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 139 | OPENSTACK_PUBLIC_NET_ID: "__public_net_id__" |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 140 | OPENSTACK_PUBLIC_NET_NAME: "__public_net_name__" |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 141 | OPENSTACK_OAM_NETWORK_CIDR: "__oam_network_cidr__" |
| 142 | OPENSTACK_TENANT_NAME: "__openstack_tenant_name__" |
| 143 | OPENSTACK_TENANT_ID: "__openstack_tenant_id__" |
| 144 | OPENSTACK_USERNAME: "__openstack_username__" |
| 145 | OPENSTACK_API_KEY: "__openstack_api_key__" |
| 146 | OPENSTACK_KEYSTONE_URL: "__keystone_url__" |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 147 | DCAE_IP_ADDR: "__dcae_ip_addr__" |
| 148 | DCAE_KEYSTONE_URL: "__keystone_url__/v2.0" |
| 149 | DNS_LIST: "__dns_list__" |
| 150 | DNS_FORWARDER: "__dns_forwarder__" |
| 151 | EXTERNAL_DNS: "8.8.8.8" |
| 152 | DNSAAS_REGION: "RegionOne" |
| 153 | DNSAAS_KEYSTONE_URL: "__keystone_url__/v2.0" |
| 154 | DNSAAS_TENANT_NAME: "__openstack_tenant_name__" |
| 155 | DNSAAS_USERNAME: "__openstack_username__" |
| 156 | DNSAAS_PASSWORD: "__openstack_api_key__" |
| 157 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 158 | EOF |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 159 | cat ~/oom/kubernetes/config/onap-parameters.yaml |
| 160 | |
| 161 | |
| 162 | # wait for kubernetes to initialze |
| 163 | sleep 100 |
| 164 | until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do |
| 165 | sleep 10 |
| 166 | done |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 167 | |
| 168 | # Source the environment file: |
| 169 | cd ~/oom/kubernetes/oneclick/ |
| 170 | source setenv.bash |
| 171 | |
| 172 | # run the config pod creation |
| 173 | cd ~/oom/kubernetes/config |
| 174 | ./createConfig.sh -n onap |
| 175 | |
| 176 | # Wait until the config container completes. |
| 177 | sleep 200 |
| 178 | until [ $(kubectl get pods --namespace onap -a | tail -n +2 | grep -c Completed) -eq 1 ]; do |
| 179 | sleep 10 |
| 180 | done |
| 181 | |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 182 | # version control the config to see what's happening |
| 183 | cd /dockerdata-nfs/ |
| 184 | git init |
| 185 | git config user.email "root@k8s" |
| 186 | git config user.name "root" |
| 187 | git add -A |
| 188 | git commit -m "initial commit" |
| 189 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 190 | # Run ONAP: |
| 191 | cd ~/oom/kubernetes/oneclick/ |
| 192 | ./createAll.bash -n onap |
| 193 | |
| 194 | # Check ONAP status: |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame^] | 195 | sleep 3 |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 196 | kubectl get pods --all-namespaces |