If you checked my previous articles about the two VMs with external IPs, you may have noticed that both VMs get an external IP and that there is no TCP port restriction to them. That won’t likely be the normal situation. Very commonly, you will want something balancing the load between those two identical machines, as well as some control over the ports that can be accessed. In order to accomplish that, we will first create a SINGLE publicIP and then apply to a load balancer entity.
First things first. The Public IP configuration. What I will do is remove the loop and make it a single public IP. This is what I had:
Now, after changing:
I have also changed the variable names, to represent better what we need to have (names, not prefixes).
Next I will remove the reference from the Nics, since the VMs themselves won’t have public IPs:
However, you will need to add a dependency on the Load Balancer and assigned NAT rules and backend LB pool:
Second, we should add the load balancer itself. It is a tough cookie this one, so let’s take the “Jack the Ripper approach”: Let’s cut it into pieces.
But first, let’s take a look from a high level. Here’s the skeleton of the beast:
1. “type”: “Microsoft.Network/loadBalancers”, –> sort of obvious.
2. “dependsOn”: [ “[concat(‘Microsoft.Network/publicIPAddresses/’, variables(‘PublicIPName’))]” ], –> it needs the external IP to work.
3. “frontendIPConfigurations” –> Contains the name of the external LB IP and a reference to the external IP we have created before.
4. “backendAddressPools” -> This configuration will have the name and the backend IP addresses. In this case, the names are sort of hardcoded (allowing only two IPs).
5. “inboundNatRules” –> as the name states, this will create NAT rules to allow certain protocols through the load balancer. This used to be done with a cloud service in the old service model.
Notice that I’m basically mapping Port 50001 and 50002 to 3389 through the same external IP to the respective internal VM IPs.
6. “loadBalancingRules” –> here’s where you’ll define which ports (services) will be load-balanced:
7. “probes”: And finally, how to detect the availability of the load-balanced services:
I have also added an Availability set, just so I can get guaranteed 99.95% availability:
And assigned the VMs:
Once deployed, you’ll hopefully see this:
Now for a quick testing. Let’s deploy IIS to both VMs, change the default website and test the LB. Notice that because I have a LB rule, I can Connect to the VM:
Just accept the the next question and there you are:
Let’s add IIS to both VMs:
And add something to identify each one of the VMs:
Now, when opening the page from the outside:
So! That concludes or tutorial! You can find the template here.
I hope this helps!