Skip to content

Commit 9707537

Browse files
authored
Merge pull request kubernetes#94267 from lizhuqi/hostname-override
Override hostname with instance name
2 parents 5118418 + 16f8588 commit 9707537

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

cluster/gce/windows/k8s-node-setup.psm1

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,20 @@ function Start-WorkerServices {
11381138
$kubelet_args_str = ${kube_env}['KUBELET_ARGS']
11391139
$kubelet_args = $kubelet_args_str.Split(" ")
11401140
Log-Output "kubelet_args from metadata: ${kubelet_args}"
1141+
1142+
# To join GCE instances to AD, we need to shorten their names, as NetBIOS name
1143+
# must be <= 15 characters, and GKE generated names are longer than that.
1144+
# To perform the join in an automated way, it's preferable to apply the rename
1145+
# and domain join in the GCESysprep step. However, after sysprep is complete
1146+
# and the machine restarts, kubelet bootstrapping should not use the shortened
1147+
# computer name, and instead use the instance's name by using --hostname-override,
1148+
# otherwise kubelet and kube-proxy will not be able to run properly.
1149+
$instance_name = "$(Get-InstanceMetadata 'name' | Out-String)"
11411150
$default_kubelet_args = @(`
1142-
"--pod-infra-container-image=${env:INFRA_CONTAINER}"
1151+
"--pod-infra-container-image=${env:INFRA_CONTAINER}",
1152+
"--hostname-override=${instance_name}"
11431153
)
1154+
11441155
$kubelet_args = ${default_kubelet_args} + ${kubelet_args}
11451156
if (-not (Test-NodeUsesAuthPlugin ${kube_env})) {
11461157
Log-Output 'Using bootstrap kubeconfig for authentication'
@@ -1165,8 +1176,10 @@ function Start-WorkerServices {
11651176
# And also with various volumeMounts and "securityContext: privileged: true".
11661177
$default_kubeproxy_args = @(`
11671178
"--kubeconfig=${env:KUBEPROXY_KUBECONFIG}",
1168-
"--cluster-cidr=$(${kube_env}['CLUSTER_IP_RANGE'])"
1179+
"--cluster-cidr=$(${kube_env}['CLUSTER_IP_RANGE'])",
1180+
"--hostname-override=${instance_name}"
11691181
)
1182+
11701183
$kubeproxy_args = ${default_kubeproxy_args} + ${kubeproxy_args}
11711184
Log-Output "Final kubeproxy_args: ${kubeproxy_args}"
11721185

0 commit comments

Comments
 (0)