|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * windows_containers/creating_windows_machinesets/creating-windows-machineset-vsphere.adoc |
| 4 | + |
| 5 | +[id="creating-the-vsphere-windows-vm-golden-image_{context}"] |
| 6 | += Creating the vSphere Windows VM golden image |
| 7 | + |
| 8 | +Create a vSphere Windows virtual machine (VM) golden image. |
| 9 | + |
| 10 | +.Prerequisites |
| 11 | + |
| 12 | +* You have installed a cluster on vSphere. |
| 13 | + |
| 14 | +.Procedure |
| 15 | + |
| 16 | +. Create the VM from an updated version of the Windows Server 1909 VM image that includes the following link:https://support.microsoft.com/en-us/help/4565351/windows-10-update-kb4565351[Microsoft patch]. |
| 17 | + |
| 18 | +. Create the `C:\Users\Administrator.ssh\authorized_keys` file in the Windows VM containing the public key that corresponds to the private key that resides in the secret you created in the `openshift-windows-machine-config-operator` namespace. The private key of the secret was created when first installing the Windows Machine Config Operator (WMCO) to give {product-title} access to Windows VMs. The `authorized_keys` file is used to configure SSH in the Windows VM. |
| 19 | + |
| 20 | +. Configure SSH on the Windows VM by running the following Powershell script: |
| 21 | ++ |
| 22 | +[source,posh] |
| 23 | +---- |
| 24 | +# Powershell script to configure SSH on vSphere Windows VMs |
| 25 | +Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 |
| 26 | +$firewallRuleName = "ContainerLogsPort" |
| 27 | +$containerLogsPort = "10250" |
| 28 | +New-NetFirewallRule -DisplayName $firewallRuleName -Direction Inbound -Action Allow -Protocol TCP -LocalPort $containerLogsPort -EdgeTraversalPolicy Allow |
| 29 | +Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force |
| 30 | +Install-Module -Force OpenSSHUtils |
| 31 | +Set-Service -Name ssh-agent -StartupType 'Automatic' |
| 32 | +Set-Service -Name sshd -StartupType 'Automatic' |
| 33 | +Start-Service ssh-agent |
| 34 | +Start-Service sshd |
| 35 | +$pubKeyConf = (Get-Content -path C:\ProgramData\ssh\sshd_config) -replace '#PubkeyAuthentication yes','PubkeyAuthentication yes' |
| 36 | +$pubKeyConf | Set-Content -Path C:\ProgramData\ssh\sshd_config |
| 37 | +$passwordConf = (Get-Content -path C:\ProgramData\ssh\sshd_config) -replace '#PasswordAuthentication yes','PasswordAuthentication yes' |
| 38 | +$passwordConf | Set-Content -Path C:\ProgramData\ssh\sshd_config |
| 39 | +$authFileConf = (Get-Content -path C:\ProgramData\ssh\sshd_config) -replace 'AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys','#AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys' |
| 40 | +$authFileConf | Set-Content -Path C:\ProgramData\ssh\sshd_config |
| 41 | +$pubKeyLocationConf = (Get-Content -path C:\ProgramData\ssh\sshd_config) -replace 'Match Group administrators','#Match Group administrators' |
| 42 | +$pubKeyLocationConf | Set-Content -Path C:\ProgramData\ssh\sshd_config |
| 43 | +Restart-Service sshd |
| 44 | +New-item -Path $env:USERPROFILE -Name .ssh -ItemType Directory -force |
| 45 | +---- |
| 46 | + |
| 47 | +. Install and configure VMware Tools version 11.0.6 or greater on the Windows VM. See the link:https://docs.vmware.com/en/VMware-Tools/index.html[VMware Tools documentation] for more information. |
| 48 | + |
| 49 | +. After installing VMware Tools on the Windows VM, verify the following: |
| 50 | +.. The `C:\ProgramData\VMware\VMware Tools\tools.conf` file has the following entry: |
| 51 | ++ |
| 52 | +[source,ini] |
| 53 | +---- |
| 54 | +exclude-nics= |
| 55 | +---- |
| 56 | ++ |
| 57 | +This entry ensures the following: |
| 58 | ++ |
| 59 | +* The cloned vNIC generated on the Windows VM by the hybrid-overlay is not ignored. |
| 60 | +* The VM has an IP address in vCenter. |
| 61 | + |
| 62 | +.. The VMTools Windows service is running. |
| 63 | + |
| 64 | +. Pull all of the required Windows container base images needed for your applications. The images you pull |
| 65 | +are dependent on the Windows kernel you are using. See Microsoft's documentation on link:https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-base-images[pulling Windows container base images] for more information. |
| 66 | + |
| 67 | +. Run the link:https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/sysprep--generalize--a-windows-installation[Windows Sysprep tool] on the Windows VM: |
| 68 | ++ |
| 69 | +[source,terminal] |
| 70 | +---- |
| 71 | +C:\> sysprep.exe /generalize /oobe /shutdown /unattend:<path_to_unattend.xml> |
| 72 | +---- |
| 73 | ++ |
| 74 | +An example `unattend.xml` is provided, which maintains all the changes needed for the WMCO. For example, the `unattend.xml` file must ensure the Administrator's home directory stays intact with the SSH public key. You must customize the example to fit your needs. |
| 75 | ++ |
| 76 | +.Example `unattend.xml` |
| 77 | +[%collapsible] |
| 78 | +==== |
| 79 | +[source,xml] |
| 80 | +---- |
| 81 | +<?xml version="1.0" encoding="UTF-8"?> |
| 82 | +<!--A sample unattend.xml which helps in setting admin password and running scripts on first boot--> |
| 83 | +<unattend xmlns="urn:schemas-microsoft-com:unattend"> |
| 84 | + <settings pass="specialize"> |
| 85 | + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http:// www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core" processorArchitecture="am d64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> |
| 86 | + <InputLocale>0409:00000409</InputLocale> |
| 87 | + <SystemLocale>en-US</SystemLocale> |
| 88 | + <UILanguage>en-US</UILanguage> |
| 89 | + <UILanguageFallback>en-US</UILanguageFallback> |
| 90 | + <UserLocale>en-US</UserLocale> |
| 91 | + </component> |
| 92 | + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> |
| 93 | + <SkipAutoActivation>true</SkipAutoActivation> |
| 94 | + </component> |
| 95 | + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-SQMApi" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> |
| 96 | + <CEIPEnabled>0</CEIPEnabled> |
| 97 | + </component> |
| 98 | + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> |
| 99 | + <ComputerName>windows-host</ComputerName> |
| 100 | + <ProductKey>My_Product_key</ProductKey> |
| 101 | + </component> |
| 102 | + </settings> |
| 103 | + <settings pass="oobeSystem"> |
| 104 | + <component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> |
| 105 | + <AutoLogon> |
| 106 | + <Password> |
| 107 | + <Value>MyPassword</Value> |
| 108 | + <PlainText>true</PlainText> |
| 109 | + </Password> |
| 110 | + <Enabled>true</Enabled> |
| 111 | + <Username>Administrator</Username> |
| 112 | + </AutoLogon> |
| 113 | + <OOBE> |
| 114 | + <HideEULAPage>true</HideEULAPage> |
| 115 | + <HideLocalAccountScreen>true</HideLocalAccountScreen> |
| 116 | + <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> |
| 117 | + <HideOnlineAccountScreens>true</HideOnlineAccountScreens> |
| 118 | + <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> |
| 119 | + <NetworkLocation>Work</NetworkLocation> |
| 120 | + <ProtectYourPC>1</ProtectYourPC> |
| 121 | + <SkipMachineOOBE>true</SkipMachineOOBE> |
| 122 | + <SkipUserOOBE>true</SkipUserOOBE> |
| 123 | + </OOBE> |
| 124 | + <RegisteredOrganization>Organization</RegisteredOrganization> |
| 125 | + <RegisteredOwner>Owner</RegisteredOwner> |
| 126 | + <DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet> |
| 127 | + <TimeZone>Eastern Standard Time</TimeZone> |
| 128 | + <UserAccounts> |
| 129 | + <AdministratorPassword> |
| 130 | + <Value>MyPassword</Value> |
| 131 | + <PlainText>true</PlainText> |
| 132 | + </AdministratorPassword> |
| 133 | + <LocalAccounts> |
| 134 | + <LocalAccount wcm:action="add"> |
| 135 | + <Description>Administrator</Description> |
| 136 | + <DisplayName>Administrator</DisplayName> |
| 137 | + <Group>Administrators</Group> |
| 138 | + <Name>Administrator</Name> |
| 139 | + </LocalAccount> |
| 140 | + </LocalAccounts> |
| 141 | + </UserAccounts> |
| 142 | + </component> |
| 143 | + </settings> |
| 144 | +</unattend> |
| 145 | +---- |
| 146 | +==== |
0 commit comments