Skip to content

Commit f9c4551

Browse files
author
Jakub Pierewoj
committed
Use private master IP in GCE kubemark tests
Currently hollow nodes communicate with kubemark master using public master IP, which results in each call going through cloud NAT. Cloud NAT limitations become performance bottleneck (see kubernetes/perf-tests/issues/874). To mitigate this, in this change, a second kubeconfig called "internal" is created. It uses private master IP and is used to set up hollow nodes. Note that we still need the original kubemark kubeconfig (using public master IP) to be able to communicate with the master from outside the cluster (when setting it up or running tests). Testing: - set up kubemark cluster, verified apiserver logs to confirm that the call from hollow nodes did not go through NAT
1 parent 0273d43 commit f9c4551

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

test/kubemark/gce/util.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/kubemark/skeleton/util.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function authenticate-docker {
2626

2727
# This function should create kubemark master and write kubeconfig to
2828
# "${RESOURCE_DIRECTORY}/kubeconfig.kubemark".
29+
# If a cluster uses private master IP, create-kubemark-master might also write
30+
# a second kubeconfig to "${RESOURCE_DIRECTORY}/kubeconfig-internal.kubemark".
31+
# The difference between these two kubeconfigs is that the internal one uses
32+
# private master IP, which might be better suited for setting up hollow nodes.
2933
function create-kubemark-master {
3034
echo "Creating cluster..."
3135
}

test/kubemark/start-kubemark.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ KUBECTL="${KUBE_ROOT}/cluster/kubectl.sh"
3838
KUBEMARK_DIRECTORY="${KUBE_ROOT}/test/kubemark"
3939
RESOURCE_DIRECTORY="${KUBEMARK_DIRECTORY}/resources"
4040
LOCAL_KUBECONFIG="${RESOURCE_DIRECTORY}/kubeconfig.kubemark"
41+
INTERNAL_KUBECONFIG="${RESOURCE_DIRECTORY}/kubeconfig-internal.kubemark"
4142

4243
# Generate a random 6-digit alphanumeric tag for the kubemark image.
4344
# Used to uniquify image builds across different invocations of this script.
@@ -96,12 +97,12 @@ function create-kube-hollow-node-resources {
9697
# It's bad that all component shares the same kubeconfig.
9798
# TODO(https://github.com/kubernetes/kubernetes/issues/79883): Migrate all components to separate credentials.
9899
"${KUBECTL}" create secret generic "kubeconfig" --type=Opaque --namespace="kubemark" \
99-
--from-file=kubelet.kubeconfig="${LOCAL_KUBECONFIG}" \
100-
--from-file=kubeproxy.kubeconfig="${LOCAL_KUBECONFIG}" \
101-
--from-file=npd.kubeconfig="${LOCAL_KUBECONFIG}" \
102-
--from-file=heapster.kubeconfig="${LOCAL_KUBECONFIG}" \
103-
--from-file=cluster_autoscaler.kubeconfig="${LOCAL_KUBECONFIG}" \
104-
--from-file=dns.kubeconfig="${LOCAL_KUBECONFIG}"
100+
--from-file=kubelet.kubeconfig="${HOLLOWNODE_KUBECONFIG}" \
101+
--from-file=kubeproxy.kubeconfig="${HOLLOWNODE_KUBECONFIG}" \
102+
--from-file=npd.kubeconfig="${HOLLOWNODE_KUBECONFIG}" \
103+
--from-file=heapster.kubeconfig="${HOLLOWNODE_KUBECONFIG}" \
104+
--from-file=cluster_autoscaler.kubeconfig="${HOLLOWNODE_KUBECONFIG}" \
105+
--from-file=dns.kubeconfig="${HOLLOWNODE_KUBECONFIG}"
105106

106107
# Create addon pods.
107108
# Heapster.
@@ -227,7 +228,13 @@ function start-hollow-nodes {
227228
detect-project &> /dev/null
228229
create-kubemark-master
229230

230-
MASTER_IP=$(grep server "$LOCAL_KUBECONFIG" | awk -F "/" '{print $3}')
231+
if [ -f "${INTERNAL_KUBECONFIG}" ]; then
232+
HOLLOWNODE_KUBECONFIG="${INTERNAL_KUBECONFIG}"
233+
else
234+
HOLLOWNODE_KUBECONFIG="${LOCAL_KUBECONFIG}"
235+
fi
236+
237+
MASTER_IP=$(grep server "${HOLLOWNODE_KUBECONFIG}" | awk -F "/" '{print $3}')
231238

232239
start-hollow-nodes
233240

0 commit comments

Comments
 (0)