Quickstart: Create an internal load balancer to load balance VMs using the Azure portal

Get started with Azure Load Balancer by using the Azure portal to create an internal load balancer and two virtual machines.

Prerequisites

Sign in to Azure

Sign in to the Azure portal at https://portal.azure.com.


Note

Standard SKU load balancer is recommended for production workloads. For more information about skus, see Azure Load Balancer SKUs.

In this section, you create a load balancer that load balances virtual machines.

When you create an internal load balancer, a virtual network is configured as the network for the load balancer.

A private IP address in the virtual network is configured as the frontend (named as LoadBalancerFrontend by default) for the load balancer.

The frontend IP address can be Static or Dynamic.

Create the virtual network

In this section, you'll create a virtual network and subnet.

  1. On the upper-left side of the screen, select Create a resource > Networking > Virtual network or search for Virtual network in the search box.

  2. In Create virtual network, enter or select this information in the Basics tab:

    Setting Value
    Project Details
    Subscription Select your Azure subscription
    Resource Group Select CreateIntLBQS-rg
    Instance details
    Name Enter myVNet
    Region Select West Europe
  3. Select the IP Addresses tab or select the Next: IP Addresses button at the bottom of the page.

  4. In the IP Addresses tab, enter this information:

    Setting Value
    IPv4 address space Enter 10.1.0.0/16
  5. Under Subnet name, select the word default.

  6. In Edit subnet, enter this information:

    Setting Value
    Subnet name Enter myBackendSubnet
    Subnet address range Enter 10.1.0.0/24
  7. Select Save.

  8. Select the Security tab.

  9. Under BastionHost, select Enable. Enter this information:

    Setting Value
    Bastion name Enter myBastionHost
    AzureBastionSubnet address space Enter 10.1.1.0/24
    Public IP Address Select Create new.
    For Name, enter myBastionIP.
    Select OK.
  10. Select the Review + create tab or select the Review + create button.

  11. Select Create.

Create load balancer

  1. On the top left-hand side of the screen, select Create a resource > Networking > Load Balancer.

  2. In the Basics tab of the Create load balancer page, enter, or select the following information:

    Setting Value
    Subscription Select your subscription.
    Resource group Select CreateIntLBQS-rg created in the previous step.
    Name Enter myLoadBalancer
    Region Select West Europe.
    Type Select Internal.
    SKU Select Standard
    Virtual network Select myVNet created in the previous step.
    Subnet Select myBackendSubnet created in the previous step.
    IP address assignment Select Dynamic.
    Availability zone Select Zone-redundant
  3. Accept the defaults for the remaining settings, and then select Review + create.

  4. In the Review + create tab, select Create.

    Create a standard internal load balancer.

Create load balancer resources

In this section, you configure:

  • Load balancer settings for a backend address pool.
  • A health probe.
  • A load balancer rule.

Create a backend pool

A backend address pool contains the IP addresses of the virtual (NICs) connected to the load balancer.

Create the backend address pool myBackendPool to include virtual machines for load-balancing internet traffic.

  1. Select All services in the left-hand menu, select All resources, and then select myLoadBalancer from the resources list.

  2. Under Settings, select Backend pools, then select Add.

  3. On the Add a backend pool page, for name, type myBackendPool, as the name for your backend pool, and then select Add.

Create a health probe

The load balancer monitors the status of your app with a health probe.

The health probe adds or removes VMs from the load balancer based on their response to health checks.

Create a health probe named myHealthProbe to monitor the health of the VMs.

  1. Select All services in the left-hand menu, select All resources, and then select myLoadBalancer from the resources list.

  2. Under Settings, select Health probes, then select Add.

    Setting Value
    Name Enter myHealthProbe.
    Protocol Select HTTP.
    Port Enter 80.
    Interval Enter 15 for number of Interval in seconds between probe attempts.
    Unhealthy threshold Select 2 for number of Unhealthy threshold or consecutive probe failures that must occur before a VM is considered unhealthy.
  3. Leave the rest the defaults and Select OK.

Create a load balancer rule

A load balancer rule is used to define how traffic is distributed to the VMs. You define the frontend IP configuration for the incoming traffic and the backend IP pool to receive the traffic. The source and destination port are defined in the rule.

In this section, you'll create a load balancer rule:

  • Named myHTTPRule.
  • In the frontend named LoadBalancerFrontEnd.
  • Listening on Port 80.
  • Directs load balanced traffic to the backend named myBackendPool on Port 80.
  1. Select All services in the left-hand menu, select All resources, and then select myLoadBalancer from the resources list.

  2. Under Settings, select Load balancing rules, then select Add.

  3. Use these values to configure the load-balancing rule:

    Setting Value
    Name Enter myHTTPRule.
    IP Version Select IPv4
    Frontend IP address Select LoadBalancerFrontEnd
    Protocol Select TCP.
    Port Enter 80.
    Backend port Enter 80.
    Backend pool Select myBackendPool.
    Health probe Select myHealthProbe.
    Idle timeout (minutes) Move the slider to 15 minutes.
    TCP reset Select Enabled.
    Outbound source network address translation (SNAT) Select (Recommended) Use outbound rules to provide backend pool members access to the internet..
  4. Leave the rest of the defaults and then select OK.

Note

The virtual machines in the backend pool will not have outbound internet connectivity with this configuration.
For more information on providing outbound connectivity, see:
Outbound connections in Azure
Options for providing connectivity:
Outbound-only load balancer configuration
What is Virtual Network NAT?

Create backend servers

In this section, you:

  • Create two virtual machines for the backend pool of the load balancer.
  • Install IIS on the virtual machines to test the load balancer.

Create virtual machines

In this section, you'll create two VMs (myVM1 and myVM2).

These VMs are added to the backend pool of the load balancer that was created earlier.

  1. On the upper-left side of the portal, select Create a resource > Compute > Virtual machine.

  2. In Create a virtual machine, type or select the values in the Basics tab:

    Setting Value
    Project Details
    Subscription Select your Azure subscription
    Resource Group Select CreateIntLBQS-rg
    Instance details
    Virtual machine name Enter myVM1
    Region Select West Europe
    Availability Options Select Availability zones
    Availability zone Select 1
    Image Select Windows Server 2019 Datacenter
    Azure Spot instance Select No
    Size Choose VM size or take default setting
    Administrator account
    Username Enter a username
    Password Enter a password
    Confirm password Reenter password
  3. Select the Networking tab, or select Next: Disks, then Next: Networking.

  4. In the Networking tab, select or enter:

    Setting Value
    Network interface
    Virtual network myVNet
    Subnet myBackendSubnet
    Public IP Select None
    NIC network security group Select Advanced
    Configure network security group Select Create new.
    In the Create network security group, enter myNSG in Name.
    Select OK
    Load balancing
    Place this virtual machine behind an existing load balancing solution? Select Yes
    Load balancing settings
    Load balancing options Select Azure load balancing
    Select a load balancer Select myLoadBalancer
    Select a backend pool Select myBackendPool
  5. Select Review + create.

  6. Review the settings, and then select Create.

  7. Follow the steps 1 to 8 to create one additional VM with the following values and all the other settings the same as myVM1:

    Setting VM 2
    Name myVM2
    Availability zone 2
    Network security group Select the existing myNSG

Create test virtual machine

In this section, you'll create a VM named myTestVM. This VM will be used to test the load balancer configuration.

  1. On the upper-left side of the portal, select Create a resource > Compute > Virtual machine.

  2. In Create a virtual machine, type or select the values in the Basics tab:

    Setting Value
    Project Details
    Subscription Select your Azure subscription
    Resource Group Select CreateIntLBQS-rg
    Instance details
    Virtual machine name Enter myTestVM
    Region Select West Europe
    Availability Options Select No infrastructure redundancy required
    Image Select Windows Server 2019 Datacenter
    Azure Spot instance Select No
    Size Choose VM size or take default setting
    Administrator account
    Username Enter a username
    Password Enter a password
    Confirm password Reenter password
  3. Select the Networking tab, or select Next: Disks, then Next: Networking.

  4. In the Networking tab, select or enter:

    Setting Value
    Network interface
    Virtual network myVNet
    Subnet myBackendSubnet
    Public IP Select None.
    NIC network security group Select Advanced
    Configure network security group Select MyNSG created in the previous step.
  5. Select Review + create.

  6. Review the settings, and then select Create.

Install IIS

  1. Select All services in the left-hand menu, select All resources, and then from the resources list, select myVM1 that is located in the CreateIntLBQS-rg resource group.

  2. On the Overview page, select Connect, then Bastion.

  3. Enter the username and password entered during VM creation.

  4. Select Connect.

  5. On the server desktop, navigate to Windows Administrative Tools > Windows PowerShell.

  6. In the PowerShell Window, run the following commands to:

    • Install the IIS server
    • Remove the default iisstart.htm file
    • Add a new iisstart.htm file that displays the name of the VM:
    
     # install IIS server role
     Install-WindowsFeature -name Web-Server -IncludeManagementTools
    
     # remove default htm file
      remove-item  C:\inetpub\wwwroot\iisstart.htm
    
     # Add a new htm file that displays server name
      Add-Content -Path "C:\inetpub\wwwroot\iisstart.htm" -Value $("Hello World from " + $env:computername)
    
  7. Close the Bastion session with myVM1.

  8. Repeat steps 1 to 6 to install IIS and the updated iisstart.htm file on myVM2.

Test the load balancer

  1. Find the private IP address for the load balancer on the Overview screen. Select All services in the left-hand menu, select All resources, and then select myLoadBalancer.

  2. Make note or copy the address next to Private IP Address in the Overview of myLoadBalancer.

  3. Select All services in the left-hand menu, select All resources, and then from the resources list, select myTestVM that is located in the CreateIntLBQS-rg resource group.

  4. On the Overview page, select Connect, then Bastion.

  5. Enter the username and password entered during VM creation.

  6. Open Internet Explorer on myTestVM.

  7. Enter the IP address from the previous step into the address bar of the browser. The default page of IIS Web server is displayed on the browser.

    Screenshot shows a browser window displaying the default page, as expected.

To see the load balancer distribute traffic across both VMs, you can customize the default page of each VM's IIS Web server and then force-refresh your web browser from the client machine.

Clean up resources

When no longer needed, delete the resource group, load balancer, and all related resources. To do so, select the resource group CreateIntLBQS-rg that contains the resources and then select Delete.

Next steps

In this quickstart, you:

  • Created an Azure standard or basic internal load balancer
  • Attached 2 VMs to the load balancer.
  • Configured the load balancer traffic rule, health probe, and then tested the load balancer.

To learn more about Azure Load Balancer, continue to..