Quickstart: Create a public load balancer to load balance VMs using the Azure portal

Get started with Azure Load Balancer by using the Azure portal to create a public load balancer and three 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.

Standard load balancer resources created for quickstart.

Figure: Resources created in quickstart.

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

When you create a public load balancer, you create a new public IP address that is configured as the frontend (named as LoadBalancerFrontend by default) for the load balancer.

  1. Select Create a resource.

  2. In the search box, enter Load balancer. Select Load balancer in the search results.

  3. In the Load balancer page, select Create.

  4. On the Create load balancer page enter, or select the following information:

    Setting Value
    Subscription Select your subscription.
    Resource group Select Create new and enter CreatePubLBQS-rg in the text box.
    Name Enter myLoadBalancer
    Region Select (Europe) West Europe.
    Type Select Public.
    SKU Leave the default Standard.
    Tier Leave the default Regional.
    Public IP address Select Create new. If you have an existing Public IP you would like to use, select Use existing.
    Public IP address name Type myPublicIP in the text box.
    Availability zone Select Zone-redundant to create a resilient load balancer. To create a zonal load balancer, select a specific zone from 1, 2, or 3
    Add a public IPv6 address Select No.
    For more information on IPv6 addresses and load balancer, see What is IPv6 for Azure Virtual Network?
    Routing preference Leave the default of Microsoft network.
    For more information on routing preference, see What is routing preference (preview)?.
  5. Accept the defaults for the remaining settings, and then select Review + create.

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

    Create a standard 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.

Create backend servers

In this section, you:

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

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 CreatePubLBQS-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 virtual machines

In this section, you'll create three VMs (myVM1, myVM2 and myVM3) in three different zones (Zone 1, Zone 2, and Zone 3).

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 CreatePubLBQS-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
    Inbound port rules
    Public inbound ports Select None
  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.
    Under Inbound rules, select +Add an inbound rule.
    Under Destination port ranges, enter 80.
    Under Priority, enter 100.
    In Name, enter myHTTPRule
    Select Add
    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 the Management tab, or select Next > Management.

  6. In the Management tab, select or enter:

    Setting Value
    Monitoring
    Boot diagnostics Select Off
  7. Select Review + create.

  8. Review the settings, and then select Create.

  9. Follow the steps 1 to 8 to create two additional VMs with the following values and all the other settings the same as myVM1:

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

Note

Azure provides an ephemeral IP for Azure Virtual Machines which aren't assigned a public IP address, or are in the backend pool of an internal Basic Azure Load Balancer. The ephemeral IP mechanism provides an outbound IP address that isn't configurable.

The ephemeral IP is disabled when a public IP address is assigned to the virtual machine or the virtual machine is placed in the backend pool of a Standard Load Balancer with or without outbound rules. If a Azure Virtual Network NAT gateway resource is assigned to the subnet of the virtual machine, the ephemeral IP is disabled.

For more information on outbound connections in Azure, see Using Source Network Address Translation (SNAT) for outbound connections.

Create outbound rule configuration

Load balancer outbound rules configure outbound SNAT for VMs in the backend pool.

For more information on outbound connections, see Outbound connections in Azure.

Create outbound rule

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

  2. Under Settings, select Outbound rules, then select Add.

  3. Use these values to configure the outbound rules:

    Setting Value
    Name Enter myOutboundRule.
    Frontend IP address Select Create new.
    In Name, enter LoadBalancerFrontEndOutbound.
    Select IP address or IP prefix.
    Select Create new under Public IP address or Public IP prefix.
    For Name, enter myPublicIPOutbound or myPublicIPPrefixOutbound.
    Select Add.
    Idle timeout (minutes) Move slider to 15 minutes.
    TCP Reset Select Enabled.
    Backend pool Select Create new.
    Enter myBackendPoolOutbound in Name.
    Select Add.
    Port allocation -> Port allocation Select Manually choose number of outbound ports
    Outbound ports -> Choose by Select Ports per instance
    Outbound ports -> Ports per instance Enter 10000.
  4. Select Add.

Add virtual machines to outbound pool

  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.

  3. Select myBackendPoolOutbound.

  4. In Virtual network, select myVNet.

  5. In Virtual machines, select + Add.

  6. Check the boxes next to myVM1, myVM2, and myVM3.

  7. Select Add.

  8. Select Save.

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 CreatePubLBQS-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 and myVM3.

Test the load balancer

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

  2. Copy the public IP address, and then paste it into the address bar of your browser. The default page of IIS Web server is displayed on the browser.

    IIS Web server

To see the load balancer distribute traffic across all three 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 CreatePubLBQS-rg that contains the resources and then select Delete.

Next steps

In this quickstart, you:

  • Created an Azure Standard or Basic Load Balancer
  • Attached 3 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: