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