Getting Started with Azure Resource Manager for load balancers in Go

Автор: Mariana Cardoso
Последнее обновление: 11.05.2017
Редактирование в GitHub

This sample shows how to manage a load balancer using the Azure Resource Manager APIs for Go.

You can use a load balancer to provide high availability for your workloads in Azure. An Azure load balancer is a Layer-4 (TCP, UDP) type load balancer that distributes incoming traffic among healthy service instances in cloud services or virtual machines defined in a load balancer set.

For a detailed overview of Azure load balancers, see Azure Load Balancer overview.

This sample deploys an internet-facing load balancer. It then creates and deploys two Azure virtual machines behind the load balancer. For a detailed overview of internet-facing load balancers, see Internet-facing load balancer overview.

To deploy an internet-facing load balancer, you'll need to create and configure the following objects.

  • Front end IP configuration - contains public IP addresses for incoming network traffic.
  • Back end address pool - contains network interfaces (NICs) for the virtual machines to receive network traffic from the load balancer.
  • Load balancing rules - contains rules mapping a public port on the load balancer to port in the back end address pool.
  • Inbound NAT rules - contains rules mapping a public port on the load balancer to a port for a specific virtual machine in the back end address pool.
  • Probes - contains health probes used to check availability of virtual machines instances in the back end address pool.

You can get more information about load balancer components with Azure resource manager at Azure Resource Manager support for Load Balancer.

Tasks performed in this sample

The sample performs the following tasks to create the load balancer and the load-balanced virtual machines:

  1. Create a resource group
  2. Create a storage account
  3. Create a public IP
  4. Create the load balancer with a payload that includes:
    • Front-end IP pool
    • Back-end address pool
    • Health probe
    • Load balancer rule
    • 2 NAT rules
  5. Create a virtual network (vnet)
  6. Create a subnet
  7. Create an availability set
  8. Create NIC 1 and the first VM: Web1
  9. Create NIC 2 and the second VM: Web2
  10. Delete the resource group and the resources created in the previous steps

Run this sample

  1. If you don't already have a Microsoft Azure subscription, you can register for a free trial account.

  2. If you don't already have it, install Go.

  3. Clone the repository.

    git clone
  4. Install the dependencies using glide.

    cd network-go-manage-loadbalancer
    glide install
  5. Create an Azure service principal either through Azure CLI, PowerShell or the portal.

  6. Set the following environment variables using the information from the service principle that you created.

    export AZURE_TENANT_ID={your tenant id}
    export AZURE_CLIENT_ID={your client id}
    export AZURE_CLIENT_SECRET={your client secret}
    export AZURE_SUBSCRIPTION_ID={your subscription id}

    [AZURE.NOTE] On Windows, use set instead of export.

  7. Run the sample.

    go run example.go

More information