Created
May 17, 2025 09:20
-
-
Save levymoreira/42d4ae3c8d04097708f30f8f33dc878b to your computer and use it in GitHub Desktop.
2 LB 1 VMSSET (differnt ports!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"location": { | |
"type": "string", | |
"defaultValue": "[resourceGroup().location]", | |
"metadata": { | |
"description": "The location for all resources." | |
} | |
}, | |
"vmSize": { | |
"type": "string", | |
"defaultValue": "Standard_DS1_v2", | |
"metadata": { | |
"description": "The size of the virtual machines." | |
} | |
}, | |
"adminUsername": { | |
"type": "string", | |
"metadata": { | |
"description": "The username for the virtual machines." | |
} | |
}, | |
"adminPassword": { | |
"type": "securestring", | |
"metadata": { | |
"description": "The password for the virtual machines." | |
} | |
}, | |
"instanceCount": { | |
"type": "int", | |
"defaultValue": 2, | |
"minValue": 2, | |
"metadata": { | |
"description": "The number of virtual machine instances in the scale set." | |
} | |
}, | |
"imageOffer": { | |
"type": "string", | |
"defaultValue": "UbuntuServer", | |
"metadata": { | |
"description": "The offer for the virtual machine image." | |
} | |
}, | |
"imageSku": { | |
"type": "string", | |
"defaultValue": "18.04-LTS", | |
"metadata": { | |
"description": "The SKU for the virtual machine image." | |
} | |
}, | |
"loadBalancerNamePrefix": { | |
"type": "string", | |
"defaultValue": "web-lb", | |
"metadata": { | |
"description": "Prefix for the load balancer name" | |
} | |
}, | |
"publicIPNamePrefix": { | |
"type": "string", | |
"defaultValue": "publicip", | |
"metadata": { | |
"description": "Prefix for the public IP name" | |
} | |
} | |
}, | |
"variables": { | |
"virtualNetworkName": "web-vnet", | |
"subnetName": "web-subnet", | |
"publicIPName": "web-publicip", | |
"publicIPNameV2": "web-publicip-v2", | |
"loadBalancerName": "web-lb", | |
"loadBalancerNameV2": "web-lb-v2", | |
"nsgName": "web-nsg", | |
"loadBalancerFrontEndConfigName": "LBFrontend", | |
"loadBalancerFrontEndConfigNameV2": "LBFrontendV2", | |
"loadBalancerBackEndPoolName": "LBBackendPool", | |
"loadBalancerBackEndPoolNameV2": "LBBackendPoolV2", | |
"loadBalancerProbeName": "LBProbe", | |
"loadBalancerProbeNameV2": "LBProbeV2", | |
"loadBalancerHttpRuleName": "HTTPRule", | |
"loadBalancerHttpRuleNameV2": "HTTPRuleV2", | |
"vmssName": "web-vmss", | |
"vmssNameV2": "web-vmss-v2", | |
"storageAccountName": "[concat('st', uniqueString(resourceGroup().id))]", | |
"loadBalancerBackEndPoolName2": "LBBackendPool2" | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Storage/storageAccounts", | |
"apiVersion": "2021-04-01", | |
"name": "[variables('storageAccountName')]", | |
"location": "[parameters('location')]", | |
"sku": { | |
"name": "Standard_LRS" | |
}, | |
"kind": "Storage" | |
}, | |
{ | |
"type": "Microsoft.Network/networkSecurityGroups", | |
"apiVersion": "2020-08-01", | |
"name": "[variables('nsgName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"securityRules": [ | |
{ | |
"name": "AllowHTTP", | |
"properties": { | |
"priority": 1000, | |
"protocol": "Tcp", | |
"access": "Allow", | |
"direction": "Inbound", | |
"sourceAddressPrefix": "*", | |
"sourcePortRange": "*", | |
"destinationAddressPrefix": "*", | |
"destinationPortRange": "80" | |
} | |
}, | |
{ | |
"name": "AllowHTTP8080", | |
"properties": { | |
"priority": 1010, | |
"protocol": "Tcp", | |
"access": "Allow", | |
"direction": "Inbound", | |
"sourceAddressPrefix": "*", | |
"sourcePortRange": "*", | |
"destinationAddressPrefix": "*", | |
"destinationPortRange": "8080" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/publicIPAddresses", | |
"apiVersion": "2020-08-01", | |
"name": "[variables('publicIPName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"publicIPAllocationMethod": "Static" | |
}, | |
"sku": { | |
"name": "Standard" | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/publicIPAddresses", | |
"apiVersion": "2020-08-01", | |
"name": "[variables('publicIPNameV2')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"publicIPAllocationMethod": "Static" | |
}, | |
"sku": { | |
"name": "Standard" | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/virtualNetworks", | |
"apiVersion": "2020-08-01", | |
"name": "[variables('virtualNetworkName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]" | |
], | |
"properties": { | |
"addressSpace": { | |
"addressPrefixes": [ | |
"10.0.0.0/16" | |
] | |
}, | |
"subnets": [ | |
{ | |
"name": "[variables('subnetName')]", | |
"properties": { | |
"addressPrefix": "10.0.0.0/24", | |
"networkSecurityGroup": { | |
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgName'))]" | |
} | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/loadBalancers", | |
"apiVersion": "2020-08-01", | |
"name": "[variables('loadBalancerName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))]", | |
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]" | |
], | |
"properties": { | |
"frontendIPConfigurations": [ | |
{ | |
"name": "[variables('loadBalancerFrontEndConfigName')]", | |
"properties": { | |
"publicIPAddress": { | |
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))]" | |
} | |
} | |
} | |
], | |
"backendAddressPools": [ | |
{ | |
"name": "[variables('loadBalancerBackEndPoolName')]" | |
}, | |
{ | |
"name": "[variables('loadBalancerBackEndPoolName2')]" | |
} | |
], | |
"loadBalancingRules": [ | |
{ | |
"name": "[variables('loadBalancerHttpRuleName')]", | |
"properties": { | |
"frontendIPConfiguration": { | |
"id": "[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', variables('loadBalancerName'), variables('loadBalancerFrontEndConfigName'))]" | |
}, | |
"frontendPort": 80, | |
"backendPort": 80, | |
"protocol": "Tcp", | |
"enableFloatingIP": false, | |
"backendAddressPool": { | |
"id": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', variables('loadBalancerName'), variables('loadBalancerBackEndPoolName'))]" | |
}, | |
"probe": { | |
"id": "[resourceId('Microsoft.Network/loadBalancers/probes', variables('loadBalancerName'), variables('loadBalancerProbeName'))]" | |
} | |
} | |
} | |
], | |
"probes": [ | |
{ | |
"name": "[variables('loadBalancerProbeName')]", | |
"properties": { | |
"protocol": "Http", | |
"port": 80, | |
"requestPath": "/", | |
"intervalInSeconds": 15, | |
"numberOfProbes": 2 | |
} | |
} | |
] | |
}, | |
"sku": { | |
"name": "Standard" | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/loadBalancers", | |
"apiVersion": "2020-08-01", | |
"name": "[variables('loadBalancerNameV2')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPNameV2'))]", | |
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]" | |
], | |
"properties": { | |
"frontendIPConfigurations": [ | |
{ | |
"name": "[variables('loadBalancerFrontEndConfigNameV2')]", | |
"properties": { | |
"publicIPAddress": { | |
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPNameV2'))]" | |
} | |
} | |
} | |
], | |
"backendAddressPools": [ | |
{ | |
"name": "[variables('loadBalancerBackEndPoolNameV2')]" | |
} | |
], | |
"loadBalancingRules": [ | |
{ | |
"name": "[variables('loadBalancerHttpRuleNameV2')]", | |
"properties": { | |
"frontendIPConfiguration": { | |
"id": "[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations', variables('loadBalancerNameV2'), variables('loadBalancerFrontEndConfigNameV2'))]" | |
}, | |
"frontendPort": 80, | |
"backendPort": 8080, | |
"protocol": "Tcp", | |
"enableFloatingIP": false, | |
"backendAddressPool": { | |
"id": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', variables('loadBalancerNameV2'), variables('loadBalancerBackEndPoolNameV2'))]" | |
}, | |
"probe": { | |
"id": "[resourceId('Microsoft.Network/loadBalancers/probes', variables('loadBalancerNameV2'), variables('loadBalancerProbeNameV2'))]" | |
} | |
} | |
} | |
], | |
"probes": [ | |
{ | |
"name": "[variables('loadBalancerProbeNameV2')]", | |
"properties": { | |
"protocol": "Http", | |
"port": 8080, | |
"requestPath": "/", | |
"intervalInSeconds": 15, | |
"numberOfProbes": 2 | |
} | |
} | |
] | |
}, | |
"sku": { | |
"name": "Standard" | |
} | |
}, | |
{ | |
"type": "Microsoft.Compute/virtualMachineScaleSets", | |
"apiVersion": "2020-12-01", | |
"name": "[variables('vmssName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName'))]", | |
"[resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerNameV2'))]", | |
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]" | |
], | |
"sku": { | |
"name": "[parameters('vmSize')]", | |
"capacity": "[parameters('instanceCount')]" | |
}, | |
"properties": { | |
"upgradePolicy": { | |
"mode": "Manual" | |
}, | |
"virtualMachineProfile": { | |
"osProfile": { | |
"computerNamePrefix": "vmss", | |
"adminUsername": "[parameters('adminUsername')]", | |
"adminPassword": "[parameters('adminPassword')]" | |
}, | |
"storageProfile": { | |
"osDisk": { | |
"createOption": "FromImage", | |
"managedDisk": { | |
"storageAccountType": "Standard_LRS" | |
} | |
}, | |
"imageReference": { | |
"publisher": "Canonical", | |
"offer": "[parameters('imageOffer')]", | |
"sku": "[parameters('imageSku')]", | |
"version": "latest" | |
} | |
}, | |
"networkProfile": { | |
"networkInterfaceConfigurations": [ | |
{ | |
"name": "nicConfig", | |
"properties": { | |
"primary": true, | |
"ipConfigurations": [ | |
{ | |
"name": "ipConfig", | |
"properties": { | |
"primary": true, | |
"subnet": { | |
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]" | |
}, | |
"loadBalancerBackendAddressPools": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', variables('loadBalancerName'), variables('loadBalancerBackEndPoolName'))]" | |
} | |
] | |
} | |
}, | |
{ | |
"name": "ipConfig2", | |
"properties": { | |
"subnet": { | |
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]" | |
}, | |
"loadBalancerBackendAddressPools": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools', variables('loadBalancerNameV2'), variables('loadBalancerBackEndPoolNameV2'))]" | |
} | |
] | |
} | |
} | |
], | |
"enableIpForwarding": true | |
} | |
} | |
] | |
}, | |
"extensionProfile": { | |
"extensions": [ | |
{ | |
"name": "InstallWebServer", | |
"properties": { | |
"publisher": "Microsoft.Azure.Extensions", | |
"type": "CustomScript", | |
"typeHandlerVersion": "2.1", | |
"autoUpgradeMinorVersion": true, | |
"settings": { | |
"commandToExecute": "apt-get update && apt-get install -y nginx && systemctl start nginx && systemctl enable nginx && echo '<html><body><h1>Hello from Azure VM Scale Set - Port 80</h1><p>Server hostname: '$(hostname)'</p><p>This content is served from the first load balancer (web-lb)</p><p>Current time: '$(date)'</p></body></html>' > /var/www/html/index.html && mkdir -p /var/www/html-v2 && echo '<html><body><h1>Hello from Azure VM Scale Set - Port 8080</h1><p>Server hostname: '$(hostname)'</p><p>This content is served from the second load balancer (web-lb-v2)</p><p>Current time: '$(date)'</p></body></html>' > /var/www/html-v2/index.html && echo 'server { listen 8080; root /var/www/html-v2; index index.html index.htm; server_name _; location / { try_files $uri $uri/ =404; } }' > /etc/nginx/sites-available/v2 && ln -s /etc/nginx/sites-available/v2 /etc/nginx/sites-enabled/ && ufw allow 'Nginx HTTP' && ufw allow 8080/tcp && systemctl reload nginx" | |
}, | |
"protectedSettings": {} | |
} | |
}, | |
{ | |
"name": "health-extension", | |
"properties": { | |
"publisher": "Microsoft.ManagedServices", | |
"type": "ApplicationHealthLinux", | |
"typeHandlerVersion": "1.0", | |
"autoUpgradeMinorVersion": true, | |
"settings": { | |
"protocol": "http", | |
"port": 80, | |
"requestPath": "/" | |
} | |
} | |
} | |
] | |
} | |
}, | |
"overprovision": true | |
} | |
} | |
], | |
"outputs": { | |
"publicIPAddress": { | |
"type": "string", | |
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))).ipAddress]" | |
}, | |
"publicIPAddressV2": { | |
"type": "string", | |
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPNameV2'))).ipAddress]" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment