ChaGPT added lab simulations
This commit is contained in:
45
lab-environment/02-install-and-build.ps1
Normal file
45
lab-environment/02-install-and-build.ps1
Normal file
@@ -0,0 +1,45 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$distribution = 'Ubuntu-24.04'
|
||||
|
||||
function Test-Distribution {
|
||||
$names = @(& wsl.exe --list --quiet 2>$null) | ForEach-Object { $_.Trim("`0 ") }
|
||||
return $names -contains $distribution
|
||||
}
|
||||
|
||||
if (-not (Test-Distribution)) {
|
||||
Write-Host "Installing $distribution..."
|
||||
& wsl.exe --install --web-download --distribution $distribution --no-launch
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw 'Ubuntu installation failed. Confirm Windows was restarted after running 01-enable-wsl.ps1.'
|
||||
}
|
||||
}
|
||||
|
||||
& wsl.exe --set-default-version 2
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not set WSL2 as the default.' }
|
||||
|
||||
# Starting as root avoids an interactive Unix-user prompt in this disposable VM.
|
||||
& wsl.exe --distribution $distribution --user root --exec /bin/true
|
||||
if ($LASTEXITCODE -ne 0) { throw "$distribution did not initialize correctly." }
|
||||
|
||||
$linuxDirectory = (& wsl.exe --distribution $distribution --user root --exec wslpath -a $PSScriptRoot).Trim()
|
||||
if (-not $linuxDirectory) { throw 'Could not translate the lab path into WSL.' }
|
||||
|
||||
Write-Host 'Installing pinned lab tools...'
|
||||
& wsl.exe --distribution $distribution --user root --exec bash "$linuxDirectory/bootstrap.sh"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Linux tool bootstrap failed.' }
|
||||
|
||||
# Reload WSL so systemd and Docker use the newly written WSL configuration.
|
||||
& wsl.exe --shutdown
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
Write-Host 'Creating the isolated Kubernetes cluster...'
|
||||
& wsl.exe --distribution $distribution --user root --exec bash "$linuxDirectory/create-lab.sh" "$linuxDirectory/kind-v1.34.yaml"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Cluster creation failed.' }
|
||||
|
||||
& wsl.exe --distribution $distribution --user root --exec bash "$linuxDirectory/verify-lab.sh"
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Lab verification failed.' }
|
||||
|
||||
Write-Host ''
|
||||
Write-Host 'CKS lab is ready. Enter it with:'
|
||||
Write-Host ' .\enter-lab.ps1'
|
||||
|
||||
Reference in New Issue
Block a user