@@ -1143,9 +1143,20 @@ function Start-WorkerServices {
1143
1143
$kubelet_args_str = ${kube_env} [' KUBELET_ARGS' ]
1144
1144
$kubelet_args = $kubelet_args_str.Split (" " )
1145
1145
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 ) "
1146
1155
$default_kubelet_args = @ (`
1147
- " --pod-infra-container-image=${env: INFRA_CONTAINER} "
1156
+ " --pod-infra-container-image=${env: INFRA_CONTAINER} " ,
1157
+ " --hostname-override=${instance_name} "
1148
1158
)
1159
+
1149
1160
$kubelet_args = ${default_kubelet_args} + ${kubelet_args}
1150
1161
if (-not (Test-NodeUsesAuthPlugin ${kube_env} )) {
1151
1162
Log- Output ' Using bootstrap kubeconfig for authentication'
@@ -1170,8 +1181,10 @@ function Start-WorkerServices {
1170
1181
# And also with various volumeMounts and "securityContext: privileged: true".
1171
1182
$default_kubeproxy_args = @ (`
1172
1183
" --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} "
1174
1186
)
1187
+
1175
1188
$kubeproxy_args = ${default_kubeproxy_args} + ${kubeproxy_args}
1176
1189
Log- Output " Final kubeproxy_args: ${kubeproxy_args} "
1177
1190
0 commit comments