Skip to content

Commit d6d929b

Browse files
authored
Install.ps1 file for LCA workaround
This file can be used to provision the minimal resources for the lab. This is a workaround as the LCA issue has not been resolved.
1 parent 9434f4f commit d6d929b

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

src/install.ps1

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
$resourceGroup = 'PreDayRG'
2+
$location = '@lab.CloudResourceGroup(ResourceGroup1).Location'
3+
$acrName = '[email protected]'
4+
$aksName = 'predaycluster'
5+
$nodepoolName = 'labpool'
6+
$accountName = '[email protected]'
7+
$databaseName = 'productsdb'
8+
$productContainer = 'productscontainer'
9+
$ordersContainer = 'orderscontainer'
10+
$namespaceName = '[email protected]'
11+
$queueName = 'productsqueue'
12+
$keyVaultName = '[email protected]'
13+
$openaiName = '[email protected]'
14+
$openailocation = 'westus'
15+
$deploymentName = 'gpt-4o'
16+
$modelName = 'gpt-4o'
17+
$modelVersion = '2024-11-20'
18+
19+
#Register Azure Resources providers
20+
az provider register --namespace Microsoft.ContainerService
21+
az provider register --namespace Microsoft.ContainerRegistry
22+
23+
while ($true) {
24+
$status = az provider show --namespace Microsoft.ContainerService --query registrationState -o tsv
25+
Write-Output "Current registration state: $status"
26+
if ($status -eq "Registered") { break }
27+
Start-Sleep -Seconds 5
28+
}
29+
30+
while ($true) {
31+
$status = az provider show --namespace Microsoft.ContainerRegistry --query registrationState -o tsv
32+
Write-Output "Current registration state: $status"
33+
if ($status -eq "Registered") { break }
34+
Start-Sleep -Seconds 5
35+
}
36+
37+
# Create ACR
38+
az acr create --resource-group $resourceGroup --name $acrName --sku Basic --location $location
39+
40+
#Create new User-Assigned Managed Identity
41+
$identityName = "$aksName-identity"
42+
az identity create --resource-group $resourceGroup --name $identityName --location $location
43+
$identityId = az identity show --resource-group $resourceGroup --name $identityName --query id -o tsv
44+
45+
# Create AKS cluster, attach ACR, enable Key Vault CSI driver addon, and assign managed identity
46+
az aks create --resource-group $resourceGroup --name $aksName --node-count 2 --node-vm-size Standard_D2s_v3 --network-plugin azure --no-ssh-key -x --enable-addons azure-keyvault-secrets-provider --assign-identity $identityId
47+
48+
#Create AKS node pool to run the workloads
49+
az aks nodepool add --resource-group $resourceGroup --cluster-name $aksName --name $nodepoolName --node-count 2 --node-vm-size Standard_D2s_v3
50+
51+
# Assign the managed identity to the node pool
52+
$VMSSresourceGroup = az aks show --resource-group $resourceGroup --name $aksName --query "nodeResourceGroup" -o tsv
53+
$VMSSnodepoolName = az vmss list --resource-group $VMSSresourceGroup --query "[].name" -o tsv | Select-String "$nodepoolName"
54+
az vmss identity assign --resource-group $VMSSresourceGroup --name $VMSSnodepoolName --identities $identityId
55+
56+
#Update VMSS instances
57+
az vmss update-instances -g $VMSSresourceGroup -n $VMSSnodepoolName --instance-ids *
58+
59+
# Create CosmosDB account (SQL API)
60+
az cosmosdb create --name $accountName --resource-group $resourceGroup --locations regionName=$location failoverPriority=0 isZoneRedundant=False --kind GlobalDocumentDB
61+
62+
# Create SQL API database
63+
az cosmosdb sql database create --account-name $accountName --name $databaseName --resource-group $resourceGroup
64+
65+
# Create SQL API container for products
66+
az cosmosdb sql container create --account-name $accountName --database-name $databaseName --name $productContainer --resource-group $resourceGroup --partition-key-path "/id" --throughput 400
67+
68+
# Create SQL API container for orders
69+
az cosmosdb sql container create --account-name $accountName --database-name $databaseName --name $ordersContainer --resource-group $resourceGroup --partition-key-path "/id" --throughput 400
70+
71+
# Create Service Bus namespace
72+
az servicebus namespace create --resource-group $resourceGroup --name $namespaceName --location $location --sku Standard
73+
74+
# Create Service Bus queue
75+
az servicebus queue create --resource-group $resourceGroup --namespace-name $namespaceName --name $queueName
76+
77+
# Create Key Vault
78+
az keyvault create --name $keyVaultName --resource-group $resourceGroup --location $location
79+
80+
# --- Grant AKS user-assigned managed identity access to Key Vault ---
81+
# Get the principalId of the AKS user-assigned managed identity
82+
$identityName = "$aksName-identity"
83+
$identityId = az identity show --resource-group $resourceGroup --name $identityName --query principalId -o tsv
84+
85+
# Get subscription ID
86+
$subscriptionId = $(az account show --query id -o tsv)
87+
88+
#Below script doesn't work on Skillable environment
89+
# Assign Key Vault Secrets User role to AKS managed identity at Key Vault scope
90+
$kvScope = "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.KeyVault/vaults/$keyVaultName"
91+
$roleResult = az role assignment create --assignee-object-id $identityId --role "Key Vault Secrets User" --scope $kvScope --assignee-principal-type "ServicePrincipal" 2>&1
92+
if ($LASTEXITCODE -eq 0) {
93+
Write-Host "Granted AKS user-assigned managed identity Key Vault Secrets User role for RBAC access."
94+
} else {
95+
Write-Error "Failed to assign Key Vault Secrets User role to managed identity. Output: $roleResult"
96+
}
97+
98+
# Create Azure OpenAI resource
99+
az cognitiveservices account create `
100+
--name $openaiName `
101+
--resource-group $resourceGroup `
102+
--location $openailocation `
103+
--kind OpenAI `
104+
--sku s0
105+
106+
az cognitiveservices account deployment create `
107+
--resource-group $resourceGroup `
108+
--name $openaiName `
109+
--model-name $deploymentName `
110+
--model-name $modelName `
111+
--model-version $modelVersion `
112+
--model-format OpenAI

0 commit comments

Comments
 (0)