Thursday, July 9, 2015

DevOps and PowerShell in Azure IaaS - Adding virtual machines to Azure load balancer set

With Azure IaaS, it’s very easy to create and manage virtual machines and cloud services. With Azure high availability and disaster recovery are of high importance for infrastructures. High availability and performance in Azure IaaS can be achieved by having a load balancer. The Azure load balancer is a layer-4 (TCP, UDP) type load balancer that distributes incoming traffic among the healthy virtual machines in the set.

In order to load balance the virtual machines, they need to be in the same cloud service. In this post we’ll see how to add a load balancer to the 80 port of the virtual machines that are deployed to the same cloud service and see how that results in distributing traffic to the machines in the set that are healthy. For creating the virtual machines to the same cloud service, we can use the cmdlet.

New-AzureVMConfig -Name WebScaleVM01 `
    -InstanceSize ExtraSmall `
    -ImageName [VM_IMAGE_NAME] | `
        Add-AzureProvisioningConfig -Windows `
                -AdminUsername [ADMIN_USER] `
                -Password [ADMIN_PASSWORD] | `
        Add-AzureDataDisk -CreateNew `
                -DiskSizeInGB 200 `
                -DiskLabel "datadisk1" `
                -LUN 0 | `
        Add-AzureEndpoint -Name "PowerShell" `
                -Protocol TCP `
                -LocalPort 5986 `
                -PublicPort 5986 | `
        New-AzureVM -ServiceName [YOUR_CLOUD_SERVICE_NAME]

You can create the second virtual machine in the same way. Make sure that the VMs are added to the same cloud service. The final outcome will result like the image given below.

Next we’ll add a load balanced endpoint and add the virtual machines to the set. The Add-AzureEndpoint cmdlet can be used to add an endpoint to the virtual machine. To add the endpoint use the cmdlet as

Get-AzureVM -ServiceName WebScaleVM01 | `
Add-AzureEndpoint -Name Http -LocalPort 80 -PublicPort 80 -LBSetName WebScaleLBDemo -DefaultProbe -Protocol tcp | `
Update-AzureVM

To add the other virtual machines in the cloud service to the load balanced set, replace the name of the VM in the above cmdlet and run it again. You can check the details on the Azure portal by looking into the settings of the VMs.





No comments: