Skip to content

Commit 16f8588

Browse files
committed
Override hostname with instance name
1 parent 5ea0b25 commit 16f8588

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
@@ -1143,9 +1143,20 @@ function Start-WorkerServices {
11431143
$kubelet_args_str = ${kube_env}['KUBELET_ARGS']
11441144
$kubelet_args = $kubelet_args_str.Split(" ")
11451145
Log-Output "kubelet_args from metadata: ${kubelet_args}"
1146+
1147+
# To join GCE instances to AD, we need to shorten their names, as NetBIOS name
1148+
# must be <= 15 characters, and GKE generated names are longer than that.
1149+
# To perform the join in an automated way, it's preferable to apply the rename
1150+
# and domain join in the GCESysprep step. However, after sysprep is complete
1151+
# and the machine restarts, kubelet bootstrapping should not use the shortened
1152+
# computer name, and instead use the instance's name by using --hostname-override,
1153+
# otherwise kubelet and kube-proxy will not be able to run properly.
1154+
$instance_name = "$(Get-InstanceMetadata 'name' | Out-String)"
11461155
$default_kubelet_args = @(`
1147-
"--pod-infra-container-image=${env:INFRA_CONTAINER}"
1156+
"--pod-infra-container-image=${env:INFRA_CONTAINER}",
1157+
"--hostname-override=${instance_name}"
11481158
)
1159+
11491160
$kubelet_args = ${default_kubelet_args} + ${kubelet_args}
11501161
if (-not (Test-NodeUsesAuthPlugin ${kube_env})) {
11511162
Log-Output 'Using bootstrap kubeconfig for authentication'
@@ -1170,8 +1181,10 @@ function Start-WorkerServices {
11701181
# And also with various volumeMounts and "securityContext: privileged: true".
11711182
$default_kubeproxy_args = @(`
11721183
"--kubeconfig=${env:KUBEPROXY_KUBECONFIG}",
1173-
"--cluster-cidr=$(${kube_env}['CLUSTER_IP_RANGE'])"
1184+
"--cluster-cidr=$(${kube_env}['CLUSTER_IP_RANGE'])",
1185+
"--hostname-override=${instance_name}"
11741186
)
1187+
11751188
$kubeproxy_args = ${default_kubeproxy_args} + ${kubeproxy_args}
11761189
Log-Output "Final kubeproxy_args: ${kubeproxy_args}"
11771190

0 commit comments

Comments
 (0)