Thursday, July 9, 2015

PowerShell and Azure IaaS - Managing global traffic using Azure traffic manager

With Azure Load balancer, you can now have high availability and consistency for the Virtual machines that are in a single region, but if you are looking for a solution that works across VMs deployed globally based on flexible policies like Round-robin, failover, performance etc. then you need to use the load balancer with the combination with traffic manger as given in the image below.

The traffic manager works by applying a policy engine to DNS queries for the domain names of the resources. By implementing a traffic manager it will be possible to provide automatic failover when a cloud service in a location goes down. It also helps improve the responsiveness of the resources by redirecting the user to the closes resource available to the location where the resource is accessed from.

If you have a requirement for zero downtime installations and rollbacks, you can achieve this by bringing down the resources in one location and performing an update or installation on that cloud service and the traffic manager will take care of routing the user to an available resource till the one which was down is ready. This also helps in making complex installations/ upgrade scenarios much easier.

For the sample scenario, I’ve deployed 2 cloud services each containing 2 VM across locations that are load balanced using an Azure load balancer as in the image given below.




To automate the management of profiles we’ll use the New-AzureTrafficManagementProfile cmdlet as given below.

New-AzureTrafficManagerProfile `
            -Name WebScaleTM01 `
            -DomainName WwebScaleTM01.trafficmanager.net `
            -LoadBalancingMethod FailOver `
            -MonitorPort 80 `
            -MonitorProtocol Http `
            -MonitorRelativePath "/" `
            -Ttl 30

The load balancing method is defined as FailOver and this will the criteria to distribute the connection. Other possible options are Performance and RoundRobin. For more details on the Add-AzureTrafficManagerProfile cmdlets refer to the documentation here https://msdn.microsoft.com/en-us/library/azure/dn690246.aspx

The next step after creating the profile is to add the endpoints to the profile. To do that we can make use of the Add-AzureTrafficManagerEndpoint cmdlet as given below and update the profile using the Set-AzureTrafficManagerProfile cmdlet.

New-AzureTrafficManagerProfile `
            -Name WebScaleTM01 `
            -DomainName WwebScaleTM01.trafficmanager.net `
            -LoadBalancingMethod FailOver `
            -MonitorPort 80 `
            -MonitorProtocol Http `
            -MonitorRelativePath "/" `
            -Ttl 300 | `
            Add-AzureTrafficManagerEndpoint -DomainName webscalecs01.cloudapp.net -Type Any -Status Enabled | `
            Add-AzureTrafficManagerEndpoint -DomainName webscalecs02.cloudapp.net -Type Any -Status Enabled | `
             Set-AzureTrafficManagerProfile

You can check the status of the traffic manager by logging into the old Azure portal and see the endpoints added to it. Also test the functionality by bringing down one cloud service and see that the traffic manager automatically redirects to the healthy cloud service.




No comments: