diff options
author | Areli Fuss <af732p@att.com> | 2018-02-01 13:09:07 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2018-02-06 17:57:29 +0000 |
commit | 471a29706bfc3ed50a6c66f96ee6575fc2e3087b (patch) | |
tree | cce1286f59676a2f7097cb34146cfa94940d65b4 /sdc-os-chef/scripts | |
parent | 00c6ec7d386bd27c7752cf86e4692669e8b850ab (diff) |
Add K8S deployment above Vagrant
Set deployment manifest files and scripts
for deploy SDC over Kubernetes inside
Vagrant
Preparation for OOM integration
Change-Id: I1f54b95067538f42d2d68fa3366b512dc9134f43
Issue-ID: SDC-907
Signed-off-by: Areli Fuss <af732p@att.com>
Diffstat (limited to 'sdc-os-chef/scripts')
-rw-r--r-- | sdc-os-chef/scripts/k8s/build_nsenter_exec.sh | 22 | ||||
-rw-r--r-- | sdc-os-chef/scripts/k8s/deploy_k8s_sdc.sh | 74 | ||||
-rw-r--r-- | sdc-os-chef/scripts/k8s/etc/bash_completion.d/nsenter | 63 | ||||
-rwxr-xr-x | sdc-os-chef/scripts/k8s/get_helm.sh | 230 | ||||
-rw-r--r-- | sdc-os-chef/scripts/k8s/install_helm.sh | 20 | ||||
-rw-r--r-- | sdc-os-chef/scripts/k8s/install_kubectl.sh | 19 | ||||
-rw-r--r-- | sdc-os-chef/scripts/k8s/install_minikube.sh | 18 | ||||
-rw-r--r-- | sdc-os-chef/scripts/k8s/kubernetes_run.sh | 77 |
8 files changed, 523 insertions, 0 deletions
diff --git a/sdc-os-chef/scripts/k8s/build_nsenter_exec.sh b/sdc-os-chef/scripts/k8s/build_nsenter_exec.sh new file mode 100644 index 0000000000..7ee1196d98 --- /dev/null +++ b/sdc-os-chef/scripts/k8s/build_nsenter_exec.sh @@ -0,0 +1,22 @@ +# Ubuntu 14.04 don't have nsenter - the straight forward way required me to install build tools and etc. +# I preferred to keep the system clean and install nsenter in a container and then copy the command to the host +# Note - its also possible to run nsenter from a container (didn't tried) https://github.com/jpetazzo/nsenter + +# start a container +docker run --name nsenter -it ubuntu:14.04 bash + +## in the docker +apt-get update +apt-get install git build-essential libncurses5-dev libslang2-dev gettext zlib1g-dev libselinux1-dev debhelper lsb-release pkg-config po-debconf autoconf automake autopoint libtool bison + +git clone git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git util-linux +cd util-linux/ + +./autogen.sh +./configure --without-python --disable-all-programs --enable-nsenter +make + +## from different shell - on the host +echo "[Action requires] From different shell on the host run the following:" +docker cp nsenter:/util-linux/nsenter /usr/local/bin/ +docker cp nsenter:/util-linux/bash-completion/nsenter /etc/bash_completion.d/nsenter
\ No newline at end of file diff --git a/sdc-os-chef/scripts/k8s/deploy_k8s_sdc.sh b/sdc-os-chef/scripts/k8s/deploy_k8s_sdc.sh new file mode 100644 index 0000000000..9a7b57747b --- /dev/null +++ b/sdc-os-chef/scripts/k8s/deploy_k8s_sdc.sh @@ -0,0 +1,74 @@ +#!/bin/sh +set -x + +check_status() +{ + local rc=$1 + shift + local comment="$@" + if [ ${rc} != 0 ]; then + echo "[ERR] Failure detected - ${comment}. Aborting !" + exit 255 + fi +} + + +# Should be removed while private dockers (maven build) will be available: +echo "[INFO] ONAP Docker login" +sudo docker login -u docker -p docker nexus3.onap.org:10001 +check_status $? "Onap docker registry login" + +# Verify the kube-system pods are running: +# kube-addon-manager, kube-dns, kubernetes-dashboard, storage-provisioner, tiller-deploy +echo "[INFO] Wait for Kubernetes Service ..." +cd ../../kubernetes +status=0 +while [ ${status} -ne 5 ] +do + status=$(sudo kubectl get pods --namespace kube-system -o json \ + | jq -r ' + .items[] + | select(.status.phase == "Running" and + ([ .status.conditions[] | select(.type == "Ready" and .status == "True") ] + | length ) == 1 ) + | .metadata.namespace + "/" + .metadata.name + ' \ + | wc -l ) + sleep 3 +done + +# Create namespace +echo "[INFO] Check Namespace existence" +exist_namespace=$( sudo kubectl get namespaces | grep onap-sdc | grep Active | wc -l ) +if [ ${exist_namespace} -eq 0 ]; then + sudo kubectl create namespace onap-sdc + check_status $? "Create namespace" +fi + +echo "[INFO] Running helm init" +sudo helm init +check_status $? "Helm init" + +set -x + +printf "[INFO] Wait for helm to get ready\n" +helm_health=1 +while [ ${helm_health} -ne 0 ] +do + sudo helm version | grep "Server" >/dev/null 2>&1 + helm_health=$? + sleep 5 +done + +# Remove previous chart +exist_chart=$( sudo helm ls onap-sdc -q | wc -l ) +if [ ${exist_chart} -ne 0 ];then + echo "[INFO] Delete the existing onap-sdc chart" + sudo helm del --purge onap-sdc + check_status $? "Delete chart" +fi + +# Install updated chart +echo "[INFO] Create onap-sdc deployment" +sudo helm install sdc --name onap-sdc +check_status $? "Install chart" diff --git a/sdc-os-chef/scripts/k8s/etc/bash_completion.d/nsenter b/sdc-os-chef/scripts/k8s/etc/bash_completion.d/nsenter new file mode 100644 index 0000000000..ad56f06e48 --- /dev/null +++ b/sdc-os-chef/scripts/k8s/etc/bash_completion.d/nsenter @@ -0,0 +1,63 @@ +_nsenter_module() +{ + local cur prev OPTS + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + case $prev in + '-S'|'--uid') + COMPREPLY=( $(compgen -W "uid" -- $cur) ) + return 0 + ;; + '-G'|'--gid') + COMPREPLY=( $(compgen -W "gid" -- $cur) ) + return 0 + ;; + '-t'|'--target') + local PIDS + PIDS=$(cd /proc && echo [0-9]*) + COMPREPLY=( $(compgen -W "$PIDS" -- $cur) ) + return 0 + ;; + '-h'|'--help'|'-V'|'--version') + return 0 + ;; + esac + case $cur in + '=') + # FIXME: --root and --wd should use get only + # directories as compgen output. If $cur is + # overwrote the same way as below in case segment + # for $prev the command-line will get mangled. + cur=${cur#=} + ;; + -*) + OPTS=" + --all + --target + --mount= + --uts= + --ipc= + --net= + --pid= + --cgroup= + --user= + --setuid + --setgid + --preserve-credentials + --root= + --wd= + --no-fork + --help + --version + " + COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) + return 0 + ;; + esac + local IFS=$'\n' + compopt -o filenames + COMPREPLY=( $(compgen -f -- $cur) ) + return 0 +} +complete -F _nsenter_module nsenter diff --git a/sdc-os-chef/scripts/k8s/get_helm.sh b/sdc-os-chef/scripts/k8s/get_helm.sh new file mode 100755 index 0000000000..79e9f35203 --- /dev/null +++ b/sdc-os-chef/scripts/k8s/get_helm.sh @@ -0,0 +1,230 @@ +#!/usr/bin/env bash + +# Copyright 2016 The Kubernetes Authors All rights reserved. +# +# 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. + +# The install script is based off of the MIT-licensed script from glide, +# the package manager for Go: https://github.com/Masterminds/glide.sh/blob/master/get + +PROJECT_NAME="helm" + +: ${HELM_INSTALL_DIR:="/usr/local/bin"} + +# initArch discovers the architecture for this system. +initArch() { + ARCH=$(uname -m) + case $ARCH in + armv5*) ARCH="armv5";; + armv6*) ARCH="armv6";; + armv7*) ARCH="armv7";; + aarch64) ARCH="arm64";; + x86) ARCH="386";; + x86_64) ARCH="amd64";; + i686) ARCH="386";; + i386) ARCH="386";; + esac +} + +# initOS discovers the operating system for this system. +initOS() { + OS=$(echo `uname`|tr '[:upper:]' '[:lower:]') + + case "$OS" in + # Minimalist GNU for Windows + mingw*) OS='windows';; + esac +} + +# runs the given command as root (detects if we are root already) +runAsRoot() { + local CMD="$*" + + if [ $EUID -ne 0 ]; then + CMD="sudo $CMD" + fi + + $CMD +} + +# verifySupported checks that the os/arch combination is supported for +# binary builds. +verifySupported() { + local supported="darwin-386\ndarwin-amd64\nlinux-386\nlinux-amd64\nlinux-arm\nlinux-arm64\nlinux-ppc64le\nwindows-386\nwindows-amd64" + if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then + echo "No prebuilt binary for ${OS}-${ARCH}." + echo "To build from source, go to https://github.com/kubernetes/helm" + exit 1 + fi + + if ! type "curl" > /dev/null && ! type "wget" > /dev/null; then + echo "Either curl or wget is required" + exit 1 + fi +} + +# checkDesiredVersion checks if the desired version is available. +checkDesiredVersion() { + # Use the GitHub releases webpage for the project to find the desired version for this project. + local release_url="https://github.com/kubernetes/helm/releases/${DESIRED_VERSION:-latest}" + if type "curl" > /dev/null; then + TAG=$(curl -SsL $release_url | awk '/\/tag\//' | cut -d '"' -f 2 | awk '{n=split($NF,a,"/");print a[n]}' | awk 'a !~ $0{print}; {a=$0}') + elif type "wget" > /dev/null; then + TAG=$(wget -q -O - $release_url | awk '/\/tag\//' | cut -d '"' -f 2 | awk '{n=split($NF,a,"/");print a[n]}' | awk 'a !~ $0{print}; {a=$0}') + fi + if [ "x$TAG" == "x" ]; then + echo "Cannot determine ${DESIRED_VERSION} tag." + exit 1 + fi +} + +# checkHelmInstalledVersion checks which version of helm is installed and +# if it needs to be changed. +checkHelmInstalledVersion() { + if [[ -f "${HELM_INSTALL_DIR}/${PROJECT_NAME}" ]]; then + local version=$(helm version | grep '^Client' | cut -d'"' -f2) + if [[ "$version" == "$TAG" ]]; then + echo "Helm ${version} is already ${DESIRED_VERSION:-latest}" + return 0 + else + echo "Helm ${TAG} is available. Changing from version ${version}." + return 1 + fi + else + return 1 + fi +} + +# downloadFile downloads the latest binary package and also the checksum +# for that binary. +downloadFile() { + HELM_DIST="helm-$TAG-$OS-$ARCH.tar.gz" + DOWNLOAD_URL="https://kubernetes-helm.storage.googleapis.com/$HELM_DIST" + CHECKSUM_URL="$DOWNLOAD_URL.sha256" + HELM_TMP_ROOT="$(mktemp -dt helm-installer-XXXXXX)" + HELM_TMP_FILE="$HELM_TMP_ROOT/$HELM_DIST" + HELM_SUM_FILE="$HELM_TMP_ROOT/$HELM_DIST.sha256" + echo "Downloading $DOWNLOAD_URL" + if type "curl" > /dev/null; then + curl -SsL "$CHECKSUM_URL" -o "$HELM_SUM_FILE" + elif type "wget" > /dev/null; then + wget -q -O "$HELM_SUM_FILE" "$CHECKSUM_URL" + fi + if type "curl" > /dev/null; then + curl -SsL "$DOWNLOAD_URL" -o "$HELM_TMP_FILE" + elif type "wget" > /dev/null; then + wget -q -O "$HELM_TMP_FILE" "$DOWNLOAD_URL" + fi +} + +# installFile verifies the SHA256 for the file, then unpacks and +# installs it. +installFile() { + HELM_TMP="$HELM_TMP_ROOT/$PROJECT_NAME" + local sum=$(openssl sha1 -sha256 ${HELM_TMP_FILE} | awk '{print $2}') + local expected_sum=$(cat ${HELM_SUM_FILE}) + if [ "$sum" != "$expected_sum" ]; then + echo "SHA sum of $HELM_TMP does not match. Aborting." + exit 1 + fi + + mkdir -p "$HELM_TMP" + tar xf "$HELM_TMP_FILE" -C "$HELM_TMP" + HELM_TMP_BIN="$HELM_TMP/$OS-$ARCH/$PROJECT_NAME" + echo "Preparing to install into ${HELM_INSTALL_DIR}" + runAsRoot cp "$HELM_TMP_BIN" "$HELM_INSTALL_DIR" +} + +# fail_trap is executed if an error occurs. +fail_trap() { + result=$? + if [ "$result" != "0" ]; then + if [[ -n "$INPUT_ARGUMENTS" ]]; then + echo "Failed to install $PROJECT_NAME with the arguments provided: $INPUT_ARGUMENTS" + help + else + echo "Failed to install $PROJECT_NAME" + fi + echo -e "\tFor support, go to https://github.com/kubernetes/helm." + fi + cleanup + exit $result +} + +# testVersion tests the installed client to make sure it is working. +testVersion() { + set +e + echo "$PROJECT_NAME installed into $HELM_INSTALL_DIR/$PROJECT_NAME" + HELM="$(which $PROJECT_NAME)" + if [ "$?" = "1" ]; then + echo "$PROJECT_NAME not found. Is $HELM_INSTALL_DIR on your "'$PATH?' + exit 1 + fi + set -e + echo "Run '$PROJECT_NAME init' to configure $PROJECT_NAME." +} + +# help provides possible cli installation arguments +help () { + echo "Accepted cli arguments are:" + echo -e "\t[--help|-h ] ->> prints this help" + echo -e "\t[--version|-v <desired_version>] . When not defined it defaults to latest" + echo -e "\te.g. --version v2.4.0 or -v latest" +} + +# cleanup temporary files to avoid https://github.com/kubernetes/helm/issues/2977 +cleanup() { + rm -rf "$HELM_TMP_ROOT" +} + +# Execution + +#Stop execution on any error +trap "fail_trap" EXIT +set -e + +# Parsing input arguments (if any) +export INPUT_ARGUMENTS="${@}" +set -u +while [[ $# -gt 0 ]]; do + case $1 in + '--version'|-v) + shift + if [[ $# -ne 0 ]]; then + export DESIRED_VERSION="${1}" + else + echo -e "Please provide the desired version. e.g. --version v2.4.0 or -v latest" + exit 0 + fi + ;; + '--help'|-h) + help + exit 0 + ;; + *) exit 1 + ;; + esac + shift +done +set +u + +initArch +initOS +verifySupported +checkDesiredVersion +if ! checkHelmInstalledVersion; then + downloadFile + installFile +fi +testVersion +cleanup diff --git a/sdc-os-chef/scripts/k8s/install_helm.sh b/sdc-os-chef/scripts/k8s/install_helm.sh new file mode 100644 index 0000000000..a3681d033a --- /dev/null +++ b/sdc-os-chef/scripts/k8s/install_helm.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +curl_status=$(curl -w '%{http_code}\n' https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get -o get_helm.sh) + +echo $curl_status + +if [ ${curl_status} != 200 ]; then + echo "[ERROR] Download get_helm failed - $curl_status" + exit -1 +fi + +chmod 700 get_helm.sh + +echo "[INFO] Running get helm" +./get_helm.sh --version v2.7.2 + +if [ $? != 0 ]; then + echo "[ERROR] failed to run get_helm" +fi + diff --git a/sdc-os-chef/scripts/k8s/install_kubectl.sh b/sdc-os-chef/scripts/k8s/install_kubectl.sh new file mode 100644 index 0000000000..8d1229b527 --- /dev/null +++ b/sdc-os-chef/scripts/k8s/install_kubectl.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +kubectl_version=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) + +echo "[INFO] kubectl version - ${kubectl_version}" + +curl_status=$(curl -w '%{http_code}\n' -LO https://storage.googleapis.com/kubernetes-release/release/${kubectl_version}/bin/linux/amd64/kubectl) + +if [ $curl_status != 200 ] ; then + echo "[ERROR] Download kubectl failed - $curl_status" + exit -1 +fi + +chmod +x ./kubectl + +sudo mv ./kubectl /usr/local/bin/kubectl + +echo "source <(kubectl completion bash)" >> ~/.bashrc + diff --git a/sdc-os-chef/scripts/k8s/install_minikube.sh b/sdc-os-chef/scripts/k8s/install_minikube.sh new file mode 100644 index 0000000000..b0f0d53cae --- /dev/null +++ b/sdc-os-chef/scripts/k8s/install_minikube.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +echo "[INFO] minikube version - v0.24.1" + +curl_status=$(curl -w '%{http_code}\n' -Lo minikube https://storage.googleapis.com/minikube/releases/v0.24.1/minikube-linux-amd64) + +if [ $curl_status != 200 ] ; then + echo "[ERROR] Download minikube failed - $curl_status" + exit -1 +fi + +chmod +x minikube + +sudo mv minikube /usr/local/bin/ + +export CHANGE_MINIKUBE_NONE_USER=true + +sudo minikube start --vm-driver=none diff --git a/sdc-os-chef/scripts/k8s/kubernetes_run.sh b/sdc-os-chef/scripts/k8s/kubernetes_run.sh new file mode 100644 index 0000000000..fd9de2e181 --- /dev/null +++ b/sdc-os-chef/scripts/k8s/kubernetes_run.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +#################### +# Functions # +#################### + +status() +{ + local rc=$1 + if [ ${rc} != 0 ]; then + echo "[ERR] Failure detected. Aborting !" + exit 255 + else + echo "[INFO] Done " + fi +} + +print_header() +{ + header=$* + echo "" + echo "-------------------------" + echo " ${header}" + echo "-------------------------" + echo "" + } + +#################### +# Main # +#################### +clear + +#################### +# kubectl # +#################### +print_header "Kubelet - Install ..." +sh ./install_kubectl.sh +status $? + + +#################### +# minikube # +#################### +print_header "Minikube - Install ..." +sh ./install_minikube.sh +status $? + + +#################### +# dependencies # +#################### +print_header "Dependency - Install ..." +echo "[INFO] Install - nsenter" +# Use pre compiled nsenter: +sudo cp bin/nsenter /usr/local/bin/nsenter +sudo cp etc/bash_completion.d/nsenter /etc/bash_completion.d/nsenter + +## In order to build the nsenter use the below instructions: +##./build_nsenter_exec.sh +echo "[INFO] Install - socat" +sudo apt-get install -y socat jq + +#################### +# helm # +#################### +print_header "Helm - Install ..." +sh ./install_helm.sh +status $? "$action" + + +#################### +# K8s # +#################### +print_header "SDC - Deploy Pods ..." +sh ./deploy_k8s_sdc.sh +status $? + |