From 49afcfa5f2062ebc8cb03c5f57df751a6b8468e2 Mon Sep 17 00:00:00 2001 From: Ben Hu Date: Wed, 30 Sep 2020 23:06:37 +0000 Subject: [PATCH] Use host IP instead of localhost for control plane component kubeconfig files. This is a part of work to allow control plane components to be moved off hostNetwork. --- cluster/gce/config-default.sh | 3 +++ cluster/gce/config-test.sh | 3 +++ cluster/gce/gci/configure-helper.sh | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cluster/gce/config-default.sh b/cluster/gce/config-default.sh index 245f5340de3..0eb527ab232 100755 --- a/cluster/gce/config-default.sh +++ b/cluster/gce/config-default.sh @@ -529,3 +529,6 @@ export ENABLE_CSI_PROXY="${ENABLE_CSI_PROXY:-true}" # in addition to listening to 127.0.0.1, and whether kube-apiserver should connect to etcd servers # through host IP. export ETCD_LISTEN_ON_HOST_IP="${ETCD_LISTEN_ON_HOST_IP:-false}" + +# Use host IP instead of localhost in control plane kubeconfig files. +export KUBECONFIG_USE_HOST_IP="${KUBECONFIG_USE_HOST_IP:-false}" diff --git a/cluster/gce/config-test.sh b/cluster/gce/config-test.sh index 1b23afbca93..6564b815021 100755 --- a/cluster/gce/config-test.sh +++ b/cluster/gce/config-test.sh @@ -576,3 +576,6 @@ export ENABLE_CSI_PROXY="${ENABLE_CSI_PROXY:-true}" # in addition to listening to 127.0.0.1, and whether kube-apiserver should connect to etcd servers # through host IP. export ETCD_LISTEN_ON_HOST_IP="${ETCD_LISTEN_ON_HOST_IP:-false}" + +# Use host IP instead of localhost in control plane kubeconfig files. +export KUBECONFIG_USE_HOST_IP="${KUBECONFIG_USE_HOST_IP:-false}" diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index 06e55240c95..a2395e12c98 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -1265,11 +1265,18 @@ EOF fi } +# Create kubeconfig files for control plane components. function create-kubeconfig { local component=$1 local token=$2 echo "Creating kubeconfig file for component ${component}" mkdir -p "/etc/srv/kubernetes/${component}" + + local kube_apiserver="localhost" + if [[ ${KUBECONFIG_USE_HOST_IP:-} == "true" ]] ; then + kube_apiserver=$(hostname -i) + fi + cat <"/etc/srv/kubernetes/${component}/kubeconfig" apiVersion: v1 kind: Config @@ -1281,7 +1288,7 @@ clusters: - name: local cluster: insecure-skip-tls-verify: true - server: https://localhost:443 + server: https://${kube_apiserver}:443 contexts: - context: cluster: local