Michael O'Brien | a3eb4e1 | 2019-02-23 19:44:56 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ############################################################################# |
| 3 | # Copyright © 2019 Bell. |
| 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 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | ############################################################################# |
| 17 | # |
| 18 | # This installation is for an RKE install of kubernetes |
| 19 | # after this run the standard oom install |
| 20 | # this installation can be run on amy ubuntu 16.04 VM, RHEL 7.6 (root only), physical or cloud azure/aws host |
| 21 | # https://wiki.onap.org/display/DW/OOM+RKE+Kubernetes+Deployment |
| 22 | # source from https://jira.onap.org/browse/OOM-1598 |
| 23 | # |
| 24 | # master/dublin |
| 25 | # RKE 0.1.16 Kubernetes 1.11.6, kubectl 1.11.6, Helm 2.9.1, Docker 18.06 |
| 26 | # single node install, HA pending |
| 27 | |
| 28 | usage() { |
| 29 | cat <<EOF |
| 30 | Usage: $0 [PARAMs] |
| 31 | example |
| 32 | sudo ./rke_setup.sh -b dublin -s rke.onap.cloud -e onap -l amdocs -v true |
| 33 | -u : Display usage |
| 34 | -b [branch] : branch = master or dublin (required) |
| 35 | -s [server] : server = IP or DNS name (required) |
| 36 | -e [environment] : use the default (onap) |
| 37 | -k [key] : ssh key name |
| 38 | -l [username] : login username account (use ubuntu for example) |
| 39 | EOF |
| 40 | } |
| 41 | |
| 42 | install_onap() { |
| 43 | #constants |
| 44 | PORT=8880 |
| 45 | if [ "$BRANCH" == "casablanca" ]; then |
| 46 | KUBERNETES_VERSION= |
| 47 | RKE_VERSION=0.1.15 |
| 48 | KUBECTL_VERSION=1.11.3 |
| 49 | HELM_VERSION=2.9.1 |
| 50 | DOCKER_VERSION=17.03 |
| 51 | else |
| 52 | KUBERNETES_VERSION= |
| 53 | RKE_VERSION=0.1.16 |
| 54 | KUBECTL_VERSION=1.11.6 |
| 55 | HELM_VERSION=2.9.1 |
| 56 | DOCKER_VERSION=18.06 |
| 57 | fi |
| 58 | |
| 59 | # copy your private ssh key and cluster.yml file to the vm |
| 60 | # on your dev machine |
| 61 | #sudo cp ~/.ssh/onap_rsa . |
| 62 | #sudo chmod 777 onap_rsa |
| 63 | #scp onap_rsa ubuntu@192.168.241.132:~/ |
| 64 | # on this vm |
| 65 | #sudo chmod 400 onap_rsa |
| 66 | #sudo cp onap_rsa ~/.ssh |
| 67 | # make sure public key is insetup correctly in |
| 68 | # sudo vi ~/.ssh/authorized_keys |
| 69 | |
| 70 | echo "please supply your ssh key as provided by the -k keyname - it must be be chmod 400 and chown user:user in ~/.ssh/" |
| 71 | echo "The RKE version specific cluster.yaml is already integrated in this script for 0.1.15/0.1.16 no need for below generation..." |
| 72 | echo "rke config --name cluster.yml" |
| 73 | echo "specifically" |
| 74 | echo "address: $SERVER" |
| 75 | echo "user: $USERNAME" |
| 76 | echo "ssh_key_path: $SSHPATH_PREFIX/$SSHKEY" |
| 77 | |
| 78 | RKETOOLS= |
| 79 | HYPERCUBE= |
| 80 | POD_INFRA_CONTAINER= |
| 81 | if [ "$RKE_VERSION" == "0.1.16" ]; then |
| 82 | RKETOOLS=0.1.15 |
| 83 | HYPERCUBE=1.11.6-rancher1 |
| 84 | POD_INFRA_CONTAINER=rancher/pause-amd64:3.1 |
| 85 | else |
| 86 | # 0.1.15 |
| 87 | RKETOOLS=0.1.14 |
| 88 | HYPERCUBE=1.11.3-rancher1 |
| 89 | POD_INFRA_CONTAINER=gcr.io.google_containers/pause-amd64:3.1 |
| 90 | fi |
| 91 | |
| 92 | cat > cluster.yml <<EOF |
| 93 | # generated from rke_setup.sh |
| 94 | nodes: |
| 95 | - address: $SERVER |
| 96 | port: "22" |
| 97 | internal_address: "" |
| 98 | role: |
| 99 | - controlplane |
| 100 | - worker |
| 101 | - etcd |
| 102 | hostname_override: "" |
| 103 | user: $USERNAME |
| 104 | docker_socket: /var/run/docker.sock |
| 105 | ssh_key: "" |
| 106 | ssh_key_path: $SSHPATH_PREFIX/$SSHKEY |
| 107 | labels: {} |
| 108 | services: |
| 109 | etcd: |
| 110 | image: "" |
| 111 | extra_args: {} |
| 112 | extra_binds: [] |
| 113 | extra_env: [] |
| 114 | external_urls: [] |
| 115 | ca_cert: "" |
| 116 | cert: "" |
| 117 | key: "" |
| 118 | path: "" |
| 119 | snapshot: null |
| 120 | retention: "" |
| 121 | creation: "" |
| 122 | kube-api: |
| 123 | image: "" |
| 124 | extra_args: {} |
| 125 | extra_binds: [] |
| 126 | extra_env: [] |
| 127 | service_cluster_ip_range: 10.43.0.0/16 |
| 128 | service_node_port_range: "" |
| 129 | pod_security_policy: false |
| 130 | kube-controller: |
| 131 | image: "" |
| 132 | extra_args: {} |
| 133 | extra_binds: [] |
| 134 | extra_env: [] |
| 135 | cluster_cidr: 10.42.0.0/16 |
| 136 | service_cluster_ip_range: 10.43.0.0/16 |
| 137 | scheduler: |
| 138 | image: "" |
| 139 | extra_args: {} |
| 140 | extra_binds: [] |
| 141 | extra_env: [] |
| 142 | kubelet: |
| 143 | image: "" |
| 144 | extra_args: |
| 145 | max-pods: 900 |
| 146 | extra_binds: [] |
| 147 | extra_env: [] |
| 148 | cluster_domain: cluster.local |
| 149 | infra_container_image: "" |
| 150 | cluster_dns_server: 10.43.0.10 |
| 151 | fail_swap_on: false |
| 152 | kubeproxy: |
| 153 | image: "" |
| 154 | extra_args: {} |
| 155 | extra_binds: [] |
| 156 | extra_env: [] |
| 157 | network: |
| 158 | plugin: canal |
| 159 | options: {} |
| 160 | authentication: |
| 161 | strategy: x509 |
| 162 | options: {} |
| 163 | sans: [] |
| 164 | system_images: |
| 165 | etcd: rancher/coreos-etcd:v3.2.18 |
| 166 | alpine: rancher/rke-tools:v$RKETOOLS |
| 167 | nginx_proxy: rancher/rke-tools:v$RKETOOLS |
| 168 | cert_downloader: rancher/rke-tools:v$RKETOOLS |
| 169 | kubernetes_services_sidecar: rancher/rke-tools:v$RKETOOLS |
| 170 | kubedns: rancher/k8s-dns-kube-dns-amd64:1.14.10 |
| 171 | dnsmasq: rancher/k8s-dns-dnsmasq-nanny-amd64:1.14.10 |
| 172 | kubedns_sidecar: rancher/k8s-dns-sidecar-amd64:1.14.10 |
| 173 | kubedns_autoscaler: rancher/cluster-proportional-autoscaler-amd64:1.0.0 |
| 174 | kubernetes: rancher/hyperkube:v$HYPERCUBE |
| 175 | flannel: rancher/coreos-flannel:v0.10.0 |
| 176 | flannel_cni: rancher/coreos-flannel-cni:v0.3.0 |
| 177 | calico_node: rancher/calico-node:v3.1.3 |
| 178 | calico_cni: rancher/calico-cni:v3.1.3 |
| 179 | calico_controllers: "" |
| 180 | calico_ctl: rancher/calico-ctl:v2.0.0 |
| 181 | canal_node: rancher/calico-node:v3.1.3 |
| 182 | canal_cni: rancher/calico-cni:v3.1.3 |
| 183 | canal_flannel: rancher/coreos-flannel:v0.10.0 |
| 184 | wave_node: weaveworks/weave-kube:2.1.2 |
| 185 | weave_cni: weaveworks/weave-npc:2.1.2 |
| 186 | pod_infra_container: $POD_INFRA_CONTAINER |
| 187 | ingress: rancher/nginx-ingress-controller:0.16.2-rancher1 |
| 188 | ingress_backend: rancher/nginx-ingress-controller-defaultbackend:1.4 |
| 189 | metrics_server: rancher/metrics-server-amd64:v0.2.1 |
| 190 | ssh_key_path: $SSHPATH |
| 191 | ssh_agent_auth: false |
| 192 | authorization: |
| 193 | mode: rbac |
| 194 | options: {} |
| 195 | ignore_docker_version: false |
| 196 | kubernetes_version: "$KUBERNETES_VERSION" |
| 197 | private_registries: [] |
| 198 | ingress: |
| 199 | provider: "" |
| 200 | options: {} |
| 201 | node_selector: {} |
| 202 | extra_args: {} |
| 203 | cluster_name: "" |
| 204 | cloud_provider: |
| 205 | name: "" |
| 206 | prefix_path: "" |
| 207 | addon_job_timeout: 0 |
| 208 | bastion_host: |
| 209 | address: "" |
| 210 | port: "" |
| 211 | user: "" |
| 212 | ssh_key: "" |
| 213 | ssh_key_path: "" |
| 214 | monitoring: |
| 215 | provider: "" |
| 216 | options: {} |
| 217 | EOF |
| 218 | |
| 219 | |
| 220 | |
| 221 | echo "Installing on ${SERVER} for ${BRANCH}: RKE: ${RKE_VERSION} Kubectl: ${KUBECTL_VERSION} Helm: ${HELM_VERSION} Docker: ${DOCKER_VERSION} username: ${USERNAME}" |
| 222 | sudo echo "127.0.0.1 ${SERVER}" >> /etc/hosts |
| 223 | echo "Install docker - If you must install as non-root - comment out the docker install below - run it separately, run the user mod, logout/login and continue this script" |
| 224 | curl https://releases.rancher.com/install-docker/$DOCKER_VERSION.sh | sh |
| 225 | sudo usermod -aG docker $USERNAME |
| 226 | |
| 227 | echo "Install RKE" |
| 228 | sudo wget https://github.com/rancher/rke/releases/download/v$RKE_VERSION/rke_linux-amd64 |
| 229 | mv rke_linux-amd64 rke |
| 230 | sudo chmod +x rke |
| 231 | sudo mv ./rke /usr/local/bin/rke |
| 232 | |
| 233 | echo "Install make - required for beijing+ - installed via yum groupinstall Development Tools in RHEL" |
| 234 | # ubuntu specific |
| 235 | sudo apt-get install make -y |
| 236 | |
| 237 | sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/v$KUBECTL_VERSION/bin/linux/amd64/kubectl |
| 238 | sudo chmod +x ./kubectl |
| 239 | sudo mv ./kubectl /usr/local/bin/kubectl |
| 240 | sudo mkdir ~/.kube |
| 241 | wget http://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-linux-amd64.tar.gz |
| 242 | sudo tar -zxvf helm-v${HELM_VERSION}-linux-amd64.tar.gz |
| 243 | sudo mv linux-amd64/helm /usr/local/bin/helm |
| 244 | |
| 245 | echo "Bringing RKE up - using supplied cluster.yml" |
| 246 | sudo rke up |
| 247 | echo "wait 2 extra min for the cluster" |
| 248 | sleep 60 |
| 249 | echo "1 more min" |
| 250 | sleep 60 |
| 251 | echo "copy kube_config_cluter.yaml generated - to ~/.kube/config" |
| 252 | sudo cp kube_config_cluster.yml ~/.kube/config |
| 253 | # avoid using sudo for kubectl |
| 254 | sudo chmod 777 ~/.kube/config |
| 255 | echo "Verify all pods up on the kubernetes system - will return localhost:8080 until a host is added" |
| 256 | echo "kubectl get pods --all-namespaces" |
| 257 | kubectl get pods --all-namespaces |
| 258 | echo "install tiller/helm" |
| 259 | kubectl -n kube-system create serviceaccount tiller |
| 260 | kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller |
| 261 | helm init --service-account tiller |
| 262 | kubectl -n kube-system rollout status deploy/tiller-deploy |
| 263 | echo "upgrade server side of helm in kubernetes" |
| 264 | if [ "$USERNAME" == "root" ]; then |
| 265 | helm version |
| 266 | else |
| 267 | sudo helm version |
| 268 | fi |
| 269 | echo "sleep 30" |
| 270 | sleep 30 |
| 271 | if [ "$USERNAME" == "root" ]; then |
| 272 | helm init --upgrade |
| 273 | else |
| 274 | sudo helm init --upgrade |
| 275 | fi |
| 276 | echo "sleep 30" |
| 277 | sleep 30 |
| 278 | echo "verify both versions are the same below" |
| 279 | if [ "$USERNAME" == "root" ]; then |
| 280 | helm version |
| 281 | else |
| 282 | sudo helm version |
| 283 | fi |
| 284 | echo "start helm server" |
| 285 | if [ "$USERNAME" == "root" ]; then |
| 286 | helm serve & |
| 287 | else |
| 288 | sudo helm serve & |
| 289 | fi |
| 290 | echo "sleep 30" |
| 291 | sleep 30 |
| 292 | echo "add local helm repo" |
| 293 | if [ "$USERNAME" == "root" ]; then |
| 294 | helm repo add local http://127.0.0.1:8879 |
| 295 | helm repo list |
| 296 | else |
| 297 | sudo helm repo add local http://127.0.0.1:8879 |
| 298 | sudo helm repo list |
| 299 | fi |
| 300 | echo "To enable grafana dashboard - do this after running cd.sh which brings up onap - or you may get a 302xx port conflict" |
| 301 | echo "kubectl expose -n kube-system deployment monitoring-grafana --type=LoadBalancer --name monitoring-grafana-client" |
| 302 | echo "to get the nodeport for a specific VM running grafana" |
| 303 | echo "kubectl get services --all-namespaces | grep graf" |
| 304 | sudo docker version |
| 305 | helm version |
| 306 | kubectl version |
| 307 | kubectl get services --all-namespaces |
| 308 | kubectl get pods --all-namespaces |
| 309 | echo "finished!" |
| 310 | } |
| 311 | |
| 312 | BRANCH= |
| 313 | SERVER= |
| 314 | ENVIRON= |
| 315 | VALIDATE=false |
| 316 | USERNAME=ubuntu |
| 317 | SSHPATH_PREFIX=~/.ssh |
| 318 | |
| 319 | while getopts ":b:s:e:u:l:k:v" PARAM; do |
| 320 | case $PARAM in |
| 321 | u) |
| 322 | usage |
| 323 | exit 1 |
| 324 | ;; |
| 325 | b) |
| 326 | BRANCH=${OPTARG} |
| 327 | ;; |
| 328 | e) |
| 329 | ENVIRON=${OPTARG} |
| 330 | ;; |
| 331 | s) |
| 332 | SERVER=${OPTARG} |
| 333 | ;; |
| 334 | l) |
| 335 | USERNAME=${OPTARG} |
| 336 | ;; |
| 337 | k) |
| 338 | SSHKEY=${OPTARG} |
| 339 | ;; |
| 340 | v) |
| 341 | VALIDATE=${OPTARG} |
| 342 | ;; |
| 343 | ?) |
| 344 | usage |
| 345 | exit |
| 346 | ;; |
| 347 | esac |
| 348 | done |
| 349 | |
| 350 | if [[ -z $BRANCH ]]; then |
| 351 | usage |
| 352 | exit 1 |
| 353 | fi |
| 354 | |
| 355 | install_onap $BRANCH $SERVER $ENVIRON $USERNAME $SSHPATH_PREFIX $SSHKEY $VALIDATE |