From ea83d035d863452d738abca47b966defb9a35456 Mon Sep 17 00:00:00 2001 From: wrider Date: Tue, 4 Jun 2019 22:31:18 -0400 Subject: [PATCH] R1 k8s cluster deployment Added a dryrun option for the deploy-stack script. Change-Id: I9b526ee0b0efdbe63338b92d3577a9fd32068e62 Signed-off-by: wrider --- ric-infra/00-Kubernetes/README.md | 73 +++++ ric-infra/00-Kubernetes/bin/deploy-stack.sh | 315 ++++++++++++++++++ ric-infra/00-Kubernetes/bin/gen-cloud-init.sh | 140 ++++++++ ric-infra/00-Kubernetes/bin/gen-ric-heat-yaml.sh | 91 ++++++ ric-infra/00-Kubernetes/bin/install | 45 ++- ric-infra/00-Kubernetes/bin/install-1node-k8s | 363 --------------------- ric-infra/00-Kubernetes/bin/undeploy-stack.sh | 75 +++++ ric-infra/00-Kubernetes/etc/env.rc | 49 +++ ric-infra/00-Kubernetes/etc/infra.rc | 6 + ric-infra/00-Kubernetes/etc/openstack.rc | 32 ++ ric-infra/00-Kubernetes/heat/env/aux.env | 44 +++ ric-infra/00-Kubernetes/heat/env/ric.env | 49 +++ ric-infra/00-Kubernetes/heat/parts/part-1-v6.yaml | 173 ++++++++++ ric-infra/00-Kubernetes/heat/parts/part-1.yaml | 189 +++++++++++ ric-infra/00-Kubernetes/heat/parts/part-2-v6.yaml | 105 ++++++ ric-infra/00-Kubernetes/heat/parts/part-2.yaml | 75 +++++ ric-infra/00-Kubernetes/heat/parts/part-3-v6.yaml | 3 + ric-infra/00-Kubernetes/heat/parts/part-3.yaml | 4 + .../heat/scripts/k8s_vm_aux_install.sh | 95 ++++++ .../heat/scripts/k8s_vm_custom_repos.sh | 34 ++ .../{etc/k8s-1node => heat/scripts/k8s_vm_init.sh} | 18 +- .../00-Kubernetes/heat/scripts/k8s_vm_init_serv.sh | 117 +++++++ .../00-Kubernetes/heat/scripts/k8s_vm_install.sh | 308 +++++++++++++++++ 23 files changed, 2022 insertions(+), 381 deletions(-) create mode 100644 ric-infra/00-Kubernetes/README.md create mode 100755 ric-infra/00-Kubernetes/bin/deploy-stack.sh create mode 100755 ric-infra/00-Kubernetes/bin/gen-cloud-init.sh create mode 100755 ric-infra/00-Kubernetes/bin/gen-ric-heat-yaml.sh delete mode 100755 ric-infra/00-Kubernetes/bin/install-1node-k8s create mode 100755 ric-infra/00-Kubernetes/bin/undeploy-stack.sh create mode 100644 ric-infra/00-Kubernetes/etc/env.rc create mode 100644 ric-infra/00-Kubernetes/etc/infra.rc create mode 100644 ric-infra/00-Kubernetes/etc/openstack.rc create mode 100644 ric-infra/00-Kubernetes/heat/env/aux.env create mode 100644 ric-infra/00-Kubernetes/heat/env/ric.env create mode 100644 ric-infra/00-Kubernetes/heat/parts/part-1-v6.yaml create mode 100644 ric-infra/00-Kubernetes/heat/parts/part-1.yaml create mode 100644 ric-infra/00-Kubernetes/heat/parts/part-2-v6.yaml create mode 100644 ric-infra/00-Kubernetes/heat/parts/part-2.yaml create mode 100644 ric-infra/00-Kubernetes/heat/parts/part-3-v6.yaml create mode 100644 ric-infra/00-Kubernetes/heat/parts/part-3.yaml create mode 100644 ric-infra/00-Kubernetes/heat/scripts/k8s_vm_aux_install.sh create mode 100644 ric-infra/00-Kubernetes/heat/scripts/k8s_vm_custom_repos.sh rename ric-infra/00-Kubernetes/{etc/k8s-1node => heat/scripts/k8s_vm_init.sh} (80%) create mode 100644 ric-infra/00-Kubernetes/heat/scripts/k8s_vm_init_serv.sh create mode 100644 ric-infra/00-Kubernetes/heat/scripts/k8s_vm_install.sh diff --git a/ric-infra/00-Kubernetes/README.md b/ric-infra/00-Kubernetes/README.md new file mode 100644 index 00000000..71dfb6c0 --- /dev/null +++ b/ric-infra/00-Kubernetes/README.md @@ -0,0 +1,73 @@ +### Introduction + +This directory contains configurations, templates, and scripts for deploying a Kubernetes cluster for RIC and other AUX functions. + +Two methods of deployment are supported: +- Single node Kubernetes cluster deployment: + - A cloud init script that installs the docker-kubernetes-helm stack onto a VM launched using cloud Ubuntu 16.04 image. + - The same script can be run on a newly launched VM using cloud Ubuntu 16.04 image to install the same infrastructure software stack. +- Multi-node, dual-cluster deployment: + - Using OpenStack Heat Orchestration Template, calling OpenStack stack creation API to create two sets of VMs, one for RIC cluster and the other for AUX cluster. + - Installing docker-kubernetes-helm stack on each of the VMs. + - Configuring each set of VMs into a Kubernets cluster. + - Configure well-known host name resolutions. + +### Directory Structure +- bin + - deploy-stack.sh + - gen-cloud-init.sh + - gen-ric-heat-yaml.sh + - install + - undeploy-stack.sh +- etc + - env.rc + - infra.rc + - openstack.rc +- heat + - env + - aux.env + - ric.env + - parts + - part-1-v6.yaml + - part-1.yaml + - part-2-v6.yaml + - part-2.yaml + - part-3-v6.yaml + - part-3.yaml + - scripts + - k8s_vm_aux_install.sh + - k8s_vm_custom_repos.sh + - k8s_vm_init.sh + - k8s_vm_init_serv.sh + - k8s_vm_install.sh + + +### Configuration +All configurations are under etc directory +- env.rc + - This file contains configurations for Gerrit, Helm, and Docker registry that will be used for hosting artifacts for the deployment. +- infra.rc + - This file contains configuratuions infrastructure software stack, e.g. versions of docker, Kubernetes, and Helm software to be installed. + - Normally there is no need to modify this file. +- openstack.rc + - This file contains configuratuions for the local OpenStack instance that will be used for deploying the Heat stacks. + + +### Deploying 1-node Kubernetes + +1. Must complete the local configuration in etc/env.rc file. +2. cd bin +3. ./gen-cloud-init.sh +4. The generated cloud init file is named k8s-1node-cloud-init.sh +5. Use the generate k8s-1node-cloud-init.sh script: + a. At VM launch time, paste in the contents of the k8s-1node-cloud-init.sh file to the "Customnization script" window of the "Configuration" step, when using Horizon dashboard to launch new VM. + b. Copy the k8s-1node-cloud-init.sh file to a newly launched cloud image Ubuntu 16.04 VM. Run the script in a "sudo -i" shell. +6. After the execution of the script is completed, run "kubectl get pods --all-namespaces" to check. + +### Deploying Dual Kubernetes Cluster +1. Must complete the local configuration in etc/env.rc and etc/openstack.rc files. +2. cd bin +3. ./install +4. After the execution is completed, go to WORKDIR_ric and WORKDIR_aux to see the file that contains the IP addresses of the VMs. +5. ssh into the -mst VMs (master nodes) of the clusters, run run "kubectl get pods --all-namespaces" to check. + diff --git a/ric-infra/00-Kubernetes/bin/deploy-stack.sh b/ric-infra/00-Kubernetes/bin/deploy-stack.sh new file mode 100755 index 00000000..fd350b66 --- /dev/null +++ b/ric-infra/00-Kubernetes/bin/deploy-stack.sh @@ -0,0 +1,315 @@ +#!/bin/bash +################################################################################ +# Copyright (c) 2019 AT&T Intellectual Property. # +# Copyright (c) 2019 Nokia. # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ + +set -e + +stack_name="ric" +full_deletion=false + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +set -a +RCS="$(find $DIR/../etc -type f -maxdepth 1)" +for RC in $RCS; do + echo "reading in values in $RC" + source $RC +done +set +a + + +if [ -z "$__RUNRICENV_GERRIT_HOST__" ]; then + export __RUNRICENV_GERRIT_HOST__=$gerrithost +fi +if [ -z "$__RUNRICENV_GERRIT_IP__" ]; then + export __RUNRICENV_GERRIT_IP__=$gerritip +fi +if [ -z "$__RUNRICENV_DOCKER_HOST__" ]; then + export __RUNRICENV_DOCKER_HOST__=$dockerregistry +fi +if [ -z "$__RUNRICENV_DOCKER_IP__" ]; then + export __RUNRICENV_DOCKER_IP__=$dockerip +fi +if [ -z "$__RUNRICENV_DOCKER_PORT__" ]; then + export __RUNRICENV_DOCKER_PORT__=$dockerport +fi +if [ -z "$__RUNRICENV_DOCKER_USER__" ]; then + export __RUNRICENV_DOCKER_USER__=$dockeruser +fi +if [ -z "$__RUNRICENV_DOCKER_PASS__" ]; then + export __RUNRICENV_DOCKER_PASS__=$dockerpassword +fi +if [ -z "$__RUNRICENV_DOCKER_CERT__" ]; then + export __RUNRICENV_DOCKER_CERT__=$dockercert +fi +if [ -z "$__RUNRICENV_HELMREPO_HOST__" ]; then + export __RUNRICENV_HELMREPO_HOST__=$helmrepo +fi +if [ -z "$__RUNRICENV_HELMREPO_PORT__" ]; then + export __RUNRICENV_HELMREPO_PORT__=$helmport +fi +if [ -z "$__RUNRICENV_HELMREPO_IP__" ]; then + export __RUNRICENV_HELMREPO_IP__=$helmip +fi +if [ -z "$__RUNRICENV_HELMREPO_USER__" ]; then + export __RUNRICENV_HELMREPO_USER__=$helmuser +fi +if [ -z "$__RUNRICENV_HELMREPO_PASS__" ]; then + export __RUNRICENV_HELMREPO_PASS__=$helmpassword +fi +if [ -z "$__RUNRICENV_HELMREPO_CERT__" ]; then + export __RUNRICENV_HELMREPO_CERT__=$helmcert +fi + + +if [ -z "$WORKSPACE" ]; then + export WORKSPACE=`git rev-parse --show-toplevel` +fi +HEAT_DIR="$WORKSPACE/ric-infra/00-Kubernetes/heat" +BIN_DIR="$WORKSPACE/ric-infra/00-Kubernetes/bin" +ETC_DIR="$WORKSPACE/ric-infra/00-Kubernetes/etc" +ENV_DIR="$WORKSPACE/ric-infra/00-Kubernetes/heat/env" + + +cd $BIN_DIR + + +openstack --version > /dev/null +if [ $? -eq 0 ]; then + echo "OK openstack CLI installed" +else + echo "Must run in an envirnment with openstack cli" + exit 1 +fi + +if [ -z "$OS_USERNAME" ]; then + echo "Must source the Openstack RC file for the target installation tenant" + exit 1 +fi + + +usage() { + echo "Usage: $0 [ -n ][ -s ]