diff --git a/sh/deploy-storageos-cluster.sh b/sh/deploy-storageos-cluster.sh index be9dd5fc4..0b1b61e79 100755 --- a/sh/deploy-storageos-cluster.sh +++ b/sh/deploy-storageos-cluster.sh @@ -1,4 +1,11 @@ #!/bin/bash +############################################################################# +# Script Name : deploy-storageos-cluster.sh +# Description : Install StorageOS Self-Evaluation Cluster +# Args : +# Author : StorageOS +# Issues : Issues&PR https://github.com/storageos/storageos.github.io +############################################################################# set -euo pipefail @@ -17,42 +24,181 @@ set -euo pipefail # The following variables may be tuned as desired. The defaults should work in # most environments. -export OPERATOR_VERSION='v2.4.0-rc.1' -export CLI_VERSION='v2.4.0-rc.1' -export STOS_VERSION='v2.4.0-rc.1' -export STORAGEOS_OPERATOR_LABEL='name=storageos-cluster-operator' -export STOS_NAMESPACE='kube-system' -export ETCD_NAMESPACE='storageos-etcd' -export STOS_CLUSTERNAME='self-evaluation' + +# Getting the latest and greatest to deploy as a self-evaluation. +# Failing back to a manual entry if cURL not present (I know!). +if ! command -v curl &> /dev/null +then + OPERATOR_VERSION='v2.4.0-rc.1' +else + OPERATOR_VERSION=`curl --silent "https://api.github.com/repos/storageos/cluster-operator/releases/latest" |awk -F '"' '/tag_name/{print $4}'` +fi +STORAGEOS_OPERATOR_LABEL='name=storageos-cluster-operator' +STOS_NAMESPACE='kube-system' +ETCD_NAMESPACE='storageos-etcd' +STOS_CLUSTERNAME='self-evaluation' + +while getopts c:v:l: option +do + case "${option}" in + c) STOS_CLUSTERNAME=${OPTARG};; + v) OPERATOR_VERSION=${OPTARG};; + l) + esac +done +CLI_VERSION=${OPERATOR_VERSION} +STOS_VERSION=${OPERATOR_VERSION} + # Define some colours for later RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color +# spin the wheel to avoid nervous breakdown during waiting time +sp="/-\|" +spin() { + printf '\b%.1s' "$sp" + sp=${sp#?}${sp%???} +} +endspin() { + echo -ne '\b \b' +} + +# Welcoming STORAGEOS users :) +echo +echo -e "${RED}Welcome to the ${NC}STORAGE${GREEN}OS${RED} self-evaluation installation script.${NC}" +echo -e "${GREEN}Self-Evaluation guide: https://docs.storageos.com/docs/self-eval${NC}" +echo -e " ${RED}This deployment is suitable for testing purposes only.${NC}" +echo + +# Checking and exiting if requirements are not met. +echo -e "${GREEN}Checking requirements:${NC}" + +# Checking if kubectl is present! +echo -ne " Checking Kubectl......................................" +if ! command -v kubectl &> /dev/null +then + echo -ne "${RED}NOK${NC}\n" + echo -e "${RED} Kubectl could not be found on this shell.${NC}" + echo -e "${RED} Kubectl is used to access Kubernetes clusters and is required.${NC}" + echo -e "${RED} Please intall kubectl: https://kubernetes.io/docs/tasks/tools/${NC}" + exit +fi +echo -ne ".${GREEN}OK${NC}\n" + +# Checking for the minimum node count (3) +echo -ne " Checking node count (minimum 3)......................." +NODECOUNT=`kubectl get nodes -o name | wc -l` +if [ ${NODECOUNT} -lt 3 ] +then + echo -ne "${RED}NOK${NC}\n" + exit +fi +echo -ne ".${GREEN}OK${NC} (${RED}${NODECOUNT}${NC})\n" + +# Checking for an existing STORAGEOS cluster on the kubernetes target +echo -ne " Checking for exiting STORAGE${GREEN}OS${NC} cluster................" +if kubectl get storageoscluster --all-namespaces -o name &>/dev/null; +then + echo -ne "${RED}YES${NC}\n" + echo -e " ${RED}/!\ ${NC}STORAGE${GREEN}OS ${NC}cluster${RED} already deployed on this Kubernetes cluster." + echo + exit + # todo: include a clean-up option from this breaking point +else + echo -ne ".${GREEN}NO${NC}\n" +fi + +# Summary of what is on the menu for deployment today +echo +echo -e "${GREEN}The script will deploy a ${NC}STORAGE${GREEN}OS cluster: ${NC}" +echo -e " STORAGE${GREEN}OS${NC} cluster named ${RED}${STOS_CLUSTERNAME}${GREEN}.${NC}" +echo -e " STORAGE${GREEN}OS${NC} version ${RED}${STOS_VERSION}${NC} into namespace ${RED}${STOS_NAMESPACE}${GREEN}.${NC}" + +# RC? Let's have a bit of a warning there +if [[ ${STOS_VERSION} =~ .*rc.* ]]; +then + echo -e " ${RED}/!\ ${STOS_VERSION}${NC}: Release Candidate are not intended for production deployment.${NC}" +fi +# not deploying in kube-system - brace yourself! +if [[ ! "${STOS_NAMESPACE}" == "kube-system" ]]; +then + echo -e " ${RED}/!\ ${NC}only ${RED}kube-system${NC} namespace namespace for ease of self-evualation.${NC}" + exit +fi + +echo -e " etcd into namespace ${RED}${ETCD_NAMESPACE}${GREEN}.${NC}" +# not deploying in storageos-etcd - brace yourself! +if [[ ! "${ETCD_NAMESPACE}" == "storageos-etcd" ]]; +then + echo -e " ${RED}/!\ ${NC}only ${RED}storageos-etcd${NC} namespace for ease of self-evualation.${NC}" + exit +fi +echo -e "${GREEN}The installation process will stop on any encountered error.${NC}" +echo + +# Having the courtesy to check if happy with the basics settings +read < /dev/tty -n1 -r -p "Proceed with these settings? (y/n) " + +echo +if [[ ! $REPLY =~ ^[Yy]$ ]] +then + echo + echo -e "Usage: ./deploy-storageos-cluster.sh [OPTION]..." + echo -e "${RED}Install a ${NC}STORAGE${GREEN}OS${RED} Self-Evaluation cluster on Kubernetes.${NC}" + echo + echo -e " -c ${NC}STORAGE${GREEN}OS${NC} cluser name." + echo -e " -v ${NC}STORAGE${GREEN}OS${NC} version to deploy." + echo -e " Check https://github.com/storageos/cluster-operator/releases" + echo + echo "Eg: ./deploy-storageos-cluster.sh -c demo-cluster -v ${STOS_VERSION}" + echo " curl -fsSL https://storageos.run | bash -s -- -c demo-cluster -v ${STOS_VERSION}" + echo + echo "Issues: https://github.com/storageos/storageos.github.io" + echo + exit +fi + +# Starting deployment +echo -e "${GREEN}Starting ${NC}STORAGE${GREEN}OS deployment:${NC}" +echo -ne " Is it OpenShift?......................................" # If running in Openshift, an SCC is needed to start Pods -if grep -q "openshift" <(kubectl get node --show-labels); then +if grep -q "openshift" <(kubectl get node --show-labels); +then + echo -ne "${GREEN}YES${NC}\n" + + # Checking if OCP CLI is present! + echo -ne " Checking OCP CLI......................................" + if ! command -v oc &> /dev/null + then + echo -ne "${RED}NOK${NC}\n" + echo -e "${RED} OCP CLI (oc) could not be found on this shell.${NC}" + echo -e "${RED} Please intall OCP CLI: https://docs.openshift.com/container-platform/4.7/cli_reference/openshift_cli/getting-started-cli.html/${NC}" + exit + fi + echo -ne ".${GREEN}OK${NC}\n" + + echo -ne " OpenShift - adding SCC for ${RED}${ETCD_NAMESPACE}${GREEN}${NC} ............" oc adm policy add-scc-to-user anyuid \ system:serviceaccount:${ETCD_NAMESPACE}:default sleep 5 + echo -ne "${GREEN}OK${NC}\n" fi - -echo -e "${GREEN}Welcome to the StorageOS quick installation script.${NC}" -echo -e "${GREEN}I will install StorageOS version ${STOS_VERSION} into${NC}" -echo -e "${GREEN}namespace ${STOS_NAMESPACE} now. If I encounter any errors${NC}" -echo -e "${GREEN}I will stop immediately.${NC}" -echo +echo -ne ".${GREEN}NO${NC}\n" # First, we create an etcd cluster. Our example uses the CoreOS operator to # create a 3 pod cluster using transient storage. This is *unsuitable for # production deployments* but fine for evaluation purposes. The data in the # etcd will not persist outside of a reboot. -echo -e "${GREEN}Creating etcd namespace ${ETCD_NAMESPACE}${NC}" -kubectl create namespace ${ETCD_NAMESPACE} -echo -e "${GREEN}Creating etcd ClusterRole and ClusterRoleBinding${NC}" -kubectl -n ${ETCD_NAMESPACE} create -f-< /dev/null +echo -ne "${GREEN}OK${NC} (${RED}${ETCD_NAMESPACE}${NC})\n" + +echo -ne " Creating etcd ClusterRoleBinding......................" +kubectl -n ${ETCD_NAMESPACE} create -f- 1>/dev/null</dev/null</dev/null</dev/null`; +do + spin done +endspin +echo -ne ".${GREEN}OK${NC}\n" + # Create etcd CustomResource # This will install 3 etcd pods into the cluster using ephemeral storage. It # will also create a service endpoint, by which we can refer to the cluster in # the installation for StorageOS itself below. -echo -e "${GREEN}Creating etcd cluster in namespace ${ETCD_NAMESPACE}${NC}" -kubectl -n ${ETCD_NAMESPACE} create -f- </dev/null</dev/null + +echo -ne ".${GREEN}OK${NC} (${RED}${OPERATOR_VERSION}${NC})\n" + # Wait for the operator to become ready -echo -e "${GREEN}Operator installed, waiting for pod to become ready${NC}" -phase="$(kubectl -n storageos-operator get pod -l${STORAGEOS_OPERATOR_LABEL} --no-headers -ocustom-columns=status:.status.phase)" -while ! grep -q "Running" <(echo "${phase}"); do - sleep 2 - phase="$(kubectl -n storageos-operator get pod -l${STORAGEOS_OPERATOR_LABEL} --no-headers -ocustom-columns=status:.status.phase)" +echo -ne " Waiting on STORAGE${GREEN}OS${NC} operator to be running.........." +# phase="$(kubectl -n storageos-operator get pod -l${STORAGEOS_OPERATOR_LABEL} --no-headers -ocustom-columns=status:.status.phase)" +# while ! grep -q "Running" <(echo "${phase}"); do +# sleep 2 +# phase="$(kubectl -n storageos-operator get pod -l${STORAGEOS_OPERATOR_LABEL} --no-headers -ocustom-columns=status:.status.phase)" +# done +# echo -ne ".${GREEN}OK${NC}\n" + +until phase=`kubectl -n storageos-operator get pod -l${STORAGEOS_OPERATOR_LABEL} --no-headers -ocustom-columns=status:.status.phase |grep -q "Running" 1>/dev/null`; +do + spin done +endspin +echo -ne ".${GREEN}OK${NC}\n" + -echo -e "${GREEN}StorageOS Operator installed successfully${NC}" # The StorageOS secret contains credentials for our API, as well as CSI -echo -e "${GREEN}Creating Secret definining the API Username and Password${NC}" -kubectl create -f - </dev/null</dev/null + echo -ne ".${GREEN}OK${NC} (${RED}${STOS_NAMESPACE}${NC})\n" +fi + # In the StorageOS CR we declare the DNS name for the etcd deployment and # service we created earlier. -echo -e "${GREEN}Installing StorageOS Cluster version ${STOS_VERSION}${NC}" -kubectl create -f - </dev/null</dev/null`; +do + spin done +endspin +echo -ne ".${GREEN}OK${NC}\n" -echo -e "${GREEN}StorageOS Cluster installed successfully${NC}" # Now that we have a working StorageOS cluster, we can deploy a pod to run the # cli inside the cluster. When we want to access the cli, we can kubectl exec # into this pod. -echo "Deploying the StorageOS CLI as a pod in the kube-system namespace" -# Deploy the StorageOS CLI as a container -kubectl -n kube-system run \ ---image storageos/cli:${CLI_VERSION} \ ---restart=Never \ ---env STORAGEOS_ENDPOINTS=storageos:5705 \ ---env STORAGEOS_USERNAME=storageos \ ---env STORAGEOS_PASSWORD=storageos \ ---command cli \ --- /bin/sh -c "while true; do sleep 999999; done" +echo -ne " Deploying STORAGE${GREEN}OS${NC} CLI as a pod......................" +kubectl create -f- 1>/dev/null</dev/null`; +do + spin +done +endspin +echo -ne ".${GREEN}OK${NC}\n" -echo -e "${GREEN}Your StorageOS Cluster now is up and running!${NC}" +echo +echo -e "${GREEN}Your ${NC}STORAGE${GREEN}OS${NC} Cluster ${GREEN}now is up and running!" echo echo -e "${GREEN}Now would be a good time to deploy your first volume - see${NC}" -echo -e "${GREEN}https://docs.storageos.com/docs/self-eval/#a-namestorageosvolumeaprovision-a-storageos-volume${NC}" +echo -e "${GREEN} https://docs.storageos.com/docs/self-eval/#a-namestorageosvolumeaprovision-a-storageos-volume${NC}" echo -e "${GREEN}for an example of how to mount a StorageOS volume in a pod${NC}" echo -echo -e "${GREEN}Don't forget to license your cluster - see https://docs.storageos.com/docs/operations/licensing/${NC}" +echo -e "${GREEN}Get your Free Forever Developer license - see${NC}" +echo -e "${GREEN} https://docs.storageos.com/docs/operations/licensing/${NC}" +echo -e "${RED}A cluster can run unlicensed for 24 hours. Normal functioning of the cluster" +echo -e "${RED}can be unlocked by applying for a Free Forever Developer licence.${NC}" echo echo -e "${GREEN}This cluster has been set up with an etcd based on ephemeral${NC}" echo -e "${GREEN}storage. It is suitable for evaluation purposes only - for${NC}" echo -e "${GREEN}production usage please see our etcd installation nodes at${NC}" -echo -e "${GREEN}https://docs.storageos.com/docs/prerequisites/etcd/${NC}" - +echo -e "${GREEN} https://docs.storageos.com/docs/prerequisites/etcd/${NC}" +echo