-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsetup.ps1
More file actions
132 lines (106 loc) · 5.96 KB
/
setup.ps1
File metadata and controls
132 lines (106 loc) · 5.96 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<#
THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT!
This script is based on the logic from the "Amazon EKS Optimized Windows AMI"
EC2 ImageBuilder component, with modifications to use containerd 1.7.0.
The original ImageBuilder component logic is Copyright Amazon.com, Inc. or
its affiliates, and is licensed under the MIT License.
#>
# Halt execution if we encounter an error
$ErrorActionPreference = 'Stop'
# Applies in-place patches to a file
function PatchFile
{
Param (
$File,
$Patches
)
$patched = Get-Content -Path $File -Raw
$Patches.GetEnumerator() | ForEach-Object {
$patched = $patched.Replace($_.Key, $_.Value)
}
Set-Content -Path $File -Value $patched -NoNewline
}
# Constants
$KubernetesPath = "$env:ProgramFiles\Kubernetes"
$KubernetesDownload = "https://amazon-eks.s3.amazonaws.com/1.26.2/2023-03-17/bin/windows/amd64"
$ContainerdPath = "$env:ProgramFiles\containerd"
$EKSPath = "$env:ProgramFiles\Amazon\EKS"
$DomainlessGmsaPath = "$EKSPath\gmsa-plugin"
$CNIPath = "$EKSPath\cni"
$CSIProxyPath = "$EKSPath\bin"
$EKSLogsPath = "$env:ProgramData\Amazon\EKS\logs"
$TempRoot = "C:\TempEKSArtifactDir"
$TempPath = "$TempRoot\EKS-Artifacts"
# Create each of our directories
foreach ($dir in @($ContainerdPath, $KubernetesPath, $EKSPath, $CNIPath, $CSIProxyPath, $EKSLogsPath, $DomainlessGmsaPath, $TempRoot)) {
New-Item -Path $dir -ItemType Directory -Force | Out-Null
}
# Install the NVIDIA GPU drivers
$driverBucket = 'ec2-windows-nvidia-drivers'
$driver = Get-S3Object -BucketName $driverBucket -KeyPrefix 'latest' -Region 'us-east-1' | Where-Object {$_.Key.Contains('server2022')}
Copy-S3Object -BucketName $driverBucket -Key $driver.Key -LocalFile "$TempRoot\driver.exe" -Region 'us-east-1'
Start-Process -FilePath "$TempRoot\driver.exe" -ArgumentList @('-s', '-noreboot') -NoNewWindow -Wait
# Download the Kubernetes components
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile("$KubernetesDownload/kubelet.exe", "$KubernetesPath\kubelet.exe")
$webClient.DownloadFile("$KubernetesDownload/kube-proxy.exe", "$KubernetesPath\kube-proxy.exe")
$webClient.DownloadFile("$KubernetesDownload/aws-iam-authenticator.exe", "$EKSPath\aws-iam-authenticator.exe")
# Download the EKS artifacts archive
$webClient.DownloadFile("https://ec2imagebuilder-managed-resources-us-east-1-prod.s3.amazonaws.com/components/eks-optimized-ami-windows/1.26.0/EKS-Artifacts.zip", "C:\EKS-Artifacts.zip")
# Extract the EKS artifacts archive
Expand-Archive -Path "C:\EKS-Artifacts.zip" -DestinationPath $TempRoot
Remove-Item -Path "C:\EKS-Artifacts.zip" -Force
# Move the EKS files into place
Move-Item -Path "$TempPath\ctr.exe" -Destination "$ContainerdPath\ctr.exe" -Force
Move-Item -Path "$TempPath\containerd.exe" -Destination "$ContainerdPath\containerd.exe" -Force
Move-Item -Path "$TempPath\containerd-shim-runhcs-v1.exe" -Destination "$ContainerdPath\containerd-shim-runhcs-v1.exe" -Force
Move-Item -Path "$TempPath\Start-EKSBootstrap.ps1" -Destination "$EKSPath\Start-EKSBootstrap.ps1" -Force
Move-Item -Path "$TempPath\EKS-StartupTask.ps1" -Destination "$EKSPath\EKS-StartupTask.ps1" -Force
Move-Item -Path "$TempPath\vpc-shared-eni.exe" -Destination "$CNIPath\vpc-shared-eni.exe" -Force
Move-Item -Path "$TempPath\csi-proxy.exe" -Destination "$CSIProxyPath\csi-proxy.exe" -Force
# Install the Windows Containers feature
# (Note: this is actually a no-op here, since we install the feature beforehand in startup.ps1)
Install-WindowsFeature -Name Containers
# -------
# TEMPORARY UNTIL EKS ADDS SUPPORT FOR CONTAINERD v1.7.0:
# Download and extract the containerd 1.7.0 release build
$containerdTarball = "$TempPath\containerd-1.7.0.tar.gz"
$containerdFiles = "$TempPath\containerd-1.7.0"
$webClient.DownloadFile('https://github.com/containerd/containerd/releases/download/v1.7.0/containerd-1.7.0-windows-amd64.tar.gz', $containerdTarball)
New-Item -Path "$containerdFiles" -ItemType Directory -Force | Out-Null
tar.exe -xvzf "$containerdTarball" -C "$containerdFiles"
# Move the containerd files into place
Move-Item -Path "$containerdFiles\bin\containerd.exe" -Destination "$ContainerdPath\containerd.exe" -Force
Move-Item -Path "$containerdFiles\bin\containerd-shim-runhcs-v1.exe" -Destination "$ContainerdPath\containerd-shim-runhcs-v1.exe" -Force
Move-Item -Path "$containerdFiles\bin\ctr.exe" -Destination "$ContainerdPath\ctr.exe" -Force
# Clean up the containerd intermediate files
Remove-Item -Path "$containerdFiles" -Recurse -Force
Remove-Item -Path "$containerdTarball" -Force
# -------
# Patch the containerd setup script to configure a log file (rather than just discarding log output) and to use the upstream pause
# container image rather than the EKS version, since the latter appears to cause errors when attempting to create Windows Pods
PatchFile -File "$TempPath\Add-ContainerdRuntime.ps1" -Patches @{
"containerd --register-service" = "containerd --register-service --log-file 'C:\ProgramData\containerd\root\output.log'";
"amazonaws.com/eks/pause-windows:latest" = "registry.k8s.io/pause:3.9"
}
# Add the full Windows Server 2022 base image and the pause image to the list of images to pre-pull
$baseLayersFile = "$TempPath\eks.baselayers.config"
$baseLayers = Get-Content -Path $baseLayersFile -Raw | ConvertFrom-Json
$baseLayers.2022 += "mcr.microsoft.com/windows/server:ltsc2022"
$baseLayers.2022 += "registry.k8s.io/pause:3.9"
$patchedJson = ConvertTo-Json -Depth 100 -InputObject $baseLayers
Set-Content -Path $baseLayersFile -Value $patchedJson -NoNewline
# Register containerd as the EKS container runtime
Push-Location $TempPath
& .\Add-ContainerdRuntime.ps1 -Path "$ContainerdPath"
Pop-Location
# Perform EKS worker node setup
Push-Location $TempPath
& .\create-windows-pause-image.ps1 -ContainerRuntime containerd
& .\Get-EKSBaseLayers.ps1 -ConfigFile eks.baselayers.config -ContainerRuntime containerd
& .\Add-CSIProxy.ps1 -Path "$CSIProxyPath" -LogPath "$EKSLogsPath"
& .\EKS-WindowsServiceHost.ps1
& .\Install-EKSWorkerNode.ps1
Pop-Location
# Perform cleanup
Remove-Item -Path "$TempRoot" -Recurse -Force