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