@@ -411,6 +411,56 @@ function BasePrep {
411411 New-HostsConfigService
412412 }
413413
414+ # NOTE: Network configuration has been moved to NodePrep to prevent HNS network
415+ # state from being baked into VHD images, which causes DHCP conflicts when
416+ # multiple VMs are created from the same image.
417+
418+ Set-Explorer
419+ Adjust- PageFileSize
420+ Logs- To- Event - TaskName " AKS.WindowsCSE.PreprovisionExtension" - TaskMessage " Start preProvisioning script"
421+ PREPROVISION_EXTENSION
422+ Update-ServiceFailureActions
423+ Adjust- DynamicPortRange
424+ Register-LogsCleanupScriptTask
425+ Register-NodeResetScriptTask
426+
427+ Update-DefenderPreferences
428+
429+ $windowsVersion = Get-WindowsVersion
430+ if ($windowsVersion -ne " 1809" ) {
431+ Logs- To- Event - TaskName " AKS.WindowsCSE.EnableSecureTLS" - TaskMessage " Skip secure TLS protocols for Windows version: $windowsVersion "
432+ } else {
433+ Logs- To- Event - TaskName " AKS.WindowsCSE.EnableSecureTLS" - TaskMessage " Start to enable secure TLS protocols"
434+ try {
435+ . C:\k\windowssecuretls.ps1
436+ Enable-SecureTls
437+ }
438+ catch {
439+ Set-ExitCode - ExitCode $global :WINDOWS_CSE_ERROR_ENABLE_SECURE_TLS - ErrorMessage $_
440+ }
441+ }
442+
443+ Enable-FIPSMode - FipsEnabled $fipsEnabled
444+ if ($global :WindowsGmsaPackageUrl ) {
445+ Install-GmsaPlugin - GmsaPackageUrl $global :WindowsGmsaPackageUrl
446+ }
447+
448+ Write-Log " BasePrep completed successfully"
449+ Logs- To- Event - TaskName " AKS.WindowsCSE.BasePrep" - TaskMessage " BasePrep completed successfully"
450+ }
451+
452+ # ====== NODE PREP: CLUSTER INTEGRATION ======
453+ # All operations that should only run when connecting to the actual cluster
454+ function NodePrep {
455+ Install-KubernetesServices - KubeDir $global :KubeDir
456+
457+ Write-Log " Starting NodePrep - Cluster integration"
458+ Logs- To- Event - TaskName " AKS.WindowsCSE.NodePrep" - TaskMessage " Starting NodePrep - Cluster integration"
459+
460+ Check- APIServerConnectivity - MasterIP $MasterIP
461+
462+ # Configure networking - this must run during node provisioning, not VHD creation
463+ # to ensure each VM gets unique HNS network IDs and avoids DHCP conflicts
414464 Write-Log " Configuring networking with NetworkPlugin:$global :NetworkPlugin "
415465
416466 # Configure network policy.
@@ -458,50 +508,6 @@ function BasePrep {
458508 Write-Log " Enable-WindowsCiliumNetworking is not a recognized function, will skip Windows Cilium Networking installation"
459509 }
460510
461- Set-Explorer
462- Adjust- PageFileSize
463- Logs- To- Event - TaskName " AKS.WindowsCSE.PreprovisionExtension" - TaskMessage " Start preProvisioning script"
464- PREPROVISION_EXTENSION
465- Update-ServiceFailureActions
466- Adjust- DynamicPortRange
467- Register-LogsCleanupScriptTask
468- Register-NodeResetScriptTask
469-
470- Update-DefenderPreferences
471-
472- $windowsVersion = Get-WindowsVersion
473- if ($windowsVersion -ne " 1809" ) {
474- Logs- To- Event - TaskName " AKS.WindowsCSE.EnableSecureTLS" - TaskMessage " Skip secure TLS protocols for Windows version: $windowsVersion "
475- } else {
476- Logs- To- Event - TaskName " AKS.WindowsCSE.EnableSecureTLS" - TaskMessage " Start to enable secure TLS protocols"
477- try {
478- . C:\k\windowssecuretls.ps1
479- Enable-SecureTls
480- }
481- catch {
482- Set-ExitCode - ExitCode $global :WINDOWS_CSE_ERROR_ENABLE_SECURE_TLS - ErrorMessage $_
483- }
484- }
485-
486- Enable-FIPSMode - FipsEnabled $fipsEnabled
487- if ($global :WindowsGmsaPackageUrl ) {
488- Install-GmsaPlugin - GmsaPackageUrl $global :WindowsGmsaPackageUrl
489- }
490-
491- Write-Log " BasePrep completed successfully"
492- Logs- To- Event - TaskName " AKS.WindowsCSE.BasePrep" - TaskMessage " BasePrep completed successfully"
493- }
494-
495- # ====== NODE PREP: CLUSTER INTEGRATION ======
496- # All operations that should only run when connecting to the actual cluster
497- function NodePrep {
498- Install-KubernetesServices - KubeDir $global :KubeDir
499-
500- Write-Log " Starting NodePrep - Cluster integration"
501- Logs- To- Event - TaskName " AKS.WindowsCSE.NodePrep" - TaskMessage " Starting NodePrep - Cluster integration"
502-
503- Check- APIServerConnectivity - MasterIP $MasterIP
504-
505511 if ($global :WindowsCalicoPackageURL ) {
506512 Start-InstallCalico - RootDir " c:\" - KubeServiceCIDR $global :KubeServiceCIDR - KubeDnsServiceIp $KubeDnsServiceIp
507513 }
0 commit comments