Quick Note On IP Addresses And Load Balancers In Azure

When we provision a new Virtual Machine, different kinds of IP addresses are assigned to the VM. VM will be provisioned with Public IP address, where these addresses can be used to access the resources from outside Azure (internet), such as - websites hosted in IIS of Virtual Machine can be accessed using this public virtual IP address.

The second type of IP is a private IP address. These are used by virtual machines inside Azure Virtual Networks to directly communicate with each other. One thing to make note here is, these IPs will not be same next time when the virtual machine boots up! This will break the applications and it sounds terrible; right? Along with this issue, a second major problem is security, because with dynamic IPs, it is not possible to create firewall rules easily. Now, how do we fix it?

Reserved IP Addresses

Yes, this is the solution. Reserved IP addresses are permanently associated with our subscription. We can create five reserved IP addresses per subscription and we can create more as needed. A reserved IP address solves the public IP address issue, we do have Static IP addresses for private traffic inside Azure which solves the private IP address, which gets replaced during boot up.

Steps to add private IP address to the Virtual machine using PowerShell
  1. Get the virtual network and subnet details.
    1. $vnetName = "myvirtualnetwork"  
    2. $locName = "Central US"  
    3. $rgName = "TestRG"  
    4. $nicName="TestNIC"  
    5. $vnet = Get-AzureRmVirtualNetwork -ResourceGroupName $  
    6. rgName  
    7. -Name $  
    8. vnetName  
    9. $subnetid = $vnet.Subnets[0].Id  
  2. Create network Interface with private IP address.
    1. $nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName  
    2. -Location $locName -SubnetId $subnetid  
    3. -PrivateIpAddress  

    3. Add network interface to the Virtual Machine.
  1. $vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id  

Reserving an IP has a cost associated with it! The first five reserved IP addresses that are associated to a cloud service are Free! All other cost money. More details here: https://azure.microsoft.com/en-in/pricing/details/ip-addresses/

Load balancer

The goal of the load balancer is to redirect the request to multiple servers so that load can be distributed and response time can be reduced. By default, distribution of request maps go to the available servers randomly but we can also configure the distribution mode called Source IP affinity. In this the case request will be routed back to same server.

There are three types of load balancing in Azure I can think of and these are extremely important to creating highly available architecture within azure.

  • Traffic Manager
    In this case, the request will be directed to geographically close servers. This will be done at DNS level. Traffic manager does not actually route traffic, it just serves to the client the DNS name of the endpoint where traffic should go. More info here: https://docs.microsoft.com/en-us/azure/traffic-manager/traffic-manager-overview
  • Azure load balancer
    Load balancer can be done at network level by using Azure load balancer. Job of Azure load balancer is to direct traffic within region. Suppose when request comes for a website at port 80, then Azure load balancer passes it on to one of the several virtual machines which configured with same code base. So requests are handled by multiple servers and speed up the processing. Refer to the image at the end of the article.
  • Internal load balancer
    This is similar to Azure load balancer but the only change is that this distributes requests which come from INSIDE Azure between services which are also part of Azure. Let's continue the same example used in Azure load balancer in the above second point, where the request comes for a website at port 80 and is processed by one of the several virtual machines which was configured with the same code base.

    Now, this code base might need to communicate with the SQL database and it makes a request over port 1433 to internal load balancer which in turn routes the request to one of several virtual machines which are hosting the SQL Server.

Image source: https://blogs.msdn.microsoft.com/brunoterkaly/2014/07/23/fundamentals-of-azure-internal-load-balancers-ilbs/

Up Next
    Ebook Download
    View all
    View all