Use IP_ALIAS_SIZE to calculate and update IP_ALIAS_SIZE. Error added when ip-alias is not enabled when IP_ALIAS_SIZE is not empty.

This commit is contained in:
yankaiz 2018-04-25 17:47:41 -07:00
parent 3989ec66eb
commit 5fb034a33f
3 changed files with 29 additions and 8 deletions

View File

@ -98,6 +98,19 @@ function get-cluster-ip-range {
echo "${suggested_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 # NOTE: Avoid giving nodes empty scopes, because kubelet needs a service account
# in order to initialize properly. # in order to initialize properly.
NODE_SCOPES="${NODE_SCOPES:-monitoring,logging-write,storage-ro}" NODE_SCOPES="${NODE_SCOPES:-monitoring,logging-write,storage-ro}"

View File

@ -289,8 +289,10 @@ ENABLE_RESCHEDULER="${KUBE_ENABLE_RESCHEDULER:-true}"
ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false} ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false}
NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator} NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator}
if [ ${ENABLE_IP_ALIASES} = true ]; then if [ ${ENABLE_IP_ALIASES} = true ]; then
# Size of ranges allocated to each node. Currently supports only /32 and /24. # Number of Pods that can run on this node.
IP_ALIAS_SIZE=${KUBE_GCE_IP_ALIAS_SIZE:-/24} 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} 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. # 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. # 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:-} ENABLE_IP_ALIASES"
PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE" PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE"
PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME" PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME"
# Number of Pods that can run on this node. elif [[ -n "${MAX_PODS_PER_NODE:-}" ]]; then
MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110} # 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 fi
# Enable GCE Alpha features. # Enable GCE Alpha features.

View File

@ -296,8 +296,10 @@ ENABLE_RESCHEDULER="${KUBE_ENABLE_RESCHEDULER:-true}"
ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false} ENABLE_IP_ALIASES=${KUBE_GCE_ENABLE_IP_ALIASES:-false}
NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator} NODE_IPAM_MODE=${KUBE_GCE_NODE_IPAM_MODE:-RangeAllocator}
if [ ${ENABLE_IP_ALIASES} = true ]; then if [ ${ENABLE_IP_ALIASES} = true ]; then
# Size of ranges allocated to each node. gcloud current supports only /32 and /24. # Number of Pods that can run on this node.
IP_ALIAS_SIZE=${KUBE_GCE_IP_ALIAS_SIZE:-/24} 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} 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. # 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. # 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:-} ENABLE_IP_ALIASES"
PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE" PROVIDER_VARS="${PROVIDER_VARS:-} NODE_IPAM_MODE"
PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME" PROVIDER_VARS="${PROVIDER_VARS:-} SECONDARY_RANGE_NAME"
# Number of Pods that can run on this node. elif [[ -n "${MAX_PODS_PER_NODE:-}" ]]; then
MAX_PODS_PER_NODE=${MAX_PODS_PER_NODE:-110} # 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 fi
# Enable GCE Alpha features. # Enable GCE Alpha features.