Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 1 | #!/bin/bash -x |
Gary Wu | a3fb86f | 2018-06-04 16:23:54 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2018 Huawei Technologies Co., Ltd. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 12 | printenv |
| 13 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 14 | mkdir -p /opt/config |
| 15 | echo "__rancher_ip_addr__" > /opt/config/rancher_ip_addr.txt |
| 16 | echo "__k8s_vm_ips__" > /opt/config/k8s_vm_ips.txt |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 17 | echo "__oam_network_id__" > /opt/config/oam_network_id.txt |
| 18 | echo "__oam_subnet_id__" > /opt/config/oam_subnet_id.txt |
| 19 | |
| 20 | cat <<EOF > /opt/config/integration-override.yaml |
| 21 | __integration_override_yaml__ |
| 22 | EOF |
| 23 | sed -i 's/\_\_oam_network_id__/__oam_network_id__/g' /opt/config/integration-override.yaml |
| 24 | sed -i 's/\_\_oam_subnet_id__/__oam_subnet_id__/g' /opt/config/integration-override.yaml |
Gary Wu | 0a67162 | 2018-05-14 12:59:03 -0700 | [diff] [blame] | 25 | sed -i 's/\_\_k8s_1_vm_ip__/__k8s_1_vm_ip__/g' /opt/config/integration-override.yaml |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 26 | cp /opt/config/integration-override.yaml /root |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 27 | |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 28 | echo `hostname -I` `hostname` >> /etc/hosts |
| 29 | mkdir -p /etc/docker |
Gary Wu | 3ad596f | 2018-02-08 07:16:37 -0800 | [diff] [blame] | 30 | if [ ! -z "__docker_proxy__" ]; then |
| 31 | cat > /etc/docker/daemon.json <<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 32 | { |
| 33 | "insecure-registries" : ["__docker_proxy__"] |
| 34 | } |
| 35 | EOF |
Gary Wu | 3ad596f | 2018-02-08 07:16:37 -0800 | [diff] [blame] | 36 | fi |
| 37 | if [ ! -z "__apt_proxy__" ]; then |
| 38 | cat > /etc/apt/apt.conf.d/30proxy<<EOF |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 39 | Acquire::http { Proxy "http://__apt_proxy__"; }; |
| 40 | Acquire::https::Proxy "DIRECT"; |
| 41 | EOF |
Gary Wu | 3ad596f | 2018-02-08 07:16:37 -0800 | [diff] [blame] | 42 | fi |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 43 | apt-get -y update |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 44 | apt-get -y install linux-image-extra-$(uname -r) jq make nfs-kernel-server |
| 45 | |
| 46 | |
| 47 | # version control the persistence volume to see what's happening |
| 48 | mkdir -p /dockerdata-nfs/ |
| 49 | chmod 777 /dockerdata-nfs/ |
| 50 | chown nobody:nogroup /dockerdata-nfs/ |
| 51 | cd /dockerdata-nfs/ |
| 52 | git init |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 53 | git config user.email "root@onap" |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 54 | git config user.name "root" |
| 55 | git add -A |
| 56 | git commit -m "initial commit" |
| 57 | |
| 58 | # export NFS mount |
| 59 | NFS_EXP="" |
| 60 | for K8S_VM_IP in $(tr -d ',[]' < /opt/config/k8s_vm_ips.txt); do |
| 61 | NFS_EXP+="$K8S_VM_IP(rw,sync,no_root_squash,no_subtree_check) " |
| 62 | done |
| 63 | echo "/dockerdata-nfs $NFS_EXP" | tee /etc/exports |
| 64 | |
| 65 | |
| 66 | exportfs -a |
| 67 | systemctl restart nfs-kernel-server |
| 68 | |
| 69 | cd ~ |
| 70 | |
| 71 | # install docker 17.03 |
| 72 | curl -s https://releases.rancher.com/install-docker/17.03.sh | sh |
Gary Wu | 1ff5667 | 2018-01-17 20:51:45 -0800 | [diff] [blame] | 73 | usermod -aG docker ubuntu |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 74 | |
| 75 | docker run --restart unless-stopped -d -p 8080:8080 -e CATTLE_BOOTSTRAP_REQUIRED_IMAGE=__docker_proxy__/rancher/agent:v1.2.9 __docker_proxy__/rancher/server:v1.6.14 |
| 76 | |
Gary Wu | a0fe61c | 2018-06-08 08:06:47 -0700 | [diff] [blame] | 77 | # install kubernetes 1.8.10 |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 78 | curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.8.10/bin/linux/amd64/kubectl |
| 79 | chmod +x ./kubectl |
| 80 | sudo mv ./kubectl /usr/local/bin/kubectl |
| 81 | mkdir ~/.kube |
| 82 | |
| 83 | # install helm |
| 84 | wget -q http://storage.googleapis.com/kubernetes-helm/helm-v2.8.2-linux-amd64.tar.gz |
| 85 | tar -zxvf helm-v2.8.2-linux-amd64.tar.gz |
| 86 | sudo mv linux-amd64/helm /usr/local/bin/helm |
| 87 | |
| 88 | echo export RANCHER_IP=__rancher_ip_addr__ > api-keys-rc |
| 89 | source api-keys-rc |
| 90 | |
| 91 | sleep 50 |
| 92 | until curl -s -o projects.json -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projects; do |
| 93 | sleep 10 |
| 94 | done |
| 95 | OLD_PID=$(jq -r '.data[0].id' projects.json) |
| 96 | |
| 97 | curl -s -H "Accept: application/json" -H "Content-Type: application/json" -d '{"accountId":"1a1"}' http://$RANCHER_IP:8080/v2-beta/apikeys > apikeys.json |
| 98 | echo export RANCHER_ACCESS_KEY=`jq -r '.publicValue' apikeys.json` >> api-keys-rc |
| 99 | echo export RANCHER_SECRET_KEY=`jq -r '.secretValue' apikeys.json` >> api-keys-rc |
| 100 | source api-keys-rc |
| 101 | |
| 102 | |
| 103 | curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X PUT -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"id":"registry.default","type":"activeSetting","baseType":"setting","name":"registry.default","activeValue":"__docker_proxy__","inDb":true,"source":"Database","value":"__docker_proxy__"}' http://$RANCHER_IP:8080/v2-beta/settings/registry.default |
| 104 | |
| 105 | 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" |
| 106 | |
| 107 | until [ ! -z "$TEMPLATE_ID" ] && [ "$TEMPLATE_ID" != "null" ]; do |
| 108 | sleep 5 |
| 109 | curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v2-beta/projectTemplates?name=Kubernetes > projectTemplatesKubernetes.json |
| 110 | TEMPLATE_ID=$(jq -r '.data[0].id' projectTemplatesKubernetes.json) |
| 111 | done |
| 112 | |
| 113 | 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 |
| 114 | PID=`jq -r '.id' project.json` |
| 115 | echo export RANCHER_URL=http://$RANCHER_IP:8080/v1/projects/$PID >> api-keys-rc |
| 116 | source api-keys-rc |
| 117 | |
| 118 | until [ $(jq -r '.state' project.json) == "active" ]; do |
| 119 | sleep 5 |
| 120 | curl -s -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID > project.json |
| 121 | done |
| 122 | |
| 123 | |
| 124 | curl -s -u $RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"name":"docker-proxy", "serverAddress":"__docker_proxy__"}' $RANCHER_URL/registries > registry.json |
| 125 | RID=$(jq -r '.id' registry.json) |
| 126 | |
| 127 | |
| 128 | curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"publicValue":"docker", "registryId":"'$RID'", "secretValue":"docker", "type":"registryCredential"}' "http://$RANCHER_IP:8080/v2-beta/projects/$PID/registrycredential" |
| 129 | |
| 130 | |
| 131 | |
| 132 | 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') |
| 133 | touch token.json |
| 134 | while [ $(jq -r .command token.json | wc -c) -lt 10 ]; do |
| 135 | sleep 5 |
| 136 | curl -s -X GET -H "Accept: application/json" http://$RANCHER_IP:8080/v1/projects/$PID/registrationToken/$TID > token.json |
| 137 | done |
| 138 | jq -r .command token.json > rancher_agent_cmd.sh |
| 139 | chmod +x rancher_agent_cmd.sh |
| 140 | cp rancher_agent_cmd.sh /dockerdata-nfs |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 141 | cd /dockerdata-nfs |
| 142 | git add -A |
| 143 | git commit -a -m "Add rancher agent command file" |
| 144 | cd ~ |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 145 | |
| 146 | |
| 147 | KUBETOKEN=$(echo -n 'Basic '$(echo -n "$RANCHER_ACCESS_KEY:$RANCHER_SECRET_KEY" | base64 -w 0) | base64 -w 0) |
| 148 | |
| 149 | # create .kube/config |
| 150 | cat > ~/.kube/config <<EOF |
| 151 | apiVersion: v1 |
| 152 | kind: Config |
| 153 | clusters: |
| 154 | - cluster: |
| 155 | api-version: v1 |
| 156 | insecure-skip-tls-verify: true |
| 157 | server: "https://$RANCHER_IP:8080/r/projects/$PID/kubernetes:6443" |
| 158 | name: "oom" |
| 159 | contexts: |
| 160 | - context: |
| 161 | cluster: "oom" |
| 162 | user: "oom" |
| 163 | name: "oom" |
| 164 | current-context: "oom" |
| 165 | users: |
| 166 | - name: "oom" |
| 167 | user: |
| 168 | token: "$KUBETOKEN" |
| 169 | EOF |
| 170 | |
| 171 | export KUBECONFIG=/root/.kube/config |
| 172 | kubectl config view |
| 173 | |
| 174 | # wait for kubernetes to initialze |
| 175 | sleep 100 |
| 176 | until [ $(kubectl get pods --namespace kube-system | tail -n +2 | grep -c Running) -ge 6 ]; do |
| 177 | sleep 10 |
| 178 | done |
| 179 | |
| 180 | |
| 181 | # Install using OOM |
| 182 | export HOME=/root |
| 183 | |
Gary Wu | 0dfbea3 | 2018-05-12 09:27:44 -0700 | [diff] [blame] | 184 | # update and initialize git |
| 185 | apt-get -y install git |
| 186 | git config --global user.email root@rancher |
| 187 | git config --global user.name root@rancher |
| 188 | git config --global log.decorate auto |
| 189 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 190 | # Clone OOM: |
| 191 | cd ~ |
Gary Wu | c076ada | 2018-06-07 16:38:25 -0700 | [diff] [blame] | 192 | git clone -b master http://gerrit.onap.org/r/oom |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 193 | cd oom |
| 194 | git log -1 |
Gary Wu | 0dfbea3 | 2018-05-12 09:27:44 -0700 | [diff] [blame] | 195 | git tag -a "deploy0" -m "initial deployment" |
| 196 | git checkout -b workarounds |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 197 | |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 198 | # Run ONAP: |
| 199 | cd ~/oom/kubernetes/ |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 200 | helm init --client-only |
| 201 | helm init --upgrade |
| 202 | helm serve & |
| 203 | sleep 3 |
| 204 | helm repo add local http://127.0.0.1:8879 |
| 205 | helm repo list |
| 206 | make all |
| 207 | helm search -l | grep local |
Gary Wu | 11c9874 | 2018-05-02 16:19:04 -0700 | [diff] [blame] | 208 | helm install local/onap -n dev --namespace onap -f ~/integration-override.yaml |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 209 | |
hector | 56bc0dd | 2018-06-01 20:00:43 -0400 | [diff] [blame] | 210 | # Enable auto-completion for kubectl |
| 211 | echo "source <(kubectl completion bash)" >> ~/.bashrc |
Gary Wu | 14a6b30 | 2018-05-01 15:59:28 -0700 | [diff] [blame] | 212 | |
| 213 | # Check ONAP status: |
| 214 | sleep 3 |
| 215 | kubectl get pods --all-namespaces |