Skip to content

Commit 1a645c2

Browse files
authored
Merge pull request kubernetes#95743 from benhxy/apiserver-health
Use host IP instead of 127.0.0.1 for kube-apiserver healthcheck.
2 parents 63eacc2 + 8416c5c commit 1a645c2

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

cluster/gce/config-default.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,11 @@ export KONNECTIVITY_SERVICE_PROXY_PROTOCOL_MODE="${KUBE_KONNECTIVITY_SERVICE_PRO
539539
# Optional: Enable Windows CSI-Proxy
540540
export ENABLE_CSI_PROXY="${ENABLE_CSI_PROXY:-true}"
541541

542-
# ETCD_LISTEN_ON_HOST_IP decides whether etcd servers should also listen on host IP,
542+
# KUBE_APISERVER_HEALTHCHECK_ON_HOST_IP decides whether
543+
# kube-apiserver is healthchecked on host IP instead of 127.0.0.1.
544+
export KUBE_APISERVER_HEALTHCHECK_ON_HOST_IP="${KUBE_APISERVER_HEALTHCHECK_ON_HOST_IP:-false}"
545+
546+
# ETCD_LISTEN_ON_HOST_IP decides whether etcd servers should also listen on host IP,
543547
# in addition to listening to 127.0.0.1, and whether kube-apiserver should connect to etcd servers
544548
# through host IP.
545549
export ETCD_LISTEN_ON_HOST_IP="${ETCD_LISTEN_ON_HOST_IP:-false}"

cluster/gce/config-test.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,11 @@ export GCE_UPLOAD_KUBCONFIG_TO_MASTER_METADATA=true
575575
# Optoinal: Enable Windows CSI-Proxy
576576
export ENABLE_CSI_PROXY="${ENABLE_CSI_PROXY:-true}"
577577

578-
# ETCD_LISTEN_ON_HOST_IP decides whether etcd servers should also listen on host IP,
578+
# KUBE_APISERVER_HEALTHCHECK_ON_HOST_IP decides whether
579+
# kube-apiserver is healthchecked on host IP instead of 127.0.0.1.
580+
export KUBE_APISERVER_HEALTHCHECK_ON_HOST_IP="${KUBE_APISERVER_HEALTHCHECK_ON_HOST_IP:-false}"
581+
582+
# ETCD_LISTEN_ON_HOST_IP decides whether etcd servers should also listen on host IP,
579583
# in addition to listening to 127.0.0.1, and whether kube-apiserver should connect to etcd servers
580584
# through host IP.
581585
export ETCD_LISTEN_ON_HOST_IP="${ETCD_LISTEN_ON_HOST_IP:-false}"

cluster/gce/gci/configure-kubeapiserver.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ function start-kube-apiserver {
374374
# params is passed by reference, so no "$"
375375
setup-etcd-encryption "${src_file}" params
376376

377+
local healthcheck_ip="127.0.0.1"
378+
if [[ ${KUBE_APISERVER_HEALTHCHECK_ON_HOST_IP:-} == "true" ]]; then
379+
healthcheck_ip=$(hostname -i)
380+
fi
381+
377382
params="$(convert-manifest-params "${params}")"
378383
# Evaluate variables.
379384
local -r kube_apiserver_docker_tag="${KUBE_API_SERVER_DOCKER_TAG:-$(cat /home/kubernetes/kube-docker-files/kube-apiserver.docker_tag)}"
@@ -404,6 +409,7 @@ function start-kube-apiserver {
404409
sed -i -e "s@{{webhook_exec_auth_plugin_volume}}@${webhook_exec_auth_plugin_volume}@g" "${src_file}"
405410
sed -i -e "s@{{konnectivity_socket_mount}}@${default_konnectivity_socket_mnt}@g" "${src_file}"
406411
sed -i -e "s@{{konnectivity_socket_volume}}@${default_konnectivity_socket_vol}@g" "${src_file}"
412+
sed -i -e "s@{{healthcheck_ip}}@${healthcheck_ip}@g" "${src_file}"
407413

408414
cp "${src_file}" "${ETC_MANIFESTS:-/etc/kubernetes/manifests}"
409415
}

cluster/gce/manifests/kube-apiserver.manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"livenessProbe": {
3838
"httpGet": {
3939
"scheme": "HTTPS",
40-
"host": "127.0.0.1",
40+
"host": "{{healthcheck_ip}}",
4141
"port": {{secure_port}},
4242
"path": "/livez?exclude=etcd&exclude=kms-provider-0&exclude=kms-provider-1"
4343
},
@@ -47,7 +47,7 @@
4747
"readinessProbe": {
4848
"httpGet": {
4949
"scheme": "HTTPS",
50-
"host": "127.0.0.1",
50+
"host": "{{healthcheck_ip}}",
5151
"port": {{secure_port}},
5252
"path": "/readyz"
5353
},

0 commit comments

Comments
 (0)