diff --git a/kubernetes/pipeline/00setup b/kubernetes/pipeline/00setup index 4952e031..15210ce3 100644 --- a/kubernetes/pipeline/00setup +++ b/kubernetes/pipeline/00setup @@ -14,6 +14,7 @@ export -a MOD_PASSTHROUGH_OPTS=() export -A MOD_MSGS=() # Use order 0 to ensure this is first displayed MOD_MSGS[0_common.0]="run ./configure to initialise your deployment" +MOD_MSGS[0_common.1]="run ./tools/bootstrap-k8s-cloud.sh to deploy k8s bundles" # Array list of overlays to use with this deployment. export -a MOD_OVERLAYS=() diff --git a/microk8s/pipeline/00setup b/microk8s/pipeline/00setup index b2fe9748..14dc30e4 100644 --- a/microk8s/pipeline/00setup +++ b/microk8s/pipeline/00setup @@ -14,6 +14,7 @@ export -a MOD_PASSTHROUGH_OPTS=() export -A MOD_MSGS=() # Use order 0 to ensure this is first displayed MOD_MSGS[0_common.0]="run ./configure to initialise your deployment" +MOD_MSGS[0_common.1]="run ./tools/bootstrap-k8s-cloud.sh to deploy k8s bundles" # Array list of overlays to use with this deployment. export -a MOD_OVERLAYS=() diff --git a/tools/bootstrap-k8s-cloud.sh b/tools/bootstrap-k8s-cloud.sh new file mode 100755 index 00000000..ebda052a --- /dev/null +++ b/tools/bootstrap-k8s-cloud.sh @@ -0,0 +1,45 @@ +#!/bin/bash -x +# Usage: ./tools/bootstrap-k8s-cloud.sh +CLOUD="${1:-k8scloud}" +MODEL="${2:-secloud}" +CONTROLLER="${3:-k8slord}" + +check_kubeconfig() { + if [[ -z "$KUBECONFIG" && ! -f "${HOME}/.kube/config" ]]; then + echo 'ERROR: Cannot find KUBECONFIG! Set as environment variable.' + exit 1 + fi +} + +get_storageclass() { + default_storageclass="$(kubectl get sc | grep default | awk '{print $1}')" + if [[ -z "$default_storageclass" ]]; then + enable_storage + fi +} + +enable_storage() { + if leader="$(juju status --format json| jq -r '.applications["microk8s"].units|to_entries[]|select(.value["leader"])|.key' 2> /dev/null)"; then + echo 'Enabling hostpath-storage and MetalLB on Microk8s.' + juju ssh "$leader" sudo microk8s enable hostpath-storage + iprange="$(for i in `kubectl get nodes -o json | jq -r '.items[].status.addresses[] | select(.type=="InternalIP") | .address'`; do iprange+="$i-${i},"; done; echo $iprange | sed -e 's/,$//')" + juju ssh "$leader" sudo microk8s enable metallb:"$iprange" + elif leader="$(juju status --format json| jq -r '.applications["k8s"].units|to_entries[]|select(.value["leader"])|.key' 2> /dev/null)"; then + echo 'Enabling local-storage and load-balancer on Canonical K8s.' + juju ssh "$leader" sudo k8s enable local-storage + juju ssh "$leader" sudo k8s enable load-balancer + else + echo 'ERROR: No default storage class in Kubernetes. Try deploying a k8s bundle with --ceph.' + exit 1 + fi +} + +bootstrap_k8s() { + juju add-k8s "$CLOUD" --client + juju bootstrap "$CLOUD" "$CONTROLLER" + juju add-model "$MODEL" +} + +check_kubeconfig +get_storageclass +bootstrap_k8s