Add multiple Public IPs to Azure ARM loadbalancer

I am not sure about you, but I certainly find that certain tasks in Azure are just painful. Either the documentation is out of date, or it just does not exist. I get that the platform is moving so fast that keeping documentation up to date is a big ask. Yet a few years ago deploying code and features with such pace was also tough…. Rant over. I promise.

What I wanted to do was to have multiple websites hosted on different public IP addresses. Simple. Well it wasn’t and I am hoping that the following powershell will help you out.

GOTCHA – So I learnt the hard way, that there is a limit of 5 static public IPs that can be added to an Azure LB. To be able to add more you have to request it from Azure support.

#Set Resource group and location.
$RG=’My resourcegroup name’
$lb=Get-AzureRmLoadBalancer -Name AzureLBName -ResourceGroupName $RG

#Create new public IP’s. Remember you get 5 free with your subscription. The rest are charged each month.
$PIP1=New-AzureRmPublicIpAddress -Name PublicIP-website1 -ResourceGroupName $RG -Location $Location -AllocationMethod Static
$PIP2=New-AzureRmPublicIpAddress -Name PublicIP-website2 -ResourceGroupName $RG -Location $Location -AllocationMethod Static
$PIP3=New-AzureRmPublicIpAddress -Name PublicIP-website3 -ResourceGroupName $RG -Location $Location -AllocationMethod Static

#Create the new front end configurations. These contain the public IP addresses.
$FEConfig1=New-AzureRmLoadBalancerFrontendIpConfig -Name FEConfig1-website1 -PublicIpAddressId $PIP1.Id
$FEConfig2=New-AzureRmLoadBalancerFrontendIpConfig -Name FEConfig2-website2 -PublicIpAddressId $PIP2.Id
$FEConfig3=New-AzureRmLoadBalancerFrontendIpConfig -Name FEConfig3-website3 -PublicIpAddressId $PIP3.Id

#Add Frontend configurations to the LB
Set-AzureRmLoadBalancer -LoadBalancer $lb

Set-AzureRmLoadBalancer -LoadBalancer $lb

Set-AzureRmLoadBalancer -LoadBalancer $lb

At this point if you look in the Azure portal all you will be able to see if the new Static Public IPs. To see the new front end configurations you need to call your $lb value back.

Now you need to join up an Azure LB rule and Probe to the new front end configuration that has the Static public IP in it. At the time of writing this, I could not do this in the Azure Portal. As the Azure portal only exposes the default public IP of the LB.

So I wrote these additional lines of Powershell. Note I reused the $lb variable we set earlier. I only have one backend pool. You may have more. I will show you how to bind one rule to a front end configuration. You can scale this out as required. Also I am opening up TCP 1433 for SQL in my example. You may want to open HTTP. So please change as required. Finally I actually created my probe using the Azure portal before I ran these commands.

#Set some variables for the values we will require in the next command. Failing to do so will result in a lovely error!
$FEconfigWeb1=Get-AzureRmLoadBalancerFrontendIpConfig -Name FEConfig5-website1 -LoadBalancer $lb
$BEpool=Get-AzureRmLoadBalancerBackendAddressPoolConfig -LoadBalancer $lb -Name “LB_POOL”
$ProbeWeb1=Get-AzureRmLoadBalancerProbeConfig -LoadBalancer $lb -Name Probe-Website1

#Add the new backend rule to an existing Probe and frontend config.
$lb | Add-AzureRmLoadBalancerRuleConfig -Name “Website1_Rule” -FrontendIPConfiguration $FEconfigWeb1 -BackendAddressPool $BEpool -Probe $ProbeWeb1 -Protocol “Tcp” -FrontendPort 1433 -BackendPort 1433 -IdleTimeoutInminutes 15 | Set-AzureRmLoadBalancer

I hope this helps.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s