Skip to content
Open
Changes from 1 commit
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
254 changes: 254 additions & 0 deletions automation/Remote.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
function Start-VirtualMachine {
param (
[String]
[ValidateNotNullOrEmpty()]
$VMName,

[String]
[ValidateNotNullOrEmpty()]
$SwitchName,

[String]
[ValidateNotNullOrEmpty()]
$ISOFile
)

New-VM -Name $VMName -Generation 1 -MemoryStartupBytes 6000MB -Path ${env:homepath}\.minikube\machines\ -NewVHDPath ${env:homepath}\.minikube\machines\$VMName\VHD.vhdx -NewVHDSizeBytes 127000MB -SwitchName $SwitchName
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you trying to get with $ENV:Homepath? If the home directory, try using $HOME

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they are the same, but I have not tested. I believe ENV:Homepath is the original way of passing the home folder path in PS, but $Home also exists and points to the same folder. I'm assuming this comes from Linux.

Set-VM -Name $VMName -ProcessorCount 2 -AutomaticCheckpointsEnabled $false
Set-VMProcessor -VMName $VMName -ExposeVirtualizationExtensions $true
Set-VMDvdDrive -VMName $VMName -Path $ISOFile
Start-VM -Name $VMName
}

# $VMName = 'minikube-m03';
# $UserName = 'Administrator';
# $Password = '[email protected]';
function Set-Credential {
param (
[String]
[ValidateNotNullOrEmpty()]
$VMName,

[String]
[ValidateNotNullOrEmpty()]
$UserName,

[String]
[ValidateNotNullOrEmpty()]
$Pass
)

$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force;
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $SecurePassword ;

return $Credential

}

function Install-Containerd {
param(
[string]
[ValidateNotNullOrEmpty()]
[parameter(HelpMessage = "ContainerD version to use. Default 1.7.6")]
$Version = "1.7.6",

[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 = ".\bin\"
)

$Version = $Version.TrimStart('v')
$EnvPath = "$InstallPath\bin"

$containerdTarFile = "containerd-${version}-windows-amd64.tar.gz"
$Uri = "https://github.com/containerd/containerd/releases/download/v$version/$($containerdTarFile)"
$params = @{
Feature = "containerd"
Version = $Version
Uri = $Uri
InstallPath = $InstallPath
DownloadPath = "$DownloadPath\$containerdTarFile"
EnvPath = $EnvPath
cleanup = $true
}

Write-Output "Downloading and installing Containerd at $InstallPath"
Invoke-WebRequest -Uri $Uri -OutFile $DownloadPath\$containerdTarFile -Verbose
Install-RequiredFeature @params

Write-Output "Containerd successfully installed at $InstallPath"
containerd.exe -v

Write-Output "For containerd usage: run 'containerd -h'"
}

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

# 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. $_"
}
}

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

Write-Output "Configuring the containerd service"

#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
# Get-Content $containerdConfigFile
# TODO: Complete the script make the following changes in the .toml file
#
# 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\\"

# Register containerd service
Add-FeatureToPath -Feature "containerd" -Path "$ContainerdPath\bin"
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. $_"
}

Write-Output "Containerd service"
Get-Service *containerd* | Select-Object Name, DisplayName, ServiceName, ServiceType, StartupType, Status, RequiredServices, ServicesDependedOn
}

function Install-NSSM {
param(
[string]
[ValidateNotNullOrEmpty()]
[parameter(HelpMessage = "NSSM version to use. Default 2.24")]
$Version = "2.24",

[String]
[parameter(HelpMessage = "Architecture ")]
$Arch = "win64",

[String]
[parameter(HelpMessage = "Path to download files.")]
$DownloadPath = "c:\k"
)

$Version = $Version.TrimStart('v')

$nssmTarFile = "nssm-${version}.zip"
$Uri = "https://k8stestinfrabinaries.blob.core.windows.net/nssm-mirror/$($nssmTarFile)"
$params = @{
Feature = "nssm"
Version = $Version
Uri = $Uri
InstallPath = $InstallPath
DownloadPath = "$DownloadPath\$containerdTarFile"
EnvPath = $EnvPath
cleanup = $true
}

Write-Output "Downloading and installing Containerd at $InstallPath"
Invoke-WebRequest -Uri $Uri -OutFile $DownloadPath\$containerdTarFile -Verbose
Install-RequiredFeature @params

Write-Output "Containerd successfully installed at $InstallPath"
containerd.exe -v

Write-Output "For containerd usage: run 'containerd -h'"
}


function Install-Kubelet {
param (
[string]
[ValidateNotNullOrEmpty()]
$KubernetesVersion = "v1.27.3"
)

# Define the URL for kubelet download
$KubeletUrl = "https://dl.k8s.io/$KubernetesVersion/bin/windows/amd64/kubelet.exe"

# Download kubelet
Invoke-WebRequest -Uri $KubeletUrl -OutFile "c:\k\kubelet.exe"

# Create the Start-kubelet.ps1 script
@"
`$FileContent = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
`$kubeAdmArgs = `$FileContent.TrimStart(`'KUBELET_KUBEADM_ARGS=`').Trim(`'"`')

`$args = "--cert-dir=`$env:SYSTEMDRIVE/var/lib/kubelet/pki",
"--config=`$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml",
"--bootstrap-kubeconfig=`$env:SYSTEMDRIVE/etc/kubernetes/bootstrap-kubelet.conf",
"--kubeconfig=`$env:SYSTEMDRIVE/etc/kubernetes/kubelet.conf",
"--hostname-override=`$(hostname)",
"--enable-debugging-handlers",
"--cgroups-per-qos=false",
"--enforce-node-allocatable=``"``"",
"--resolv-conf=``"``""

`$kubeletCommandLine = "c:\k\kubelet.exe " + (`$args -join " ") + " `$kubeAdmArgs"
Invoke-Expression `$kubeletCommandLine
"@ | Set-Content -Path "c:\k\Start-kubelet.ps1"

# Install kubelet as a Windows service
"c:\k\nssm.exe install kubelet Powershell -ExecutionPolicy Bypass -NoProfile c:\k\Start-kubelet.ps1"
"c:\k\nssm.exe set Kubelet AppStdout C:\k\kubelet.log"
"c:\k\nssm.exe set Kubelet AppStderr C:\k\kubelet.err.log"
}


# Example usage: Install-Kubelet -KubernetesVersion "v1.27.3"


function Enable-FireWall-Ports {
New-NetFirewallRule -Name kubelet -DisplayName 'kubelet' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 10250

}


function Start-RemoteSession {
param (
[String]
[ValidateNotNullOrEmpty()]
$VMName,

[PSCredential]
[ValidateNotNullOrEmpty()]
$Credential
)

Enter-PSSession -VMName $VMName -Credential $Credential;
}

function Remove-VirtualMachine {
param (
[String]
[ValidateNotNullOrEmpty()]
$VMName
)

Stop-VM -Name $VMName -TurnOff
Remove-VM -Name $VMName -Force
Remove-Item -Path ${env:homepath}\.minikube\machines\$VMName -Force -Recurse

}