From 3808519907b23cd1d67c3afa220c0c6774f048be Mon Sep 17 00:00:00 2001 From: Jerzy Szczepkowski Date: Wed, 8 Jul 2015 16:48:33 +0200 Subject: [PATCH] Optional creation of nodes autoscaler for GCE. Implemented optional creation and deletion of nodes autoscaler in kube-up and kube-down scripts for GCE. --- cluster/gce/config-default.sh | 9 +++++++++ cluster/gce/config-test.sh | 9 +++++++++ cluster/gce/util.sh | 21 +++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/cluster/gce/config-default.sh b/cluster/gce/config-default.sh index c6f31c93a5..98e9aee6e8 100755 --- a/cluster/gce/config-default.sh +++ b/cluster/gce/config-default.sh @@ -74,6 +74,15 @@ DNS_SERVER_IP="10.0.0.10" DNS_DOMAIN="cluster.local" DNS_REPLICAS=1 +# Optional: Create autoscaler for cluster's nodes. +# NOT WORKING YET! +ENABLE_NODE_AUTOSCALER="${KUBE_ENABLE_NODE_AUTOSCALER:-false}" +if [[ "${ENABLE_NODE_AUTOSCALER}" == "true" ]]; then + AUTOSCALER_MIN_NODES="${KUBE_AUTOSCALER_MIN_NODES:-1}" + AUTOSCALER_MAX_NODES="${KUBE_AUTOSCALER_MAX_NODES:-${NUM_MINIONS}}" + TARGET_NODE_UTILIZATION="${KUBE_TARGET_NODE_UTILIZATION:-0.7}" +fi + # Admission Controllers to invoke prior to persisting objects in cluster ADMISSION_CONTROL=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota diff --git a/cluster/gce/config-test.sh b/cluster/gce/config-test.sh index fae9b7fa63..04d96cadc5 100755 --- a/cluster/gce/config-test.sh +++ b/cluster/gce/config-test.sh @@ -72,6 +72,15 @@ DNS_SERVER_IP="10.0.0.10" DNS_DOMAIN="cluster.local" DNS_REPLICAS=1 +# Optional: Create autoscaler for cluster's nodes. +# NOT WORKING YET! +ENABLE_NODE_AUTOSCALER="${KUBE_ENABLE_NODE_AUTOSCALER:-false}" +if [[ "${ENABLE_NODE_AUTOSCALER}" == "true" ]]; then + AUTOSCALER_MIN_NODES="${KUBE_AUTOSCALER_MIN_NODES:-1}" + AUTOSCALER_MAX_NODES="${KUBE_AUTOSCALER_MAX_NODES:-${NUM_MINIONS}}" + TARGET_NODE_UTILIZATION="${KUBE_TARGET_NODE_UTILIZATION:-0.7}" +fi + ADMISSION_CONTROL=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota # Optional: if set to true kube-up will automatically check for existing resources and clean them up. diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index af355ca3d8..5570497b1b 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -708,6 +708,18 @@ function kube-up { detect-minion-names detect-master + # Create autoscaler for nodes if requested + if [[ "${ENABLE_NODE_AUTOSCALER}" == "true" ]]; then + METRICS="" + METRICS+="--custom-metric-utilization metric=custom.cloudmonitoring.googleapis.com/kubernetes.io/cpu/node_utilization," + METRICS+="utilization-target=${TARGET_NODE_UTILIZATION},utilization-target-type=GAUGE " + METRICS+="--custom-metric-utilization metric=custom.cloudmonitoring.googleapis.com/kubernetes.io/memory/node_utilization," + METRICS+="utilization-target=${TARGET_NODE_UTILIZATION},utilization-target-type=GAUGE " + echo "Creating node autoscaler." + gcloud preview autoscaler --zone "${ZONE}" create "${NODE_INSTANCE_PREFIX}-autoscaler" --target "${NODE_INSTANCE_PREFIX}-group" \ + --min-num-replicas "${AUTOSCALER_MIN_NODES}" --max-num-replicas "${AUTOSCALER_MAX_NODES}" ${METRICS} || true + fi + echo "Waiting for cluster initialization." echo echo " This will continually check to see if the API for kubernetes is reachable." @@ -769,6 +781,15 @@ function kube-down { echo "Bringing down cluster" set +e # Do not stop on error + # Delete autoscaler for nodes if present. + local autoscaler + autoscaler=( $(gcloud preview autoscaler --zone "${ZONE}" list \ + | awk 'NR >= 2 { print $1 }' \ + | grep "${NODE_INSTANCE_PREFIX}-autoscaler") ) + if [[ "${autoscaler:-}" != "" ]]; then + gcloud preview autoscaler --zone "${ZONE}" delete "${NODE_INSTANCE_PREFIX}-autoscaler" + fi + # Get the name of the managed instance group template before we delete the # managed instange group. (The name of the managed instnace group template may # change during a cluster upgrade.)