diff --git a/cluster/gce/config-common.sh b/cluster/gce/config-common.sh index 628ad582719..112c63a637c 100644 --- a/cluster/gce/config-common.sh +++ b/cluster/gce/config-common.sh @@ -98,6 +98,19 @@ function get-cluster-ip-range { echo "${suggested_range}" } +# Calculate ip alias range based on max number of pods. +# Let pow be the smallest integer which is bigger than log2($1 * 2). +# (32 - pow) will be returned. +# +# $1: The number of max pods limitation. +function get-alias-range-size() { + for pow in {0..31}; do + if (( 1 << $pow > $1 * 2 )); then + echo $((32 - pow)) + return 0 + fi + done +} # NOTE: Avoid giving nodes empty scopes, because kubelet needs a service account # in order to initialize properly. NODE_SCOPES="${NODE_SCOPES:-monitoring,logging-write,storage-ro}" diff --git a/cluster/gce/config-default.sh b/cluster/gce/config-default.sh index 69516c1857e..eb2bd973d7b 100755 --- a/cluster/gce/config-default.sh +++ b/cluster/gce/config-default.sh @@ -289,8 +289,10 @@ ENABLE_RESCHEDULER="${KUBE_ENABLE_RESCHEDULER:-true}" ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false} NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator} if [ ${ENABLE_IP_ALIASES} = true ]; then - # Size of ranges allocated to each node. Currently supports only /32 and /24. - IP_ALIAS_SIZE=${KUBE_GCE_IP_ALIAS_SIZE:-/24} + # Number of Pods that can run on this node. + MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110} + # Size of ranges allocated to each node. + IP_ALIAS_SIZE="/$(get-alias-range-size ${MAX_PODS_PER_NODE})" IP_ALIAS_SUBNETWORK=${KUBE_GCE_IP_ALIAS_SUBNETWORK:-${INSTANCE_PREFIX}-subnet-default} # If we're using custom network, use the subnet we already create for it as the one for ip-alias. # Note that this means SUBNETWORK would override KUBE_GCE_IP_ALIAS_SUBNETWORK in case of custom network. @@ -305,8 +307,10 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_IP_ALIASES" PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE" PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME" - # Number of Pods that can run on this node. - MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110} +elif [[ -n "${MAX_PODS_PER_NODE:-}" ]]; then + # Should not have MAX_PODS_PER_NODE set for route-based clusters. + echo -e "${color_red}Cannot set MAX_PODS_PER_NODE for route-based projects for ${PROJECT}." >&2 + exit 1 fi # Enable GCE Alpha features. diff --git a/cluster/gce/config-test.sh b/cluster/gce/config-test.sh index d11512ac32b..b800e855f82 100755 --- a/cluster/gce/config-test.sh +++ b/cluster/gce/config-test.sh @@ -296,8 +296,10 @@ ENABLE_RESCHEDULER="${KUBE_ENABLE_RESCHEDULER:-true}" ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false} NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator} if [ ${ENABLE_IP_ALIASES} = true ]; then - # Size of ranges allocated to each node. gcloud current supports only /32 and /24. - IP_ALIAS_SIZE=${KUBE_GCE_IP_ALIAS_SIZE:-/24} + # Number of Pods that can run on this node. + MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110} + # Size of ranges allocated to each node. + IP_ALIAS_SIZE="/$(get-alias-range-size ${MAX_PODS_PER_NODE})" IP_ALIAS_SUBNETWORK=${KUBE_GCE_IP_ALIAS_SUBNETWORK:-${INSTANCE_PREFIX}-subnet-default} # If we're using custom network, use the subnet we already create for it as the one for ip-alias. # Note that this means SUBNETWORK would override KUBE_GCE_IP_ALIAS_SUBNETWORK in case of custom network. @@ -312,8 +314,10 @@ if [ ${ENABLE_IP_ALIASES} = true ]; then PROVIDER_VARS="${PROVIDER_VARS:-} ENABLE_IP_ALIASES" PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE" PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME" - # Number of Pods that can run on this node. - MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110} +elif [[ -n "${MAX_PODS_PER_NODE:-}" ]]; then + # Should not have MAX_PODS_PER_NODE set for route-based clusters. + echo -e "${color_red}Cannot set MAX_PODS_PER_NODE for route-based projects for ${PROJECT}." >&2 + exit 1 fi # Enable GCE Alpha features.