@@ -1138,9 +1138,20 @@ function Start-WorkerServices {
1138
1138
$kubelet_args_str = ${kube_env} [' KUBELET_ARGS' ]
1139
1139
$kubelet_args = $kubelet_args_str.Split (" " )
1140
1140
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 ) "
1141
1150
$default_kubelet_args = @ (`
1142
- " --pod-infra-container-image=${env: INFRA_CONTAINER} "
1151
+ " --pod-infra-container-image=${env: INFRA_CONTAINER} " ,
1152
+ " --hostname-override=${instance_name} "
1143
1153
)
1154
+
1144
1155
$kubelet_args = ${default_kubelet_args} + ${kubelet_args}
1145
1156
if (-not (Test-NodeUsesAuthPlugin ${kube_env} )) {
1146
1157
Log- Output ' Using bootstrap kubeconfig for authentication'
@@ -1165,8 +1176,10 @@ function Start-WorkerServices {
1165
1176
# And also with various volumeMounts and "securityContext: privileged: true".
1166
1177
$default_kubeproxy_args = @ (`
1167
1178
" --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} "
1169
1181
)
1182
+
1170
1183
$kubeproxy_args = ${default_kubeproxy_args} + ${kubeproxy_args}
1171
1184
Log- Output " Final kubeproxy_args: ${kubeproxy_args} "
1172
1185
0 commit comments