An Azure load balancer is a Layer-4 (TCP, UDP) load balancer. Usually a load balancer gave distributed traffic among VMs in it even if one VM is in down state. I prepared this article by referring the old Azure doc related to Load balancer. So use it for setting up load balancer on azure VM using old AzureRM Network commands. Refer only when you maintaining old AzureRM Network commands not new Az.Network one which is used in below link.
https://docs.microsoft.com/en-us/azure/load-balancer/load-balancer-get-started-internet-arm-ps
In this article I am going to create a load balancer for incoming traffic on HTTP service. Both on port 80 and 443.
At very first we need to have a windows PC/Laptop or a Server which is installed with Azure PowerShell. Because we are going to use Azure PowerShell for implementing Azure Load balancer. Details are in the below Azure doc. I installed Azure powershell using MSI available from github.
https://docs.microsoft.com/en-us/powershell/azureps-cmdlets-docs/
Now Open power-shell. Issue below command to sign in to azure account.
Get existing subscription details using below command. Note down the subscription ID
Choose which of your Azure subscriptions to use.
Create a resource group. (Skip this step if you’re using an existing resource group.)
Create a virtual network and a public IP address for the front-end IP pool
Create a front-end IP pool and a back-end address pool
Create NAT rules, a load balancer rule, a probe, and a load balancer
Create NICs
Now we have to attach this Load balanced NICs “lb-nic1-be” and “lb-nic2-be” to the VMs we are going to use under LoadBalancer. If the VMs are already there, add this NIC as additional NIC of VMs. If VMs are not there, create a new one using this NICs.
One another important point is we we need to make sure all VMs under LoadBalancer is in same “availability set”. If your existing VMs doesn’t have any availability set, then we need to recreate the VMs again to have any availability set.
Refer our own article for creating new VMs for LoadBalancer.
How to create new Azure VM using Powershell commands
Two NIC cards can’t be added to the some Windows VMs basic plan(VM Size). So in such cases we need to either remove the current NIC in the server and only have the loadbalance NIC added to the VM or Upgrade the VM plan to next level that support two NICs.
In case replacing existing NIC with Load balanced NIC, we have condition as Subnet change of VM is only possible if the both subnet are in the same vnet. Virtual network change of an existing VM is not possible at this moment. So need to delete the existing VM and create it again.
Add the network interface to the load balancer
After a network interface is added to the load balancer back-end pool, it starts receiving network traffic based on the load-balancing rules for that load balancer resource. At this point we have load balancer which will route traffic on port 80. This concludes setting up Load balancer.