@@ -40,6 +40,7 @@ function create-kubemark-master {
4040 export KUBE_TEMP=" ${KUBE_TEMP} "
4141
4242 export KUBECONFIG=" ${RESOURCE_DIRECTORY} /kubeconfig.kubemark"
43+ export KUBECONFIG_INTERNAL=" ${RESOURCE_DIRECTORY} /kubeconfig-internal.kubemark"
4344 export CLUSTER_NAME=" ${CLUSTER_NAME} -kubemark"
4445 export KUBE_CREATE_NODES=false
4546 export KUBE_GCE_INSTANCE_PREFIX=" ${KUBE_GCE_INSTANCE_PREFIX} -kubemark"
@@ -80,6 +81,33 @@ function create-kubemark-master {
8081 " ${KUBE_ROOT} /hack/e2e-internal/e2e-grow-cluster.sh"
8182 done
8283 fi
84+
85+ # The e2e-up.sh script is not sourced, so we don't have access to variables that
86+ # it sets. Instead, we read data which was written to the KUBE_TEMP directory.
87+ # The cluster-location is either ZONE (say us-east1-a) or REGION (say us-east1).
88+ # To get REGION from location, only first two parts are matched.
89+ REGION=$( grep -o " ^[a-z]*-[a-z0-9]*" " ${KUBE_TEMP} " /cluster-location.txt)
90+ MASTER_NAME=" ${KUBE_GCE_INSTANCE_PREFIX} " -master
91+
92+ MASTER_INTERNAL_IP=$( gcloud compute addresses describe " ${MASTER_NAME} -internal-ip" \
93+ --project " ${PROJECT} " --region " ${REGION} " -q --format=' value(address)' )
94+ MASTER_IP=$( gcloud compute addresses describe " ${MASTER_NAME} -ip" \
95+ --project " ${PROJECT} " --region " ${REGION} " -q --format=' value(address)' )
96+
97+ # If cluster uses private master IP, two kubeconfigs are created:
98+ # - kubeconfig with public IP, which will be used to connect to the cluster
99+ # from outside of the cluster network
100+ # - kubeconfig with private IP (called internal kubeconfig), which will be
101+ # used to create hollow nodes.
102+ #
103+ # Note that hollow nodes might use either of these kubeconfigs, but
104+ # using internal one is better from performance and cost perspective, since
105+ # traffic does not need to go through Cloud NAT.
106+ if [[ -n " ${MASTER_INTERNAL_IP:- } " ]]; then
107+ echo " Writing internal kubeconfig to '${KUBECONFIG_INTERNAL} '"
108+ ip_regexp=${MASTER_IP// ./ \\ .} # escape ".", so that sed won't treat it as "any char"
109+ sed " s/${ip_regexp} /${MASTER_INTERNAL_IP} /g" " ${KUBECONFIG} " > " ${KUBECONFIG_INTERNAL} "
110+ fi
83111 )
84112}
85113
0 commit comments