-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install-Containerd.ps1
90 lines (72 loc) · 3.1 KB
/
Install-Containerd.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<#
.SYNOPSIS
Installs ContainerD on a Windows machines in preperation for joining the node to a Kubernetes cluster.
.DESCRIPTION
This script
- Verifies that Windows Features requried for running contianers are enabled (and enables then if they are not)
- Downloads ContainerD binaries from from at the version specified.
- Downloads Windows SND CNI plugins.
- Registers ContainerD as a windows service.
.PARAMETER ContainerDVersion
ContainerD version to download and use.
.PARAMETER netAdapterName
Name of network adapter to use when configuring basic nat network.
.EXAMPLE
PS> .\Install-Conatinerd.ps1
#>
Param(
[parameter(HelpMessage = "ContainerD version to use")]
[string] $ContainerDVersion = "1.6.8",
[parameter(HelpMessage = "Name of network adapter to use when configuring basic nat network")]
[string] $netAdapterName = "Ethernet"
)
$ErrorActionPreference = 'Stop'
function DownloadFile($destination, $source) {
Write-Host("Downloading $source to $destination")
curl.exe --silent --fail -Lo $destination $source
if (!$?) {
Write-Error "Download $source failed"
exit 1
}
}
$requiredWindowsFeatures = @(
"Containers")
# "Hyper-V",
# "Hyper-V-PowerShell")
function ValidateWindowsFeatures {
$allFeaturesInstalled = $true
foreach ($feature in $requiredWindowsFeatures) {
$f = Get-WindowsFeature -Name $feature
if (-not $f.Installed) {
Write-Warning "Windows feature: '$feature' is not installed."
$allFeaturesInstalled = $false
}
}
return $allFeaturesInstalled
}
if (-not (ValidateWindowsFeatures)) {
Write-Output "Installing required windows features..."
foreach ($feature in $requiredWindowsFeatures) {
Install-WindowsFeature -Name $feature
}
Write-Output "Please reboot and re-run this script."
exit 0
}
Write-Output "Getting ContainerD binaries"
$global:ConainterDPath = "$env:ProgramFiles\containerd"
mkdir -Force $global:ConainterDPath | Out-Null
DownloadFile "$global:ConainterDPath\containerd.tar.gz" https://github.com/containerd/containerd/releases/download/v${ContainerDVersion}/containerd-${ContainerDVersion}-windows-amd64.tar.gz
tar.exe -xvf "$global:ConainterDPath\containerd.tar.gz" --strip=1 -C $global:ConainterDPath
$env:Path += ";$global:ConainterDPath"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
containerd.exe config default | Out-File "$global:ConainterDPath\config.toml" -Encoding ascii
#config file fixups
$config = Get-Content "$global:ConainterDPath\config.toml"
$config = $config -replace "bin_dir = (.)*$", "bin_dir = `"c:/opt/cni/bin`""
$config = $config -replace "conf_dir = (.)*$", "conf_dir = `"c:/etc/cni/net.d`""
$config | Set-Content "$global:ConainterDPath\config.toml" -Force
Write-Output "Registering ContainerD as a service"
containerd.exe --register-service
Write-Output "Starting ContainerD service"
Start-Service containerd
Write-Output "Done - please remember to add '--cri-socket `"npipe:////./pipe/containerd-containerd`"' to your kubeadm join command if your kubernetes version is below 1.25!"