This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 558
/
kuberneteswindowssetup.ps1
266 lines (215 loc) · 11 KB
/
kuberneteswindowssetup.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<#
.SYNOPSIS
Provisions VM as a Kubernetes agent.
.DESCRIPTION
Provisions VM as a Kubernetes agent.
The parameters passed in are required, and will vary per-deployment.
Notes on modifying this file:
- This file extension is PS1, but it is actually used as a template from pkg/acsengine/template_generator.go
- All of the lines that have braces in them will be modified. Please do not change them here, change them in the Go sources
- Single quotes are forbidden, they are reserved to delineate the different members for the ARM template concat() call
#>
[CmdletBinding(DefaultParameterSetName="Standard")]
param(
[string]
[ValidateNotNullOrEmpty()]
$MasterIP,
[parameter()]
[ValidateNotNullOrEmpty()]
$KubeDnsServiceIp,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$MasterFQDNPrefix,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Location,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$AgentKey,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$AADClientId,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$AADClientSecret
)
# These globals will not change between nodes in the same cluster, so they are not
# passed as powershell parameters
## Certificates generated by acs-engine
$global:CACertificate = "{{WrapAsParameter "caCertificate"}}"
$global:AgentCertificate = "{{WrapAsParameter "clientCertificate"}}"
## Download sources provided by acs-engine
$global:KubeBinariesPackageSASURL = "{{WrapAsParameter "kubeBinariesSASURL"}}"
$global:WindowsKubeBinariesURL = "{{WrapAsParameter "windowsKubeBinariesURL"}}"
$global:KubeBinariesVersion = "{{WrapAsParameter "kubeBinariesVersion"}}"
## Docker Version
$global:DockerVersion = "{{WrapAsParameter "windowsDockerVersion"}}"
## VM configuration passed by Azure
$global:WindowsTelemetryGUID = "{{WrapAsParameter "windowsTelemetryGUID"}}"
$global:TenantId = "{{WrapAsVariable "tenantID"}}"
$global:SubscriptionId = "{{WrapAsVariable "subscriptionId"}}"
$global:ResourceGroup = "{{WrapAsVariable "resourceGroup"}}"
$global:VmType = "{{WrapAsVariable "vmType"}}"
$global:SubnetName = "{{WrapAsVariable "subnetName"}}"
$global:MasterSubnet = "{{WrapAsParameter "masterSubnet"}}"
$global:SecurityGroupName = "{{WrapAsVariable "nsgName"}}"
$global:VNetName = "{{WrapAsVariable "virtualNetworkName"}}"
$global:RouteTableName = "{{WrapAsVariable "routeTableName"}}"
$global:PrimaryAvailabilitySetName = "{{WrapAsVariable "primaryAvailabilitySetName"}}"
$global:PrimaryScaleSetName = "{{WrapAsVariable "primaryScaleSetName"}}"
$global:KubeClusterCIDR = "{{WrapAsParameter "kubeClusterCidr"}}"
$global:KubeServiceCIDR = "{{WrapAsParameter "kubeServiceCidr"}}"
$global:KubeletNodeLabels = "{{GetAgentKubernetesLabels . "',variables('labelResourceGroup'),'"}}"
$global:KubeletConfigArgs = @( {{GetKubeletConfigKeyValsPsh .KubernetesConfig }} )
$global:UseManagedIdentityExtension = "{{WrapAsVariable "useManagedIdentityExtension"}}"
$global:UserAssignedClientID = "{{WrapAsVariable "userAssignedClientID"}}"
$global:UseInstanceMetadata = "{{WrapAsVariable "useInstanceMetadata"}}"
$global:LoadBalancerSku = "{{WrapAsVariable "loadBalancerSku"}}"
$global:ExcludeMasterFromStandardLB = "{{WrapAsVariable "excludeMasterFromStandardLB"}}"
# Windows defaults, not changed by acs-engine
$global:KubeDir = "c:\k"
$global:HNSModule = [Io.path]::Combine("$global:KubeDir", "hns.psm1")
$global:KubeDnsSearchPath = "svc.cluster.local"
$global:CNIPath = [Io.path]::Combine("$global:KubeDir", "cni")
$global:NetworkMode = "L2Bridge"
$global:CNIConfig = [Io.path]::Combine($global:CNIPath, "config", "`$global:NetworkMode.conf")
$global:CNIConfigPath = [Io.path]::Combine("$global:CNIPath", "config")
$global:AzureCNIDir = [Io.path]::Combine("$global:KubeDir", "azurecni")
$global:AzureCNIBinDir = [Io.path]::Combine("$global:AzureCNIDir", "bin")
$global:AzureCNIConfDir = [Io.path]::Combine("$global:AzureCNIDir", "netconf")
# Azure cni configuration
# $global:NetworkPolicy = "{{WrapAsParameter "networkPolicy"}}" # BUG: unused
$global:NetworkPlugin = "{{WrapAsParameter "networkPlugin"}}"
$global:VNetCNIPluginsURL = "{{WrapAsParameter "vnetCniWindowsPluginsURL"}}"
# Base64 representation of ZIP archive
$zippedFiles = "{{ GetKubernetesWindowsAgentFunctions }}"
# Extract ZIP from script
[io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles))
Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\"
# Dot-source contents of zip. This should match the list in template_generator.go GetKubernetesWindowsAgentFunctions
. c:\AzureData\k8s\kuberneteswindowsfunctions.ps1
. c:\AzureData\k8s\windowsconfigfunc.ps1
. c:\AzureData\k8s\windowskubeletfunc.ps1
. c:\AzureData\k8s\windowscnifunc.ps1
. c:\AzureData\k8s\windowsazurecnifunc.ps1
function
Update-ServiceFailureActions()
{
sc.exe failure "kubelet" actions= restart/60000/restart/60000/restart/60000 reset= 900
sc.exe failure "kubeproxy" actions= restart/60000/restart/60000/restart/60000 reset= 900
sc.exe failure "docker" actions= restart/60000/restart/60000/restart/60000 reset= 900
}
try
{
# Set to false for debugging. This will output the start script to
# c:\AzureData\CustomDataSetupScript.log, and then you can RDP
# to the windows machine, and run the script manually to watch
# the output.
if ($true) {
Write-Log "Provisioning $global:DockerServiceName... with IP $MasterIP"
Write-Log "Apply telemetry data setting"
Set-TelemetrySetting -WindowsTelemetryGUID $global:WindowsTelemetryGUID
Write-Log "Resize os drive if possible"
Resize-OSDrive
Write-Log "Create required data directories as needed"
Initialize-DataDirectories
Write-Log "Install docker"
Install-Docker -DockerVersion $global:DockerVersion
Write-Log "Download kubelet binaries and unzip"
Get-KubePackage -KubeBinariesSASURL $global:KubeBinariesPackageSASURL
# this overwrite the binaries that are download from the custom packge with binaries
# The custom package has a few files that are nessary for future steps (nssm.exe)
# this is a temporary work around to get the binaries until we depreciate
# custom package and nssm.exe as defined in #3851.
if ($global:WindowsKubeBinariesURL){
Write-Log "Overwriting kube node binaries from $global:WindowsKubeBinariesURL"
Get-KubeBinaries -KubeBinariesURL $global:WindowsKubeBinariesURL
}
Write-Log "Write Azure cloud provider config"
Write-AzureConfig `
-KubeDir $global:KubeDir `
-AADClientId $AADClientId `
-AADClientSecret $AADClientSecret `
-TenantId $global:TenantId `
-SubscriptionId $global:SubscriptionId `
-ResourceGroup $global:ResourceGroup `
-Location $Location `
-VmType $global:VmType `
-SubnetName $global:SubnetName `
-SecurityGroupName $global:SecurityGroupName `
-VNetName $global:VNetName `
-RouteTableName $global:RouteTableName `
-PrimaryAvailabilitySetName $global:PrimaryAvailabilitySetName `
-PrimaryScaleSetName $global:PrimaryScaleSetName `
-UseManagedIdentityExtension $global:UseManagedIdentityExtension `
-UserAssignedClientID $global:UserAssignedClientID `
-UseInstanceMetadata $global:UseInstanceMetadata `
-LoadBalancerSku $global:LoadBalancerSku `
-ExcludeMasterFromStandardLB $global:ExcludeMasterFromStandardLB
Write-Log "Write ca root"
Write-CACert -CACertificate $global:CACertificate `
-KubeDir $global:KubeDir
Write-Log "Write kube config"
Write-KubeConfig -CACertificate $global:CACertificate `
-KubeDir $global:KubeDir `
-MasterFQDNPrefix $MasterFQDNPrefix `
-MasterIP $MasterIP `
-AgentKey $AgentKey `
-AgentCertificate $global:AgentCertificate
Write-Log "Create the Pause Container kubletwin/pause"
New-InfraContainer -KubeDir $global:KubeDir
Write-Log "Configuring networking with NetworkPlugin:$global:NetworkPlugin"
# Configure network policy.
if ($global:NetworkPlugin -eq "azure") {
Install-VnetPlugins -AzureCNIConfDir $global:AzureCNIConfDir `
-AzureCNIBinDir $global:AzureCNIBinDir `
-VNetCNIPluginsURL $global:VNetCNIPluginsURL
Set-AzureCNIConfig -AzureCNIConfDir $global:AzureCNIConfDir `
-KubeDnsSearchPath $global:KubeDnsSearchPath `
-KubeClusterCIDR $global:KubeClusterCIDR `
-MasterSubnet $global:MasterSubnet `
-KubeServiceCIDR $global:KubeServiceCIDR
} elseif ($global:NetworkPlugin -eq "kubenet") {
Update-WinCNI -CNIPath $global:CNIPath
Get-HnsPsm1 -HNSModule $global:HNSModule
}
Write-Log "Write kubelet startfile with pod CIDR of $podCIDR"
Install-KubernetesServices `
-KubeletConfigArgs $global:KubeletConfigArgs `
-KubeBinariesVersion $global:KubeBinariesVersion `
-NetworkPlugin $global:NetworkPlugin `
-NetworkMode $global:NetworkMode `
-KubeDir $global:KubeDir `
-AzureCNIBinDir $global:AzureCNIBinDir `
-AzureCNIConfDir $global:AzureCNIConfDir `
-CNIPath $global:CNIPath `
-CNIConfig $global:CNIConfig `
-CNIConfigPath $global:CNIConfigPath `
-MasterIP $MasterIP `
-KubeDnsServiceIp $KubeDnsServiceIp `
-MasterSubnet $global:MasterSubnet `
-KubeClusterCIDR $global:KubeClusterCIDR `
-KubeServiceCIDR $global:KubeServiceCIDR `
-HNSModule $global:HNSModule `
-KubeletNodeLabels $global:KubeletNodeLabels
Write-Log "Disable Internet Explorer compat mode and set homepage"
Set-Explorer
Write-Log "Adjust pagefile size"
Adjust-PageFileSize
Write-Log "Start preProvisioning script"
PREPROVISION_EXTENSION
Write-Log "Update service failure actions"
Update-ServiceFailureActions
Write-Log "Setup Complete, reboot computer"
Restart-Computer
}
else
{
# keep for debugging purposes
Write-Log ".\CustomDataSetupScript.ps1 -MasterIP $MasterIP -KubeDnsServiceIp $KubeDnsServiceIp -MasterFQDNPrefix $MasterFQDNPrefix -Location $Location -AgentKey $AgentKey -AADClientId $AADClientId -AADClientSecret $AADClientSecret"
}
}
catch
{
Write-Error $_
}