Skip to content

Commit c7aa2f2

Browse files
author
Jaromir Kaspar
authored
Merge pull request #443 from microsoft/dev
Dev
2 parents 524f461 + cd33b09 commit c7aa2f2

File tree

4 files changed

+133
-36
lines changed

4 files changed

+133
-36
lines changed

Scenarios/AzSHCI and Kubernetes/LabConfig.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!' ; <#Prefix = 'WSLab-'#> ; DCEdition='4'; Internet=$true ; TelemetryLevel='Full' ; TelemetryNickname='' ; AdditionalNetworksConfig=@(); VMs=@()}
1+
$LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!' ; Prefix = 'MSLab-' ; DCEdition='4'; Internet=$true ; TelemetryLevel='Full' ; TelemetryNickname='' ; AdditionalNetworksConfig=@(); VMs=@()}
22

33
#2 nodes for AzSHCI Cluster
44
1..2 | ForEach-Object {$VMNames="AzSHCI" ; $LABConfig.VMs += @{ VMName = "$VMNames$_" ; Configuration = 'S2D' ; ParentVHD = 'AzSHCI20H2_G2.vhdx' ; HDDNumber = 4 ; HDDSize= 4TB ; MemoryStartupBytes= 24GB; VMProcessorCount="Max" ; NestedVirt=$true}}

Scenarios/AzSHCI and Kubernetes/Scenario.ps1

Lines changed: 110 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
<#
2+
Not needed anymore. Keeping it if someone wants to recycle
3+
14
#############################
25
### Run from Hyper-V Host ###
36
#############################
47
58
#run from Host to expand C: drives in VMs to 120GB. This is required as Install-AKSHCI checks free space on C (should check free space in CSV)
6-
$VMs=Get-VM -VMName WSLab*azshci*
9+
#script grabs all VMs starting with "MSLab" (and containing azshci), so modify line below accordingly
10+
$VMs=Get-VM -VMName MSLab*azshci*
711
$VMs | Get-VMHardDiskDrive -ControllerLocation 0 | Resize-VHD -SizeBytes 120GB
812
#VM Credentials
913
$secpasswd = ConvertTo-SecureString "LS1setup!" -AsPlainText -Force
@@ -15,6 +19,8 @@ Foreach ($VM in $VMs){
1519
$part | Resize-Partition -Size $sizemax
1620
}
1721
}
22+
#>
23+
1824

1925
###################
2026
### Run from DC ###
@@ -108,7 +114,7 @@ Clear-DNSClientCache
108114
Enable-ClusterS2D -CimSession $ClusterName -Verbose -Confirm:0
109115
#endregion
110116

111-
#region Register Azure Stack HCI to Azure
117+
#region Register Azure Stack HCI to Azure - if not registered, VMs are not added as cluster resources = AKS script will fail
112118
$ClusterName="AzSHCI-Cluster"
113119

114120
#download Azure module
@@ -141,10 +147,10 @@ reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMa
141147
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\EscDomains\msftauth.net\aadcdn" /v https /t REG_DWORD /d 2
142148
Connect-AzAccount
143149
#>
144-
#select context if more available
145-
$context=Get-AzContext -ListAvailable
146-
if (($context).count -gt 1){
147-
$context | Out-GridView -OutputMode Single | Set-AzContext
150+
#select subscription if more available
151+
$subscription=Get-AzSubscription
152+
if (($subscription).count -gt 1){
153+
$subscription | Out-GridView -OutputMode Single | Set-AzContext
148154
}
149155

150156
#grab subscription ID
@@ -194,36 +200,54 @@ Invoke-Command -ComputerName $ClusterName -ScriptBlock {
194200
}
195201
#endregion
196202

197-
#region Download AKS HCI module
198-
Start-BitsTransfer -Source "https://aka.ms/aks-hci-download" -Destination "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Mar-2021.zip"
199-
#unzip
200-
Expand-Archive -Path "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Mar-2021.zip" -DestinationPath "$env:USERPROFILE\Downloads" -Force
201-
Expand-Archive -Path "$env:USERPROFILE\Downloads\AksHci.Powershell.zip" -DestinationPath "$env:USERPROFILE\Downloads\AksHci.Powershell" -Force
203+
#region Install required modules for AKSHCI https://docs.microsoft.com/en-us/azure-stack/aks-hci/kubernetes-walkthrough-powershell
204+
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
205+
Install-Module -Name PowershellGet -Force -Confirm:$false -SkipPublisherCheck
206+
Update-Module -Name PowerShellGet
207+
#Install-Module -Name Az.Accounts -Repository PSGallery -RequiredVersion 2.2.4 -Force
208+
#Install-Module -Name Az.Resources -Repository PSGallery -RequiredVersion 3.2.0 -Force
209+
#Install-Module -Name AzureAD -Repository PSGallery -RequiredVersion 2.0.2.128 -Force
210+
#to be able to install AKSHCI, powershellget 2.2.5 needs to be used - to this posh restart is needed
211+
Start-Process -FilePath PowerShell -ArgumentList {
212+
Install-Module -Name AksHci -Repository PSGallery -Force -AcceptLicense
213+
}
214+
#add required modules (parsing required modules from kva.psd - it also requires certain version of modules)
215+
#JaromirK note: it would be great if this dependency was downloaded automagically or if you would be ok with latest version (or some minimumversion)
216+
$item=Get-ChildItem -Path "C:\Program Files\WindowsPowerShell\Modules\Kva" -Recurse | Where-Object name -eq kva.psd1
217+
$RequiredModules=(Import-LocalizedData -BaseDirectory $item.Directory -FileName $item.Name).RequiredModules
218+
foreach ($RequiredModule in $RequiredModules){
219+
if (!(Get-InstalledModule -Name $RequiredModule.ModuleName -RequiredVersion $RequiredModule.RequiredVersion -ErrorAction Ignore)){
220+
Install-Module -Name $RequiredModule.ModuleName -RequiredVersion $RequiredModule.RequiredVersion -Force
221+
}
222+
}
202223

224+
#distribute modules to cluster nodes
225+
$ClusterName="AzSHCI-Cluster"
226+
$Servers=(Get-ClusterNode -Cluster $Clustername).Name
227+
$ModuleNames="AksHci","Moc","Kva"
228+
$PSSessions=New-PSSession -ComputerName $Servers
229+
Foreach ($PSSession in $PSSessions){
230+
Foreach ($ModuleName in $ModuleNames){
231+
Copy-Item -Path $env:ProgramFiles\windowspowershell\modules\$ModuleName -Destination $env:ProgramFiles\windowspowershell\modules -ToSession $PSSession -Recurse -Force
232+
}
233+
Foreach ($ModuleName in $RequiredModules.ModuleName){
234+
Copy-Item -Path $env:ProgramFiles\windowspowershell\modules\$ModuleName -Destination $env:ProgramFiles\windowspowershell\modules -ToSession $PSSession -Recurse -Force
235+
}
236+
}
203237
#endregion
204238

205239
#region setup AKS (PowerShell)
206-
#Copy PowerShell module to nodes
240+
#set variables
207241
$ClusterName="AzSHCI-Cluster"
208242
$vSwitchName="vSwitch"
243+
$vNetName="aksvnet"
209244
$VolumeName="AKS"
210245
$Servers=(Get-ClusterNode -Cluster $ClusterName).Name
211246
$VIPPoolStart="10.0.0.100"
212247
$VIPPoolEnd="10.0.0.200"
248+
$resourcegroupname="$ClusterName-rg"
213249

214-
#Copy module to nodes
215-
$PSSessions=New-PSSession -ComputerName $Servers
216-
foreach ($PSSession in $PSSessions){
217-
$Folders=Get-ChildItem -Path $env:USERPROFILE\Downloads\AksHci.Powershell\
218-
foreach ($Folder in $Folders){
219-
Copy-Item -Path $folder.FullName -Destination $env:ProgramFiles\windowspowershell\modules -ToSession $PSSession -Recurse -Force
220-
}
221-
}
222-
223-
#why this does not work? Why I need to login ot server to run initialize AKSHCINode???
224-
<#Invoke-Command -ComputerName $servers -ScriptBlock {
225-
Initialize-AksHciNode
226-
}#>
250+
#JaromirK note: it would be great if I could simply run "Initialize-AksHciNode -ComputerName $ClusterName". I could simply skip credssp. Same applies for AksHciConfig and AksHciRegistration
227251

228252
#Enable CredSSP
229253
# Temporarily enable CredSSP delegation to avoid double-hop issue
@@ -247,16 +271,63 @@ Expand-Archive -Path "$env:USERPROFILE\Downloads\AksHci.Powershell.zip" -Destina
247271
}
248272
#configure aks
249273
Invoke-Command -ComputerName $servers[0] -Credential $Credentials -Authentication Credssp -ScriptBlock {
250-
$vnet = New-AksHciNetworkSetting -vnetName $using:vSwitchName -vippoolstart $using:vippoolstart -vippoolend $using:vippoolend
251-
#Set-AksHciConfig -vnet $vnet -workingDir c:\clusterstorage\$using:VolumeName\Images -imageDir c:\clusterstorage\$using:VolumeName\Images -cloudConfigLocation c:\clusterstorage\$using:VolumeName\Config -ClusterRoleName "$($using:ClusterName)_AKS" -enableDiagnosticData -controlPlaneVmSize 'default' # Get-AksHciVmSize
252-
Set-AksHciConfig -vnet $vnet -imageDir c:\clusterstorage\$using:VolumeName\Images -cloudConfigLocation c:\clusterstorage\$using:VolumeName\Config -ClusterRoleName "$($using:ClusterName)_AKS" -enableDiagnosticData -controlPlaneVmSize 'default' # Get-AksHciVmSize
274+
$vnet = New-AksHciNetworkSetting -Name $using:vNetName -vSwitchName $using:vSwitchName -vippoolstart $using:vippoolstart -vippoolend $using:vippoolend
275+
#Set-AksHciConfig -vnet $vnet -workingDir c:\clusterstorage\$using:VolumeName\Images -imageDir c:\clusterstorage\$using:VolumeName\Images -cloudConfigLocation c:\clusterstorage\$using:VolumeName\Config -ClusterRoleName "$($using:ClusterName)_AKS" -controlPlaneVmSize 'default' # Get-AksHciVmSize
276+
Set-AksHciConfig -vnet $vnet -imageDir c:\clusterstorage\$using:VolumeName\Images -cloudConfigLocation c:\clusterstorage\$using:VolumeName\Config -ClusterRoleName "$($using:ClusterName)_AKS" -controlPlaneVmSize 'default' # Get-AksHciVmSize
253277
}
254278

255279
#validate config
256280
Invoke-Command -ComputerName $servers[0] -ScriptBlock {
257281
Get-AksHciConfig
258282
}
259283

284+
#register in Azure
285+
if (-not (Get-AzContext)){
286+
Connect-AzAccount -UseDeviceAuthentication
287+
}
288+
$subscription=Get-AzSubscription
289+
if (($subscription).count -gt 1){
290+
$subscription | Out-GridView -OutputMode Single | Set-AzContext
291+
}
292+
$subscriptionID=(Get-AzContext).Subscription.id
293+
294+
#make sure Kubernetes resource providers are registered
295+
if (!(Get-InstalledModule -Name Az.Resources -ErrorAction Ignore)){
296+
Install-Module -Name Az.Resources -Force
297+
}
298+
Register-AzResourceProvider -ProviderNamespace Microsoft.Kubernetes
299+
Register-AzResourceProvider -ProviderNamespace Microsoft.KubernetesConfiguration
300+
301+
#wait until resource providers are registered
302+
$Providers="Microsoft.Kubernetes","Microsoft.KubernetesConfiguration"
303+
foreach ($Provider in $Providers){
304+
do {
305+
$Status=Get-AzResourceProvider -ProviderNamespace $Provider
306+
Write-Output "Registration Status - $Provider : $(($status.RegistrationState -match 'Registered').Count)/$($Status.Count)"
307+
Start-Sleep 1
308+
} while (($status.RegistrationState -match "Registered").Count -ne ($Status.Count))
309+
}
310+
311+
#Register AZSHCi without prompting for creds
312+
$armTokenItemResource = "https://management.core.windows.net/"
313+
$graphTokenItemResource = "https://graph.windows.net/"
314+
$azContext = Get-AzContext
315+
$authFactory = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory
316+
$graphToken = $authFactory.Authenticate($azContext.Account, $azContext.Environment, $azContext.Tenant.Id, $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, $graphTokenItemResource).AccessToken
317+
$armToken = $authFactory.Authenticate($azContext.Account, $azContext.Environment, $azContext.Tenant.Id, $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, $armTokenItemResource).AccessToken
318+
$id = $azContext.Account.Id
319+
320+
Invoke-Command -computername $servers[0] -ScriptBlock {
321+
Set-AksHciRegistration -SubscriptionID $using:subscriptionID -GraphAccessToken $using:graphToken -ArmAccessToken $using:armToken -AccountId $using:id -ResourceGroupName $using:resourcegroupname
322+
}
323+
324+
#or with Device Authentication
325+
<#
326+
Invoke-Command -computername $servers[0] -ScriptBlock {
327+
Set-AksHciRegistration -SubscriptionID $using:subscriptionID -ResourceGroupName $using:resourcegroupname -UseDeviceAuthentication
328+
}
329+
#>
330+
260331
#Install
261332
Invoke-Command -ComputerName $servers[0] -Credential $Credentials -Authentication Credssp -ScriptBlock {
262333
Install-AksHci
@@ -268,13 +339,15 @@ Expand-Archive -Path "$env:USERPROFILE\Downloads\AksHci.Powershell.zip" -Destina
268339
#endregion
269340

270341
#region create AKS HCI cluster
342+
#Jaromirk note: it would be great if I could specify HCI Cluster (like New-AksHciCluster -ComputerName)
271343
$ClusterName="AzSHCI-Cluster"
272344
$ClusterNode=(Get-ClusterNode -Cluster $clustername).Name | Select-Object -First 1
273345
Invoke-Command -ComputerName $ClusterNode -ScriptBlock {
274346
New-AksHciCluster -Name demo -linuxNodeCount 1 -linuxNodeVmSize Standard_A2_v2 -controlplaneVmSize Standard_A2_v2 -EnableADAuth -loadBalancerVmSize Standard_A2_v2 #smallest possible VMs
275347
}
276348

277349
#distribute kubeconfig to other nodes (just to make it symmetric)
350+
#Jaromirk note: I think this would be useful to do with new-akshcicluster
278351
$ClusterNodes=(Get-ClusterNode -Cluster $clustername).Name
279352
$FirstSession=New-PSSession -ComputerName ($ClusterNodes | Select-Object -First 1)
280353
$OtherSessions=New-PSSession -ComputerName ($ClusterNodes | Select-Object -Skip 1)
@@ -311,6 +384,11 @@ Standard_K8S3_v1 4 6
311384
#>
312385
#endregion
313386

387+
############################################################################
388+
# Tested until here - GA AKS
389+
############################################################################
390+
391+
314392
#region onboard AKS cluster to Azure ARC
315393
$ClusterName="AzSHCI-Cluster"
316394

@@ -553,9 +631,9 @@ Get-AzADApplication -DisplayNameStartWith $ClusterName | Remove-AzADApplication
553631

554632
#add feed
555633
#download nupgk (included in aks-hci module)
556-
Start-BitsTransfer -Source "https://aka.ms/aks-hci-download" -OutFile "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Oct-2020.zip"
634+
Start-BitsTransfer -Source "https://aka.ms/aks-hci-download" -Destination "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Apr-2021.zip"
557635
#unzip
558-
Expand-Archive -Path "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Oct-2020.zip" -DestinationPath "$env:USERPROFILE\Downloads" -Force
636+
Expand-Archive -Path "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Apr-2021.zip" -DestinationPath "$env:USERPROFILE\Downloads" -Force
559637
Expand-Archive -Path "$env:USERPROFILE\Downloads\AksHci.Powershell.zip" -DestinationPath "$env:USERPROFILE\Downloads\AksHci.Powershell" -Force
560638
$Filename=Get-ChildItem -Path $env:userprofile\downloads\ | Where-Object Name -like "msft.sme.aks.*.nupkg"
561639
New-Item -Path "C:\WACFeeds\" -Name Feeds -ItemType Directory -Force
@@ -620,9 +698,9 @@ foreach ($computer in $computers){
620698
}
621699

622700
#Download AKS HCI module
623-
Start-BitsTransfer -Source "https://aka.ms/aks-hci-download" -Destination "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Oct-2020.zip"
701+
Start-BitsTransfer -Source "https://aka.ms/aks-hci-download" -Destination "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Apr-2021.zip"
624702
#unzip
625-
Expand-Archive -Path "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Oct-2020.zip" -DestinationPath "$env:USERPROFILE\Downloads" -Force
703+
Expand-Archive -Path "$env:USERPROFILE\Downloads\AKS-HCI-Public-Preview-Apr-2021.zip" -DestinationPath "$env:USERPROFILE\Downloads" -Force
626704
Expand-Archive -Path "$env:USERPROFILE\Downloads\AksHci.Powershell.zip" -DestinationPath "$env:USERPROFILE\Downloads" -Force
627705

628706
#copy nupkg to WAC

Scripts/2_CreateParentDisks.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ If (-not $isAdmin) {
384384
VHDName="Win2019Core_G2.vhdx"
385385
Size=30GB
386386
}
387+
}elseif ($BuildNumber -eq 20348){
388+
#Windows Server 2022
389+
$ServerVHDs += @{
390+
Kind = "Full"
391+
Edition="4"
392+
VHDName="Win2022_G2.vhdx"
393+
Size=60GB
394+
}
395+
$ServerVHDs += @{
396+
Kind = "Core"
397+
Edition="3"
398+
VHDName="Win2022Core_G2.vhdx"
399+
Size=30GB
400+
}
387401
}elseif ($BuildNumber -ge 17744 -and $SAC){
388402
$ServerVHDs += @{
389403
Kind = "Core"

Tools/CreateParentDisk.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,11 @@ If (-not $isAdmin) {
194194
19041 {
195195
"WinServer20H1_G2.vhdx"
196196
}
197+
20348 {
198+
"Win2022Core_G2.vhdx"
199+
}
197200
}
198-
if ($BuildNumber -gt 18362){
201+
if ($BuildNumber -gt 20348){
199202
$tempvhdname="WinSrvInsiderCore_$BuildNumber.vhdx"
200203
}
201204
}elseif($Edition -like "Hyper-V*"){
@@ -233,8 +236,11 @@ If (-not $isAdmin) {
233236
17763 {
234237
"Win2019_G2.vhdx"
235238
}
239+
20348 {
240+
"Win2022_G2.vhdx"
241+
}
236242
}
237-
if ($BuildNumber -GT 18362){
243+
if ($BuildNumber -GT 20348){
238244
$tempvhdname="WinSrvInsider_$BuildNumber.vhdx"
239245
}
240246
}else{
@@ -253,7 +259,6 @@ If (-not $isAdmin) {
253259
}
254260
10240 {
255261
"Win10TH1_G2.vhdx"
256-
257262
}
258263
10586 {
259264
"Win10TH2_G2.vhdx"

0 commit comments

Comments
 (0)