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 |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 8 | if [ ! -z "__docker_proxy__" ]; then |
| 9 | cat > /etc/docker/daemon.json <<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 10 | { |
| 11 | "insecure-registries" : ["__docker_proxy__"] |
| 12 | } |
| 13 | EOF |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 14 | fi |
| 15 | if [ ! -z "__apt_proxy__" ]; then |
| 16 | cat > /etc/apt/apt.conf.d/30proxy<<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 17 | Acquire::http { Proxy "http://__apt_proxy__"; }; |
| 18 | Acquire::https::Proxy "DIRECT"; |
| 19 | EOF |
Gary Wu | 374498a | 2018-02-06 17:31:04 -0800 | [diff] [blame] | 20 | fi |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 21 | apt-get -y update |
Gary Wu | b5529a6 | 2018-04-03 14:57:17 -0700 | [diff] [blame^] | 22 | apt-get -y install linux-image-extra-$(uname -r) jq make |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 23 | |
| 24 | cd ~ |
| 25 | |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 26 | # install docker 17.03 |
| 27 | curl -s https://releases.rancher.com/install-docker/17.03.sh | sh |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 28 | usermod -aG docker ubuntu |
| 29 | |
| 30 | # install kubernetes 1.8.6 |
| 31 | curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.6/bin/linux/amd64/kubectl |
| 32 | chmod +x ./kubectl |
| 33 | sudo mv ./kubectl /usr/local/bin/kubectl |
| 34 | mkdir ~/.kube |
| 35 | |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 36 | # install helm |
| 37 | wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.6.1-linux-amd64.tar.gz |
| 38 | tar -zxvf helm-v2.6.1-linux-amd64.tar.gz |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 39 | sudo mv linux-amd64/helm /usr/local/bin/helm |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 40 | # verify version |
| 41 | helm 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 |
| 43 | helm init --upgrade |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 44 | |
| 45 | # Fix virtual memory allocation for onap-log:elasticsearch: |
| 46 | echo "vm.max_map_count=262144" >> /etc/sysctl.conf |
| 47 | sysctl -p |
| 48 | |
| 49 | # install rancher agent |
| 50 | echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc |
| 51 | source api-keys-rc |
| 52 | |
| 53 | sleep 50 |
| 54 | until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do |
| 55 | sleep 10 |
| 56 | done |
| 57 | OLD_PID=$(jq -r '.data[0].id' projects.json) |
| 58 | |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 59 | curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 60 | echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc |
| 61 | echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc |
| 62 | source api-keys-rc |
| 63 | |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame] | 64 | 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] | 65 | |
| 66 | until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do |
| 67 | sleep 5 |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 68 | curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 69 | TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json) |
| 70 | done |
| 71 | |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 72 | 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" > project.json |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 73 | PID=`jq -r '.id' project.json` |
| 74 | echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc |
| 75 | source api-keys-rc |
| 76 | |
| 77 | until [ $(jq -r '.state' project.json) == "active" ]; do |
| 78 | sleep 5 |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 79 | curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 80 | done |
| 81 | |
| 82 | 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') |
| 83 | touch token.json |
| 84 | while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do |
| 85 | sleep 5 |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 86 | curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 87 | done |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 88 | RANCHER_AGENT_CMD=$(jq -r .command token.json) |
| 89 | eval $RANCHER_AGENT_CMD |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 90 | |
| 91 | # download rancher CLI |
| 92 | wget -q https://github.com/rancher/cli/releases/download/v0.6.7/rancher-linux-amd64-v0.6.7.tar.xz |
| 93 | unxz rancher-linux-amd64-v0.6.7.tar.xz |
| 94 | tar xvf rancher-linux-amd64-v0.6.7.tar |
| 95 | |
| 96 | # Clone OOM: |
| 97 | cd ~ |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 98 | git clone -b master http://gerrit.onap.org/r/oom |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 99 | |
| 100 | # Update values.yaml to point to docker-proxy instead of nexus3: |
| 101 | cd ~/oom/kubernetes |
Gary Wu | b5529a6 | 2018-04-03 14:57:17 -0700 | [diff] [blame^] | 102 | perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml` |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 103 | |
| 104 | KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0) |
| 105 | |
| 106 | # create .kube/config |
| 107 | cat > ~/.kube/config <<EOF |
| 108 | apiVersion: v1 |
| 109 | kind: Config |
| 110 | clusters: |
| 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" |
| 116 | contexts: |
| 117 | - context: |
| 118 | cluster: "oom" |
| 119 | user: "oom" |
| 120 | name: "oom" |
| 121 | current-context: "oom" |
| 122 | users: |
| 123 | - name: "oom" |
| 124 | user: |
| 125 | token: "$KUBETOKEN" |
| 126 | EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 127 | |
| 128 | export KUBECONFIG=/root/.kube/config |
| 129 | kubectl config view |
| 130 | |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 131 | # Update ~/oom/kubernetes/kube2msb/values.yaml kubeMasterAuthToken to use the token from ~/.kube/config |
| 132 | sed -i "s/kubeMasterAuthToken:.*/kubeMasterAuthToken: $KUBETOKEN/" ~/oom/kubernetes/kube2msb/values.yaml |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 133 | |
| 134 | # Put your onap_key ssh private key in ~/.ssh/onap_key |
| 135 | |
| 136 | # Create or edit ~/oom/kubernetes/config/onap-parameters.yaml |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 137 | cat > ~/oom/kubernetes/config/onap-parameters.yaml <<EOF |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 138 | OPENSTACK_UBUNTU_14_IMAGE: "__ubuntu_1404_image__" |
| 139 | OPENSTACK_PUBLIC_NET_ID: "__public_net_id__" |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 140 | OPENSTACK_OAM_NETWORK_ID: "__oam_network_id__" |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 141 | OPENSTACK_OAM_SUBNET_ID: "__oam_subnet_id__" |
| 142 | OPENSTACK_OAM_NETWORK_CIDR: "__oam_network_cidr__" |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 143 | OPENSTACK_USERNAME: "__openstack_username__" |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 144 | OPENSTACK_API_KEY: "__openstack_api_key__" |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 145 | OPENSTACK_TENANT_NAME: "__openstack_tenant_name__" |
| 146 | OPENSTACK_TENANT_ID: "__openstack_tenant_id__" |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 147 | OPENSTACK_REGION: "RegionOne" |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 148 | OPENSTACK_KEYSTONE_URL: "__keystone_url__" |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 149 | OPENSTACK_FLAVOUR_MEDIUM: "m1.medium" |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 150 | OPENSTACK_SERVICE_TENANT_NAME: "service" |
Gary Wu | 57abb1a | 2018-03-09 13:38:28 -0800 | [diff] [blame] | 151 | DMAAP_TOPIC: "AUTO" |
| 152 | DEMO_ARTIFACTS_VERSION: "1.1.1" |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 153 | EOF |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 154 | cat ~/oom/kubernetes/config/onap-parameters.yaml |
| 155 | |
| 156 | |
| 157 | # wait for kubernetes to initialze |
| 158 | sleep 100 |
| 159 | until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do |
| 160 | sleep 10 |
| 161 | done |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 162 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 163 | # run the config pod creation |
| 164 | cd ~/oom/kubernetes/config |
| 165 | ./createConfig.sh -n onap |
| 166 | |
| 167 | # Wait until the config container completes. |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 168 | sleep 20 |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 169 | until [ $(kubectl get pods --namespace onap -a | tail -n +2 | grep -c Completed) -eq 1 ]; do |
| 170 | sleep 10 |
| 171 | done |
| 172 | |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame] | 173 | # version control the config to see what's happening |
| 174 | cd /dockerdata-nfs/ |
| 175 | git init |
| 176 | git config user.email "root@k8s" |
| 177 | git config user.name "root" |
| 178 | git add -A |
| 179 | git commit -m "initial commit" |
| 180 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 181 | # Run ONAP: |
Gary Wu | b5529a6 | 2018-04-03 14:57:17 -0700 | [diff] [blame^] | 182 | cd ~/oom/kubernetes/ |
| 183 | helm init --client-only |
| 184 | helm serve & |
| 185 | sleep 3 |
| 186 | helm repo add local http://127.0.0.1:8879 |
| 187 | make all |
| 188 | helm install local/onap --name dev --namespace onap |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 189 | |
| 190 | # Check ONAP status: |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame] | 191 | sleep 3 |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 192 | kubectl get pods --all-namespaces |