#!/usr/bin/env bash set -o errexit set -o pipefail set -o nounset CUR_DIR=$(pwd) SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" function print_usage_exit() { exit_code=${1:-0} cat </dev/null 2>&1) || $? -ne 0 ]]; do echo "Waiting for Rook CRDs" sleep 2 done kubectl apply -f ${ROOK_URL}/001-cluster.yaml kubectl apply -f ${ROOK_URL}/002-storageclass.yaml } function monitoring() { #Just to allow the CRD to be created. Ideally wait and then run second time kubectl apply -f 4-kube-prometheus/ while [[ $(kubectl get crd alertmanagers.monitoring.coreos.com prometheuses.monitoring.coreos.com prometheusrules.monitoring.coreos.com servicemonitors.monitoring.coreos.com >/dev/null 2>&1) || $? -ne 0 ]]; do echo "Waiting for Prometheus CRDs" sleep 2 done kubectl apply -f 4-kube-prometheus/ #Expose the dashboards #kubectl --namespace monitoring port-forward svc/prometheus-k8s 9090 & #kubectl --namespace monitoring port-forward svc/grafana 3000 & #kubectl --namespace monitoring port-forward svc/alertmanager-main 9093 & } function miscellaneous() { kubectl apply -f 2-dashboard/ kubectl apply -f 3-efk/ #Create an ingress load balancer kubectl apply -f 5-ingres-lb/ #Create a bare metal load balancer. #kubectl apply -f 6-metal-lb/metallb.yaml #The config map should be properly modified to pick a range that can live #on this subnet behind the same gateway (i.e. same L2 domain) #kubectl apply -f 6-metal-lb/example-layer2-config.yaml } function minimal() { cluster_init cni kata metrics } function all() { minimal storage monitoring miscellaneous } declare -A command_handlers command_handlers[init]=cluster_init command_handlers[cni]=cni command_handlers[minimal]=minimal command_handlers[all]=all command_handlers[help]=print_usage_exit declare -A command_help command_help[init]="Only inits a cluster using kubeadm" command_help[cni]="Setup network for running cluster" command_help[minimal]="init + cni + kata + metrics" command_help[all]="minimal + storage + monitoring + miscellaneous" command_help[help]="show this message" cd "${SCRIPT_DIR}" cmd_handler=${command_handlers[${1:-none}]:-unimplemented} if [ "${cmd_handler}" != "unimplemented" ]; then "${cmd_handler}" else print_usage_exit 1 fi