blob: a8938a96ee1167455dd17077688b23b3ffdb36b3 [file] [log] [blame]
Guillaume Lambert85b14922021-03-12 13:53:18 +01001#!/bin/sh
2
Michael O'Briena3eb4e12019-02-23 19:44:56 -05003#############################################################################
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
Michael O'Brienb9831142019-04-29 16:36:14 -040021# this installation can be run on any ubuntu 16.04/18.04 VM, RHEL 7.6 (root only), physical or cloud azure/aws host
Michael O'Briena3eb4e12019-02-23 19:44:56 -050022# https://wiki.onap.org/display/DW/OOM+RKE+Kubernetes+Deployment
23# source from https://jira.onap.org/browse/OOM-1598
24#
Sylvain Desbureaux5e19e242020-03-02 14:41:48 +010025# master/dublin
Michael O'Briena3eb4e12019-02-23 19:44:56 -050026# RKE 0.1.16 Kubernetes 1.11.6, kubectl 1.11.6, Helm 2.9.1, Docker 18.06
Michael O'Brienb9831142019-04-29 16:36:14 -040027# 20190428 RKE 0.2.1, Kubernetes 1.13.5, kubectl 1.13.5, Helm 2.12.3, Docker 18.09.5
Michael O'Briena3eb4e12019-02-23 19:44:56 -050028# single node install, HA pending
29
30usage() {
31cat <<EOF
32Usage: $0 [PARAMs]
33example
Sylvain Desbureaux5e19e242020-03-02 14:41:48 +010034sudo ./rke_setup.sh -b master -s rke.onap.cloud -e onap -l amdocs -v true
Michael O'Briena3eb4e12019-02-23 19:44:56 -050035-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)
41EOF
42}
43
44install_onap() {
45 #constants
46 PORT=8880
Michael O'Brienb9831142019-04-29 16:36:14 -040047 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
Sylvain Desbureaux5e19e242020-03-02 14:41:48 +010052
Michael O'Briena3eb4e12019-02-23 19:44:56 -050053 # copy your private ssh key and cluster.yml file to the vm
54 # on your dev machine
55 #sudo cp ~/.ssh/onap_rsa .
Sylvain Desbureaux5e19e242020-03-02 14:41:48 +010056 #sudo chmod 777 onap_rsa
Michael O'Briena3eb4e12019-02-23 19:44:56 -050057 #scp onap_rsa ubuntu@192.168.241.132:~/
58 # on this vm
Sylvain Desbureaux5e19e242020-03-02 14:41:48 +010059 #sudo chmod 400 onap_rsa
Michael O'Briena3eb4e12019-02-23 19:44:56 -050060 #sudo cp onap_rsa ~/.ssh
Sylvain Desbureaux5e19e242020-03-02 14:41:48 +010061 # make sure public key is insetup correctly in
Michael O'Briena3eb4e12019-02-23 19:44:56 -050062 # 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/"
Michael O'Brienb9831142019-04-29 16:36:14 -040065 echo "The RKE version specific cluster.yaml is already integrated in this script for 0.2.1 no need for below generation..."
Michael O'Briena3eb4e12019-02-23 19:44:56 -050066 echo "rke config --name cluster.yml"
67 echo "specifically"
68 echo "address: $SERVER"
69 echo "user: $USERNAME"
Sylvain Desbureaux5e19e242020-03-02 14:41:48 +010070 echo "ssh_key_path: $SSHPATH_PREFIX/$SSHKEY"
71
Michael O'Briena3eb4e12019-02-23 19:44:56 -050072 RKETOOLS=
73 HYPERCUBE=
74 POD_INFRA_CONTAINER=
Michael O'Brienb9831142019-04-29 16:36:14 -040075 RKETOOLS=0.1.27
76 HYPERCUBE=1.13.5-rancher1
77 POD_INFRA_CONTAINER=rancher/pause:3.1
Michael O'Briena3eb4e12019-02-23 19:44:56 -050078
79 cat > cluster.yml <<EOF
80# generated from rke_setup.sh
81nodes:
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
Michael O'Brienb9831142019-04-29 16:36:14 -040094 ssh_cert: ""
95 ssh_cert_path: ""
Michael O'Briena3eb4e12019-02-23 19:44:56 -050096 labels: {}
97services:
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: ""
Michael O'Brienb9831142019-04-29 16:36:14 -0400111 backup_config: null
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500112 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
Michael O'Brienb9831142019-04-29 16:36:14 -0400120 always_pull_images: false
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500121 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: []
148network:
149 plugin: canal
150 options: {}
151authentication:
152 strategy: x509
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500153 sans: []
Michael O'Brienb9831142019-04-29 16:36:14 -0400154 webhook: null
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500155system_images:
Michael O'Brienb9831142019-04-29 16:36:14 -0400156 etcd: rancher/coreos-etcd:v3.2.24-rancher1
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500157 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
Michael O'Brienb9831142019-04-29 16:36:14 -0400161 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
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500165 kubernetes: rancher/hyperkube:v$HYPERCUBE
Michael O'Brienb9831142019-04-29 16:36:14 -0400166 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
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500170 calico_controllers: ""
171 calico_ctl: rancher/calico-ctl:v2.0.0
Michael O'Brienb9831142019-04-29 16:36:14 -0400172 canal_node: rancher/calico-node:v3.4.0
173 canal_cni: rancher/calico-cni:v3.4.0
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500174 canal_flannel: rancher/coreos-flannel:v0.10.0
Michael O'Brienb9831142019-04-29 16:36:14 -0400175 wave_node: weaveworks/weave-kube:2.5.0
176 weave_cni: weaveworks/weave-npc:2.5.0
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500177 pod_infra_container: $POD_INFRA_CONTAINER
Michael O'Brienb9831142019-04-29 16:36:14 -0400178 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
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500181ssh_key_path: $SSHPATH
Michael O'Brienb9831142019-04-29 16:36:14 -0400182ssh_cert_path: ""
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500183ssh_agent_auth: false
184authorization:
185 mode: rbac
186 options: {}
187ignore_docker_version: false
188kubernetes_version: "$KUBERNETES_VERSION"
189private_registries: []
190ingress:
191 provider: ""
192 options: {}
193 node_selector: {}
194 extra_args: {}
195cluster_name: ""
196cloud_provider:
197 name: ""
198prefix_path: ""
199addon_job_timeout: 0
200bastion_host:
201 address: ""
202 port: ""
203 user: ""
204 ssh_key: ""
205 ssh_key_path: ""
Michael O'Brienb9831142019-04-29 16:36:14 -0400206 ssh_cert: ""
207 ssh_cert_path: ""
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500208monitoring:
209 provider: ""
210 options: {}
Michael O'Brienb9831142019-04-29 16:36:14 -0400211restore:
212 restore: false
213 snapshot_name: ""
214dns: null
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500215EOF
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"
Guillaume Lambert5f4af052021-03-09 21:52:32 +0100262 if [ "$USERNAME" = "root" ]; then
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500263 helm version
264 else
265 sudo helm version
266 fi
267 echo "sleep 30"
268 sleep 30
Guillaume Lambert5f4af052021-03-09 21:52:32 +0100269 if [ "$USERNAME" = "root" ]; then
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500270 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"
Guillaume Lambert5f4af052021-03-09 21:52:32 +0100277 if [ "$USERNAME" = "root" ]; then
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500278 helm version
279 else
280 sudo helm version
281 fi
282 echo "start helm server"
Guillaume Lambert5f4af052021-03-09 21:52:32 +0100283 if [ "$USERNAME" = "root" ]; then
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500284 helm serve &
285 else
286 sudo helm serve &
287 fi
288 echo "sleep 30"
289 sleep 30
290 echo "add local helm repo"
Guillaume Lambert5f4af052021-03-09 21:52:32 +0100291 if [ "$USERNAME" = "root" ]; then
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500292 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
310BRANCH=
311SERVER=
312ENVIRON=
313VALIDATE=false
314USERNAME=ubuntu
315SSHPATH_PREFIX=~/.ssh
316
317while 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
346done
347
Guillaume Lambert7abd8c32021-04-26 21:48:38 +0200348if [ -z $BRANCH ]; then
Michael O'Briena3eb4e12019-02-23 19:44:56 -0500349 usage
350 exit 1
351fi
352
353install_onap $BRANCH $SERVER $ENVIRON $USERNAME $SSHPATH_PREFIX $SSHKEY $VALIDATE