Skip to content

Commit

Permalink
Merge pull request #95209 from benhxy/gke/kubeconfig
Browse files Browse the repository at this point in the history
Use host IP instead of localhost for GKE control plane kubeconfig
  • Loading branch information
k8s-ci-robot committed Oct 23, 2020
2 parents ad97d93 + 49afcfa commit e850fa6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cluster/gce/config-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
3 changes: 3 additions & 0 deletions cluster/gce/config-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
9 changes: 8 additions & 1 deletion cluster/gce/gci/configure-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF >"/etc/srv/kubernetes/${component}/kubeconfig"
apiVersion: v1
kind: Config
Expand All @@ -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
Expand Down

0 comments on commit e850fa6

Please sign in to comment.