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 |
Helen Chen | 1451db4 | 2018-04-12 15:54:24 -0700 | [diff] [blame] | 37 | wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.7.2-linux-amd64.tar.gz |
| 38 | tar -zxvf helm-v2.7.2-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 |
| 40 | |
| 41 | # Fix virtual memory allocation for onap-log:elasticsearch: |
| 42 | echo "vm.max_map_count=262144" >> /etc/sysctl.conf |
| 43 | sysctl -p |
| 44 | |
| 45 | # install rancher agent |
| 46 | echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc |
| 47 | source api-keys-rc |
| 48 | |
| 49 | sleep 50 |
| 50 | until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do |
| 51 | sleep 10 |
| 52 | done |
| 53 | OLD_PID=$(jq -r '.data[0].id' projects.json) |
| 54 | |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 55 | 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] | 56 | echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc |
| 57 | echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc |
| 58 | source api-keys-rc |
| 59 | |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame] | 60 | 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] | 61 | |
| 62 | until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do |
| 63 | sleep 5 |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 64 | 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] | 65 | TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json) |
| 66 | done |
| 67 | |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 68 | 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] | 69 | PID=`jq -r '.id' project.json` |
| 70 | echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc |
| 71 | source api-keys-rc |
| 72 | |
| 73 | until [ $(jq -r '.state' project.json) == "active" ]; do |
| 74 | sleep 5 |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 75 | 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] | 76 | done |
| 77 | |
| 78 | 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') |
| 79 | touch token.json |
| 80 | while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do |
| 81 | sleep 5 |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 82 | 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] | 83 | done |
Gary Wu | 52dfdcb | 2018-01-25 11:02:48 -0800 | [diff] [blame] | 84 | RANCHER_AGENT_CMD=$(jq -r .command token.json) |
| 85 | eval $RANCHER_AGENT_CMD |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 86 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 87 | |
| 88 | KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0) |
| 89 | |
| 90 | # create .kube/config |
| 91 | cat > ~/.kube/config <<EOF |
| 92 | apiVersion: v1 |
| 93 | kind: Config |
| 94 | clusters: |
| 95 | - cluster: |
| 96 | api-version: v1 |
| 97 | insecure-skip-tls-verify: true |
| 98 | server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443" |
| 99 | name: "oom" |
| 100 | contexts: |
| 101 | - context: |
| 102 | cluster: "oom" |
| 103 | user: "oom" |
| 104 | name: "oom" |
| 105 | current-context: "oom" |
| 106 | users: |
| 107 | - name: "oom" |
| 108 | user: |
| 109 | token: "$KUBETOKEN" |
| 110 | EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 111 | |
| 112 | export KUBECONFIG=/root/.kube/config |
| 113 | kubectl config view |
| 114 | |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 115 | # wait for kubernetes to initialze |
| 116 | sleep 100 |
| 117 | until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do |
| 118 | sleep 10 |
| 119 | done |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 120 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 121 | |
Gary Wu | ca219e0 | 2018-04-04 11:35:55 -0700 | [diff] [blame] | 122 | # Install using OOM |
| 123 | export HOME=/root |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 124 | |
Gary Wu | ca219e0 | 2018-04-04 11:35:55 -0700 | [diff] [blame] | 125 | # Clone OOM: |
| 126 | cd ~ |
| 127 | git clone -b master http://gerrit.onap.org/r/oom |
| 128 | git log -1 |
| 129 | |
| 130 | # Update values.yaml to point to docker-proxy instead of nexus3: |
| 131 | cd ~/oom/kubernetes |
| 132 | #perl -p -i -e 's/nexus3.onap.org:10001/__docker_proxy__/g' `find ./ -name values.yaml` |
| 133 | sed -i 's/nexus3.onap.org:10001/__docker_proxy__/g' onap/values.yaml |
| 134 | sed -i 's/#repository:/repository:/g' onap/values.yaml |
| 135 | sed -i 's/#repositorySecret:/repositorySecret:/g' onap/values.yaml |
| 136 | git diff |
| 137 | |
| 138 | |
| 139 | # version control the persistence volume to see what's happening |
| 140 | mkdir -p /dockerdata-nfs/ |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame] | 141 | cd /dockerdata-nfs/ |
| 142 | git init |
| 143 | git config user.email "root@k8s" |
| 144 | git config user.name "root" |
| 145 | git add -A |
| 146 | git commit -m "initial commit" |
| 147 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 148 | # Run ONAP: |
Gary Wu | b5529a6 | 2018-04-03 14:57:17 -0700 | [diff] [blame] | 149 | cd ~/oom/kubernetes/ |
Gary Wu | ca219e0 | 2018-04-04 11:35:55 -0700 | [diff] [blame] | 150 | # verify version |
| 151 | helm version |
Gary Wu | b5529a6 | 2018-04-03 14:57:17 -0700 | [diff] [blame] | 152 | helm init --client-only |
Gary Wu | 90d878d | 2018-04-12 16:15:19 -0700 | [diff] [blame] | 153 | helm init --upgrade |
Gary Wu | b5529a6 | 2018-04-03 14:57:17 -0700 | [diff] [blame] | 154 | helm serve & |
| 155 | sleep 3 |
| 156 | helm repo add local http://127.0.0.1:8879 |
Gary Wu | ca219e0 | 2018-04-04 11:35:55 -0700 | [diff] [blame] | 157 | helm repo list |
Gary Wu | b5529a6 | 2018-04-03 14:57:17 -0700 | [diff] [blame] | 158 | make all |
Gary Wu | ca219e0 | 2018-04-04 11:35:55 -0700 | [diff] [blame] | 159 | helm search -l | grep local |
| 160 | helm install local/onap -n dev --namespace onap |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 161 | |
| 162 | # Check ONAP status: |
Gary Wu | 60dd0d8 | 2018-01-18 14:54:47 -0800 | [diff] [blame] | 163 | sleep 3 |
Gary Wu | c98156d | 2018-01-18 12:03:26 -0800 | [diff] [blame] | 164 | kubectl get pods --all-namespaces |