Skip to content

Commit 848c67d

Browse files
committed
Add extension for VMSS creation
1 parent a1b853f commit 848c67d

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

modules/kustomize/stretch/stretch.sh

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ VMSS_RG="${RG}-vmss"
1111

1212
TENANT_ID="72f988bf-86f1-41af-91ab-2d7cd011db47"
1313
AAD_ADMIN_GROUP_ID="8a5603a8-2c60-49ab-bc28-a989b91e187d"
14+
BOOTSTRAP_SCRIPT_PATH=$1
1415

1516
create_cluster() {
1617
az group create -n ${RG} -l $LOCATION --tags "SkipAKSCluster=1" "SkipASB_Audit=true" "SkipLinuxAzSecPack=true"
@@ -261,24 +262,36 @@ create_vm() {
261262
}
262263

263264
create_vmss() {
265+
bootstrap_script_path=$1
266+
LB_NAME="vmss-lb"
267+
BACKEND_POOL="lb-backend-pool"
264268
az group create -n $VMSS_RG -l $VMSS_LOCATION --tags "SkipAKSCluster=1" "SkipASB_Audit=true" "SkipLinuxAzSecPack=true"
265269
az network vnet create --resource-group $VMSS_RG --location $VMSS_LOCATION --name $VMSS_VNET --address-prefixes 172.16.0.0/12 -o none
266270
az network vnet subnet create --resource-group $VMSS_RG --vnet-name $VMSS_VNET --name $VMSS_SUBNET --address-prefixes 172.16.0.0/16 -o none
267271

268272
az network lb create \
269273
--resource-group $VMSS_RG \
270-
--name vmss-lb \
274+
--name $LB_NAME \
271275
--sku Standard \
272276
--frontend-ip-name lb-frontend \
273-
--backend-pool-name lb-backend-pool
277+
--backend-pool-name $BACKEND_POOL
274278
lb_backend_pool_id=$(az network lb address-pool show \
275279
--resource-group $VMSS_RG \
276-
--lb-name vmss-lb \
277-
--name lb-backend-pool \
280+
--lb-name $LB_NAME \
281+
--name $BACKEND_POOL \
278282
--query id -o tsv)
283+
az network lb outbound-rule create \
284+
--resource-group $VMSS_RG \
285+
--lb-name $LB_NAME \
286+
--name lb-outbound-rule \
287+
--address-pool $BACKEND_POOL \
288+
--protocol All \
289+
--idle-timeout 30 \
290+
--enable-tcp-reset true
279291

280292
identity_id=$(az identity show --name $IDENTITY_NAME --resource-group $RG --query id -o tsv)
281293

294+
# First create a VMSS with bootstrap script using CustomScript extension
282295
az deployment group create \
283296
--resource-group $VMSS_RG \
284297
--template-file vmss-dual-ipconfig.json \
@@ -287,8 +300,27 @@ create_vmss() {
287300
--parameters vnetName=$VMSS_VNET \
288301
--parameters subnetName=$VMSS_SUBNET \
289302
--parameters loadBalancerBackendPoolId="$lb_backend_pool_id" \
290-
--parameters managedIdentityId="$identity_id"
303+
--parameters managedIdentityId="$identity_id" \
304+
--parameters bootstrapScript="$(base64 -w 0 $bootstrap_script_path)"
291305

306+
echo "VMSS created in resource group: $VMSS_RG"
307+
# Next, update VMSS to uset ipvlan setup script
308+
az deployment group create \
309+
--resource-group $VMSS_RG \
310+
--template-file vmss-dual-ipconfig.json \
311+
--parameters vmssName="test-vmss" \
312+
--parameters sshPublicKey="$(cat ~/.ssh/id_rsa.pub)" \
313+
--parameters vnetName=$VMSS_VNET \
314+
--parameters subnetName=$VMSS_SUBNET \
315+
--parameters loadBalancerBackendPoolId="$lb_backend_pool_id" \
316+
--parameters managedIdentityId="$identity_id" \
317+
--parameters bootstrapScript="$(base64 -w 0 setup_ipvlan.sh)"
318+
319+
echo "Run ipvlan setup script"
320+
az vmss update-instances \
321+
--resource-group $node_rg \
322+
--name $vmss_name \
323+
--instance-ids "*"
292324
}
293325

294326
setup_vnet_peering() {
@@ -316,6 +348,6 @@ setup_vnet_peering() {
316348
}
317349

318350
# update_aks_vmss
319-
create_vm
320-
# create_vmss
351+
# create_vm
352+
create_vmss $BOOTSTRAP_SCRIPT_PATH
321353
# setup_vnet_peering

modules/kustomize/stretch/vmss-dual-ipconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
"metadata": {
7777
"description": "Resource ID of the user-assigned managed identity to associate with the VMSS (optional)"
7878
}
79+
},
80+
"bootstrapScript": {
81+
"type": "string",
82+
"metadata": {
83+
"description": "A Base64-encoded bootstrap script to run on VMSS instances"
84+
}
7985
}
8086
},
8187
"variables": {
@@ -168,6 +174,22 @@
168174
}
169175
}
170176
]
177+
},
178+
"extensionProfile": {
179+
"extensions": [
180+
{
181+
"name": "bootstrapExtension",
182+
"properties": {
183+
"publisher": "Microsoft.Azure.Extensions",
184+
"type": "CustomScript",
185+
"typeHandlerVersion": "2.1",
186+
"autoUpgradeMinorVersion": true,
187+
"settings": {
188+
"script": "[parameters('bootstrapScript')]"
189+
}
190+
}
191+
}
192+
]
171193
}
172194
}
173195
}

0 commit comments

Comments
 (0)