Skip to content

Instantly share code, notes, and snippets.

@itaysk
Last active August 29, 2015 14:26
Show Gist options
  • Save itaysk/2c717131c4557224bd63 to your computer and use it in GitHub Desktop.
Save itaysk/2c717131c4557224bd63 to your computer and use it in GitHub Desktop.
Azure - Configure Load Balancer for existing VMs (ARM)
#public ip for the load balancer
$lbpip = New-AzurePublicIpAddress -Name "ironlbpip" -ResourceGroupName "iron" -Location "West Europe" –AllocationMethod Dynamic
#configure the public ip as the fronend ip for the load balancer (access endpoint from the internet)
$lbfe = New-AzureLoadBalancerFrontendIpConfig -Name "LB-Frontend" -PublicIpAddress $lbpip
#create an address pool for load balanced servers (later we add addresses to that pool)
$lbbepool= New-AzureLoadBalancerBackendAddressPoolConfig -Name "LB-backend"
#create a load balancing policy: balance all http traffic
$lbrule = New-AzureLoadBalancerRuleConfig -Name "HTTP" -FrontendIpConfiguration $lbfe -BackendAddressPool $lbbepool -Protocol Tcp -FrontendPort 80 -BackendPort 80
#Here we actually create the load balancer resource with all the settings previously defined
$lb = New-AzureLoadBalancer -ResourceGroupName "iron" -Name "ironlb" -Location "West Europe" -FrontendIpConfiguration $lbfe -LoadBalancingRule $lbrule -BackendAddressPool $lbbepool
#Now to add to the pool of load balanced addresses. We add 2 pre-existing NICs to the pool.
#These nics was created beforehand and was associated to working servers.
$nic1 = Get-AzureNetworkInterface -ResourceGroupName iron -Name "iron1133"
$nic2 = Get-AzureNetworkInterface -ResourceGroupName iron -Name "iron3750"
$nic1.IpConfigurations[0].LoadBalancerBackendAddressPools.Add($lb.BackendAddressPools[0]);
$nic2.IpConfigurations[0].LoadBalancerBackendAddressPools.Add($lb.BackendAddressPools[0]);
$nic1 | Set-AzureNetworkInterface
$nic2 | Set-AzureNetworkInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment