Configure a Virtual Machine Scale Set with an existing Azure Standard Load Balancer
In this article, you'll learn how to configure a Virtual Machine Scale Set with an existing Azure Load Balancer. With an existing virtual network and standard sku load balancer, you can deploy a Virtual Machine Scale Set with a few clicks in the Azure portal, or with a few lines of code in the Azure
1h ago
In this article, you'll learn how to configure a Virtual Machine Scale Set with an existing Azure Load Balancer. With an existing virtual network and standard sku load balancer, you can deploy a Virtual Machine Scale Set with a few clicks in the Azure portal, or with a few lines of code in the Azure CLI, or Azure PowerShell using the following tabs.
Prerequisites
- An Azure account with an active subscription. Create an account for free.
-
- An Azure Virtual Network for the Virtual Machine Scale Set and the load balancer.
- An existing standard sku load balancer in the subscription where the Virtual Machine Scale Set will be deployed. Ensure the load balancer has a backend pool.
Sign in to the Azure portal
Sign in to the Azure portal.
Deploy Virtual Machine Scale Set with existing load balancer
In this section, you'll create a Virtual Machine Scale Set in the Azure portal with an existing Azure load balancer.
Note
The following steps assume a virtual network named myVNet and an Azure load balancer named myLoadBalancer has been previously deployed.
On the top left-hand side of the screen, select Create a resource and search for Virtual Machine Scale Set in the marketplace search.
Select Virtual machine scale set and Select Create.
In Create a virtual machine scale set, enter, or select this information in the Basics tab:
Setting Value Project details Subscription Select your Azure subscription Resource Group Select Create new, enter myResourceGroup, then select OK, or select an existing resource group. Scale set details Virtual Machine Scale Set name Enter myVMSS Region Select East US 2 Availability zone Select None Orchestration Orchestration mode Select Uniform Security type Select Standard Scaling Scaling mode Select Manual Instance count Enter 2 Instance details Image Select Ubuntu Server 22.04 LTS Azure Spot instance Select No Size Leave at default Administrator account Authentication type Select SSH public key Username Enter a username for the SSH public key. SSH public key source Select Generate new key pair. SSH key type Select RSA SSH Format. Key pair name Enter a name for the key pair. Select the Networking tab or select Next: Spot > Next: Disks > Next: Networking.
Enter or select this information in the Networking tab:
Setting Value Virtual Network Configuration Virtual network Select myVNet or your existing virtual network. Load balancing Load balancing options Select Azure load balancer Select a load balancer Select myLoadBalancer or your existing load balancer Select a backend pool Select myBackendPool or your existing backend pool. Select the Management tab.
In the Management tab, set Boot diagnostics to Off.
Select the blue Review + create button.
Review the settings and select the Create button.
Prerequisites
- An Azure account with an active subscription. Create an account for free.
- You need an existing standard sku load balancer in the subscription where the Virtual Machine Scale Set will be deployed. Ensure the load balancer has a backend pool.
- You need an Azure Virtual Network for the Virtual Machine Scale Set.
Use the Bash environment in Azure Cloud Shell. For more information, see Get started with Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Authenticate to Azure using Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use and manage extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
- This article requires version 2.0.28 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
Deploy a Virtual Machine Scale Set with existing load balancer
Deploy a Virtual Machine Scale Set with az vmss create.
Replace the values in brackets with the names of the resources in your configuration.
az vmss create \
--resource-group <resource-group> \
--name <vmss-name>\
--image <your-image> \
--admin-username <admin-username> \
--generate-ssh-keys \
--upgrade-policy-mode Automatic \
--instance-count 3 \
--vnet-name <virtual-network-name> \
--subnet <subnet-name> \
--lb <load-balancer-name> \
--backend-pool-name <backend-pool-name>
The below example deploys a Virtual Machine Scale Set with:
- Virtual Machine Scale Set named myVMSS
- Azure Load Balancer named myLoadBalancer
- Load balancer backend pool named myBackendPool
- Azure Virtual Network named myVnet
- Subnet named mySubnet
- Resource group named myResourceGroup
- Ubuntu Server image for the Virtual Machine Scale Set
az vmss create \
--resource-group myResourceGroup \
--name myVMSS \
--image Ubuntu2204 \
--admin-username adminuser \
--generate-ssh-keys \
--upgrade-policy-mode Automatic \
--instance-count 3 \
--vnet-name myVnet\
--subnet mySubnet \
--lb myLoadBalancer \
--backend-pool-name myBackendPool
Note
After you create the scale set, you can't modify the backend port for a load-balancing rule that a health probe uses. For details and the workaround, see Port forwarding and inbound NAT rules.
Prerequisites
- An Azure account with an active subscription. Create an account for free.
-
- An Azure Virtual Network for the Virtual Machine Scale Set and the load balancer.
- An existing standard sku load balancer in the subscription where the Virtual Machine Scale Set will be deployed. Ensure the load balancer has a backend pool.
Azure Cloud Shell
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.
To start Azure Cloud Shell:
| Option | Example/Link |
|---|---|
| Select Try It in the upper-right corner of a code or command block. Selecting Try It doesn't automatically copy the code or command to Cloud Shell. | Open diagram: Screenshot that shows an example of Try It for Azure Cloud Shell. |
| Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser. | Open diagram: Button to launch Azure Cloud Shell. |
| Select the Cloud Shell button on the menu bar at the upper right in the Azure portal. | Open diagram: Screenshot that shows the Cloud Shell button in the Azure portal |
To use Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block (or command block) to copy the code or command.
Paste the code or command into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.
Select Enter to run the code or command.
Note
We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Sign in to Azure CLI
Sign into Azure with Connect-AzAccount
Connect-AzAccount
Deploy a Virtual Machine Scale Set with existing load balancer
Deploy a Virtual Machine Scale Set with New-AzVMss. Replace the values in brackets with the names of the resources in your configuration.
$rsg = <resource-group>
$loc = <location>
$vms = <vm-scale-set-name>
$vnt = <virtual-network>
$sub = <subnet-name>
$lbn = <load-balancer-name>
$pol = <upgrade-policy-mode>
$img = <image-name>
$bep = <backend-pool-name>
$img = <image-name>
$lb = Get-AzLoadBalancer -ResourceGroupName $rsg -Name $lbn
New-AzVmss -ResourceGroupName $rsg -Location $loc -VMScaleSetName $vms -VirtualNetworkName $vnt -SubnetName $sub -LoadBalancerName $lb.Name -UpgradePolicyMode $pol
The below example deploys a Virtual Machine Scale Set with the following values:
- Virtual Machine Scale Set named myVMSS
- Azure Load Balancer named myLoadBalancer
- Load balancer backend pool named myBackendPool
- Azure Virtual Network named myVnet
- Subnet named mySubnet
- Resource group named myResourceGroup
$rsg = "myResourceGroup"
$loc = "East US"
$vms = "myVMSS"
$vnt = "myVNet"
$sub = "default"
$pol = "Automatic"
$lbn = "myLoadBalancer"
$bep = "myBackendPool"
$img = "Ubuntu2204"
$lb = Get-AzLoadBalancer -ResourceGroupName $rsg -Name $lbn
New-AzVmss -ResourceGroupName $rsg -Location $loc -VMScaleSetName $vms -VirtualNetworkName $vnt -SubnetName $sub -LoadBalancerName $lb.Name -UpgradePolicyMode $pol -BackendPoolName $bep -ImageName $img
Note
After you create the scale set, you can't modify the backend port for a load balancing rule that a health probe uses. For details and the workaround, see Port forwarding and inbound NAT rules.