-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path2.CreateAKS.ps1
More file actions
73 lines (60 loc) · 2.46 KB
/
2.CreateAKS.ps1
File metadata and controls
73 lines (60 loc) · 2.46 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
param(
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$Region = 'westeurope',
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$ResourceGroup = 'Symposium2020',
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$AksName = 'Symposium2020',
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$AcrName = 'Symposium2020',
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$AzureWindowsPassword="Password!12345"
)
# Setup CLI & Parameters for AKS creation
Write-Host "--- Setting up CLI & Params ---" -ForegroundColor Blue
$aksVersion = "1.17.11" #$(az aks get-versions -l $Region --query 'orchestrators[-1].orchestratorVersion' -o tsv)
Write-Host "--- Complete: CLI & Params Configured ---" -ForegroundColor Green
# create AKS instance
Write-Host "--- Creating AKS Instance K8s version $aksVersion ---" -ForegroundColor Blue
az aks create --resource-group $ResourceGroup `
--name $AksName `
--kubernetes-version $aksVersion `
--location $Region `
--windows-admin-password $AzureWindowsPassword `
--windows-admin-username azureuser `
--vm-set-type VirtualMachineScaleSets `
--node-count 2 `
--generate-ssh-keys `
--network-plugin azure `
--enable-addons monitoring `
--nodepool-name 'linux'
Write-Host "--- Complete: AKS Created ---" -ForegroundColor Green
# link AKS to ACR
Write-Host "--- Linking AKS to ACR ---" -ForegroundColor Blue
$clientID = $(az aks show --resource-group $ResourceGroup --name $AksName --query "servicePrincipalProfile.clientId" --output tsv)
$acrId = $(az acr show --name $AcrName --resource-group $ResourceGroup --query "id" --output tsv)
az role assignment create --assignee $clientID `
--role acrpull `
--scope $acrId
Write-Host "--- Complete: AKS & ACR Linked ---" -ForegroundColor Green
# Add windows server nodepool
Write-Host "--- Creating Windows Server Node Pool ---" -ForegroundColor Blue
az aks nodepool add --resource-group $ResourceGroup `
--cluster-name $AksName `
--os-type Windows `
--name win `
--node-vm-size Standard_D8s_v3 `
--node-count 1
Write-Host "--- Complete: Windows Server Node Pool Created ---" -ForegroundColor Green
# authenticate AKS instance
Write-Host "--- Authenticate with AKS ---" -ForegroundColor Blue
az aks get-credentials -a `
--resource-group $ResourceGroup `
--name $AksName `
--overwrite-existing
Write-Host "--- Complete: Windows Server Node Pool Created ---" -ForegroundColor Green