Поделиться через


Multi VIP Load balancer in ARM

I get this question more than a person would think. How can I add a new VIP to an ARM Load Balancer. Below is my script I use. You can add up to 20 by default without contacting support.

For most of this you can rinse and repeat. Make sure that your servers that are going to be in the back end pool are in the same availability set. This will make life easier down the road should you go to add more servers, or update anything.

 

Powershell script:
#Set Resource group and location. Update to your values.
$RG='MultiLBTest'
$Location='centralus'

New-AzureRmResourceGroup -Name $RG -Location $Location
#Create new public IP's Just update the name for each one you want to add.
$PIP1=New-AzureRmPublicIpAddress -Name PIP1 -ResourceGroupName $RG -Location $Location -AllocationMethod Static
$PIP2=New-AzureRmPublicIpAddress -Name PIP2 -ResourceGroupName $RG -Location $Location -AllocationMethod Static
$PIP3=New-AzureRmPublicIpAddress -Name PIP3 -ResourceGroupName $RG -Location $Location -AllocationMethod Static
$PIP4=New-AzureRmPublicIpAddress -Name PIP4 -ResourceGroupName $RG -Location $Location -AllocationMethod Static
$PIP5=New-AzureRmPublicIpAddress -Name PIP5 -ResourceGroupName $RG -Location $Location -AllocationMethod Static
#Creations of the FE Configes Update the number of FE Configs you want to create. This will increase with Public IP's and be added to the LB as shown down below.

$FEConfig=New-AzureRmLoadBalancerFrontendIpConfig -Name FEConfig1 -PublicIpAddressId $PIP1.Id
$FEConfig1=New-AzureRmLoadBalancerFrontendIpConfig -Name FEConfig2 -PublicIpAddressId $PIP2.Id
$FEConfig2=New-AzureRmLoadBalancerFrontendIpConfig -Name FEConfig3 -PublicIpAddressId $PIP3.Id
#Creation of the BEPools
$BEPool=New-AzureRmLoadBalancerBackendAddressPoolConfig -Name BEPool

#Creation of the LB
$lb=New-AzureRmLoadBalancer -Name LBTest1 -ResourceGroupName $RG -Location $Location -FrontendIpConfiguration $FEConfig,$FEConfig1 -BackendAddressPool $BEPool

#Updating with the configuration from Azure
$lb=Get-AzureRmLoadBalancer -Name LBTest1 -ResourceGroupName $RG

#Adding FE Configurations ot the LB
$lb.FrontendIpConfigurations.Add($FECOnfig2)
$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb

#Updating with the configuration from Azure
$lb=Get-AzureRmLoadBalancer -Name LBTest1 -ResourceGroupName $RG

#Adding Probes
$fec=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FEConfig.Name -LoadBalancer $lb
$fec1=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FECOnfig2.Name -LoadBalancer $lb
$BEP=Get-AzureRmLoadBalancerBackendAddressPoolConfig -Name $BEPool.Name -LoadBalancer $lb
$Probe=New-AzureRmLoadBalancerProbeConfig -Name Probe2 -Protocol Tcp -Port 80 -IntervalInSeconds 5 -ProbeCount 2
$lb.Probes.Add($Probe)
$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb

#Getting values from Azure for Rules
$lb=Get-AzureRmLoadBalancer -Name LBTest1 -ResourceGroupName $RG

#Need to have $fec1 $fec2 etc for each Front End Config in the Load balancer. Only update the $FECOnfig(1234567).Name for each.
$fec=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FEConfig.Name -LoadBalancer $lb
$fec1=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FECOnfig2.Name -LoadBalancer $lb

$BEP=Get-AzureRmLoadBalancerBackendAddressPoolConfig -Name $BEPool.Name -LoadBalancer $lb
$Probe=Get-AzureRmLoadBalancerProbeConfig -Name Probe1 -LoadBalancer $lb

#Adding LB rules

$LBRule1=New-AzureRmLoadBalancerRuleConfig -Name Rule1 -FrontendIpConfigurationId $fec.Id -BackendAddressPoolId $BEP.Id -ProbeId $Probe.Id -Protocol Tcp -FrontendPort 80 -BackendPort 80
$lb.LoadBalancingRules.Add($LBRule1)
$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb

#Adding LB Rule to FE Config
$lb=Get-AzureRmLoadBalancer -Name LBTest1 -ResourceGroupName $RG
$fec1=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FEConfig1.Name -LoadBalancer $lb
$Probe=Get-AzureRmLoadBalancerProbeConfig -Name Probe1 -LoadBalancer $lb
$LBRule1=New-AzureRmLoadBalancerRuleConfig -Name Rule2 -FrontendIpConfigurationId $fec1.Id -BackendAddressPoolId $BEP.Id -ProbeId $Probe.Id -Protocol Tcp -FrontendPort 80 -BackendPort 81
$lb.LoadBalancingRules.Add($LBRule1)
$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb
#Adding LB Rule to additional configs

$lb=Get-AzureRmLoadBalancer -Name LBTest1 -ResourceGroupName $RG
$LBRule=Get-AzureRmLoadBalancerRuleConfig -Name Rule1 -LoadBalancer $lb
$fec1=Get-AzureRmLoadBalancerFrontendIpConfig -Name $FEConfig1.Name -LoadBalancer $lb

$lb.FrontendIpConfigurations.Add($fec1)
$Set=Set-AzureRmLoadBalancer -LoadBalancer $lb