Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8cf8257
initial commit
bobsira Oct 12, 2023
8a1ce2a
intial refactoring and seperation of concerns
bobsira Oct 24, 2023
5b3e54a
more updates on the set up scripts
bobsira Oct 31, 2023
b72ec33
more updates to the automation scripts
bobsira Nov 8, 2023
18efcf9
fixes to containerd installation
bobsira Nov 13, 2023
226cc32
changes to VM specification
bobsira Nov 13, 2023
3a48a66
response content cannot be parsed because the Internet Explorer engi…
bobsira Nov 15, 2023
33456f5
fix to containerd start service command
bobsira Nov 18, 2023
12c5727
logical change to replacement of toml conf file
bobsira Nov 19, 2023
fbd7f38
error handling additions
bobsira Nov 19, 2023
3dbc715
updates to NSSM install
bobsira Nov 20, 2023
aec2483
uninstall containerd logic
bobsira Nov 29, 2023
8c9f3d7
added stop containerd serv
bobsira Nov 29, 2023
4b21c83
changes to import statement
bobsira Nov 29, 2023
949cf74
restructed file imports
bobsira Nov 29, 2023
a3488cd
fix for Uninstall-ContainerTool
bobsira Dec 7, 2023
2f71d71
removed containerd uninstalll logic
bobsira Dec 8, 2023
3ba1538
script tp execute the process
bobsira Dec 8, 2023
6c0e96e
fix on parent directory reference
bobsira Dec 8, 2023
4936277
added the missing session declaration
bobsira Dec 8, 2023
1c1900f
changes to flow of execution
Dec 11, 2023
9f16dde
removed unwanted definition
bobsira Dec 11, 2023
85426d6
nssm service check
bobsira Dec 12, 2023
d50cc1e
more error handling code
Dec 12, 2023
c508c38
folder creation error handling
Dec 13, 2023
a4c14e2
fix initialize containerd logic
Dec 14, 2023
9ed7350
indentation fix in hosts file
Dec 14, 2023
f8ff45e
phase one remoting complete
Jan 3, 2024
29505da
containerd setup modification
bobsira Jan 15, 2024
af70e9a
feedback on remote work
bobsira Jan 15, 2024
7f57213
intial authoring of auto install file
Jan 25, 2024
d291652
BIOS/MBR-Based Hard Disk answer file
Jan 30, 2024
7ae051c
setup file to test the configuration
Jan 31, 2024
58c3230
updates for testing
Jan 31, 2024
5306cf7
add auto-unattend iso file
iankingori Feb 1, 2024
c758048
flannel and kube-proxy networking config addition@
bobsira Feb 2, 2024
6109743
Merge pull request #1 from iankingori/bob/iso-setup
bobsira Feb 4, 2024
80d31ee
Merge branch 'vrapolinario:main' into user/bosira/autounattended-wind…
bobsira Feb 4, 2024
1ffcce4
changed from yml to recommended yaml extension
bobsira Feb 4, 2024
b4aae2e
generic computer name
Feb 5, 2024
4aa93e9
computer name changes
Feb 5, 2024
a2e9063
configuring linux nodes
bobsira Feb 5, 2024
cd16c12
better logging to the console
bobsira Feb 6, 2024
956beaf
fixing broken changes
bobsira Feb 6, 2024
aafc3c9
Merge branch 'user/bosira/autounattended-windows-install' of https://…
bobsira Feb 12, 2024
936eb03
draft changes to merge remote and auto-install work
Feb 20, 2024
2411d0e
initial setup to combine the two work
Mar 5, 2024
81a2cd4
final setup to merge auto-install and remote config
Mar 11, 2024
59a7270
final changes, kalkikubes
Mar 11, 2024
e6fbbed
final polish
Mar 19, 2024
62e42bf
added SSH setup during auto-install
bobsira Sep 21, 2024
2fa904f
bundled the new xml answer file into an iso
bobsira Sep 21, 2024
ed08391
fixed the path mismatch value
bobsira Sep 21, 2024
e3beabb
swapped the SSH configuration ordering
bobsira Sep 23, 2024
8398aef
OpenSSH installation in the VM
bobsira Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ You will need to append the IP address of the master node to the Hosts file on t
> You can find the IP address of the master Linux node by running the following command on your machine:
>
>```powershell
>minikube node list
>minikube ip
>```

Your hosts file should look similar to this:
Expand Down
Binary file added auto-install.iso
Binary file not shown.
257 changes: 257 additions & 0 deletions automation/ContainerdTools.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
Import-Module -Name "$PSScriptRoot\SetUpUtilities.psm1" -Force

function Get-ContainerdLatestVersion {
$latestVersion = Get-LatestToolVersion -Repository "containerd/containerd"
return $latestVersion
}

function Install-Containerd {
param(
[String]
[parameter(HelpMessage = "Path to install containerd. Defaults to ~\program files\containerd")]
$InstallPath = "$Env:ProgramFiles\containerd",

[String]
[parameter(HelpMessage = "Path to download files. Defaults to user's Downloads folder")]
$DownloadPath = "$HOME\Downloads"
)

# Uninstall if tool exists at specified location. Requires user consent
Uninstall-ContainerTool -Tool "ContainerD" -Path $InstallPath

$Version = Get-ContainerdLatestVersion

$Version = $Version.TrimStart('v')
Write-Output "* Downloading and installing Containerd v$version at $InstallPath"
"Downloading and installing Containerd v$version at $InstallPath" >> logs


# Download file from repo
$containerdTarFile = "containerd-${version}-windows-amd64.tar.gz"
try {
$Uri = "https://github.com/containerd/containerd/releases/download/v$version/$($containerdTarFile)"
Invoke-WebRequest -Uri $Uri -OutFile $DownloadPath\$containerdTarFile | Out-Null
}
catch {
Throw "Containerd download failed. $_"
}


# Untar and install tool
$params = @{
Feature = "containerd"
InstallPath = $InstallPath
DownloadPath = "$DownloadPath\$containerdTarFile"
EnvPath = "$InstallPath\bin"
cleanup = $true
}


Install-RequiredFeature @params | Out-Null

Write-Output "* Containerd v$version successfully installed at $InstallPath"
"Containerd v$version successfully installed at $InstallPath" >> logs
containerd.exe -v >> logs

"For containerd usage: run 'containerd -h'" >> logs
}

function Start-ContainerdService {
Set-Service containerd -StartupType Automatic
try {
Start-Service containerd

# Waiting for containerd to come to steady state
(Get-Service containerd -ErrorAction SilentlyContinue).WaitForStatus('Running', '00:00:30')
}
catch {
Throw "Couldn't start Containerd service. $_"
}

Write-Output "* Containerd is installed and the service is started ..."
"Containerd is installed and the service is started" >> logs

}

function Stop-ContainerdService {
$containerdStatus = Get-Service containerd -ErrorAction SilentlyContinue
if (!$containerdStatus) {
Write-Warning "Containerd service does not exist as an installed service."
"Containerd service does not exist as an installed service." >> logs
return
}

try {
Stop-Service containerd -NoWait

# Waiting for containerd to come to steady state
(Get-Service containerd -ErrorAction SilentlyContinue).WaitForStatus('Stopped', '00:00:30')
}
catch {
Throw "Couldn't stop Containerd service. $_"
}
}

function Initialize-ContainerdService {
param(
[string]
[parameter(HelpMessage = "Containerd path")]
$ContainerdPath = "$Env:ProgramFiles\containerd"
)

"Configuring the containerd service" >> logs

#Configure containerd service
$containerdConfigFile = "$ContainerdPath\config.toml"
$containerdDefault = containerd.exe config default
$containerdDefault | Out-File $ContainerdPath\config.toml -Encoding ascii
Write-Information -InformationAction Continue -MessageData "* Review containerd configutations at $containerdConfigFile ..."

Add-MpPreference -ExclusionProcess "$ContainerdPath\containerd.exe"

# Review the configuration. Depending on setup you may want to adjust:
# - the sandbox_image (Kubernetes pause image)
# - cni bin_dir and conf_dir locations


# Setting Old value New Value
# bin_dir "C:\\Program Files\\containerd\\cni\\bin" "c:\\opt\\cni\\bin"
# conf_dir "C:\\Program Files\\containerd\\cni\\conf" "c:\\etc\\cni\\net.d\\"

# Read the content of the config.toml file
$containerdConfigContent = Get-Content -Path $containerdConfigFile -Raw

# Define the replacements
$replacements = @(
@{
Find = 'bin_dir = "C:\\Program Files\\containerd\\cni\\bin"'
Replace = 'bin_dir = "c:\\opt\\cni\\bin"'
},
@{
Find = 'conf_dir = "C:\\Program Files\\containerd\\cni\\conf"'
Replace = 'conf_dir = "c:\\etc\\cni\\net.d\\"'
}
)

# Perform the check and replacement in one loop
$replacementsMade = $false
foreach($replacement in $replacements) {
if ($containerdConfigContent -match [regex]::Escape($replacement.Find)) {
$containerdConfigContent = $containerdConfigContent -replace [regex]::Escape($replacement.Find), $replacement.Replace
$replacementsMade = $true
}
}

# Write the modified content back to the config.toml file if any replacements were made
if ($replacementsMade) {
$containerdConfigContent | Set-Content -Path $containerdConfigFile
# Output a message indicating the changes
# Write-Host "Changes applied to $containerdConfigFile"
} else {
# Write-Host "No changes needed in $containerdConfigFile"
}

# Create the folders if they do not exist
$binDir = "c:\opt\cni\bin"
$confDir = "c:\etc\cni\net.d"

if (!(Test-Path $binDir)) {
mkdir $binDir | Out-Null
# Write-Host "Created $binDir"
}

if (!(Test-Path $confDir)) {
mkdir $confDir | Out-Null
# Write-Host "Created $confDir"
}


$pathExists = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine) -like "*$ContainerdPath\bin*"
if (-not $pathExists) {
# Register containerd service
Add-FeatureToPath -Feature "containerd" -Path "$ContainerdPath\bin"
}

# Check if the containerd service is already registered
$containerdServiceExists = Get-Service -Name "containerd" -ErrorAction SilentlyContinue
if (-not $containerdServiceExists) {
containerd.exe --register-service --log-level debug --service-name containerd --log-file "$env:TEMP\containerd.log"
if ($LASTEXITCODE -gt 0) {
Throw "Failed to register containerd service. $_"
}
} else {
Write-Host "Containerd service is already registered."
}

Get-Service *containerd* | Select-Object Name, DisplayName, ServiceName, ServiceType, StartupType, Status, RequiredServices, ServicesDependedOn | Out-Null
}

function Uninstall-Containerd {
param(
[string]
[parameter(HelpMessage = "Containerd path")]
$Path
)
Write-Output "Uninstalling containerd"

if (!$Path) {
$Path = Get-DefaultInstallPath -Tool "containerd"
}

$pathItems = Get-ChildItem -Path $Path -ErrorAction SilentlyContinue
if (!$pathItems.Name.Length) {
Write-Warning "Containerd does not exist at $Path or the directory is empty"
return
}

try {
Stop-ContainerdService
}
catch {
Write-Warning "$_"
}

# Unregister containerd service
Unregister-Containerd

# Delete the containerd key
$regkey = "HKLM:\SYSTEM\CurrentControlSet\Services\containerd"
Get-Item -path $regkey -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force

# Remove the folder where containerd service was installed
Get-Item -Path $Path -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force

# Remove from env path
Remove-FeatureFromPath -Feature "containerd"

Write-Output "Successfully uninstalled Containerd."
}
function Unregister-Containerd {
$scQueryResult = (sc.exe query containerd) | Select-String -Pattern "SERVICE_NAME: containerd"
if (!$scQueryResult) {
Write-Warning "Containerd service does not exist as an installed service."
return
}
# Unregister containerd service
containerd.exe --unregister-service
if ($LASTEXITCODE -gt 0) {
Write-Warning "Could not unregister containerd service. $_"
}
else {
Start-Sleep -Seconds 15
}

# # Delete containerd service
# sc.exe delete containerd
# if ($LASTEXITCODE -gt 0) {
# Write-Warning "Could not delete containerd service. $_"
# }
}


Export-ModuleMember -Function Get-ContainerdLatestVersion
Export-ModuleMember -Function Install-Containerd
Export-ModuleMember -Function Start-ContainerdService
Export-ModuleMember -Function Stop-ContainerdService -Alias Stop-Containerd
Export-ModuleMember -Function Initialize-ContainerdService
Export-ModuleMember -Function Uninstall-Containerd
49 changes: 49 additions & 0 deletions automation/MinikubeTools.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Import-Module -Name "$PSScriptRoot\k8Tools.psm1" -Force

function Get-JoinCommand {
param (
[string]
$KubernetesVersion
)
$JoinCommand = (minikube ssh "cd /var/lib/minikube/binaries/v$KubernetesVersion/ && sudo ./kubeadm token create --print-join-command")
$outputString = $JoinCommand -replace 'kubeadm', '.\kubeadm.exe'
$outputString += ' --cri-socket "npipe:////./pipe/containerd-containerd"'
$outputString += ' --v=5'
return $outputString

}

function Set-MinikubeFolderError {
if (!(Test-Path -Path c:\var\lib\minikube\certs)) {
mkdir c:\var\lib\minikube\certs | Out-Null
}

if (Test-Path -Path C:\etc\kubernetes\pki\ca.crt) {
Copy-Item C:\etc\kubernetes\pki\ca.crt -Destination C:\var\lib\Minikube\Certs | Out-Null
Remove-Item C:\etc\kubernetes\pki\ca.crt | Out-Null
} else {
Write-Output "File C:\etc\kubernetes\pki\ca.crt does not exist."
}
}

function Add-Host {
param (
[string]
[ValidateNotNullOrEmpty()]
$IP,
[string]
[ValidateNotNullOrEmpty()]
$Path = "C:\Windows\System32\drivers\etc\hosts"
)

$entry = "`t$IP`tcontrol-plane.minikube.internal"

$hostsContent = Get-Content -Path $Path -Raw -ErrorAction SilentlyContinue
if ($hostsContent -notmatch [regex]::Escape($entry)) {
Add-Content -Path $Path -Value "$entry" -Force | Out-Null
}
}

Export-ModuleMember -Function Get-JoinCommand
Export-ModuleMember -Function Set-MinikubeFolderError
Export-ModuleMember -Function Add-Host
25 changes: 25 additions & 0 deletions automation/NSSMTools.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function Install-NSSM {
$nssmService = Get-WmiObject win32_service | Where-Object {$_.PathName -like '*nssm*'}
if ($nssmService) {
Write-Output "NSSM is already installed."
return
}

if (-not (Test-Path -Path "c:\k" -PathType Container)) {
mkdir "c:\k" | Out-Null
}
$arch = "win64"
$nssmZipFile = "nssm-2.24.zip"
$nssmUri = "https://k8stestinfrabinaries.blob.core.windows.net/nssm-mirror/$nssmZipFile"
try {
Invoke-WebRequest -Uri $nssmUri -OutFile "c:\k\$nssmZipFile" | Out-Null
}
catch {
Throw "NSSM download failed. $_"
}
tar.exe C c:\k\ -xf "c:\k\$nssmZipFile" --strip-components 2 */$arch/*.exe | Out-Null

Write-Output "* NSSM is installed ..."
}

Export-ModuleMember -Function Install-NSSM
Loading