Tuesday 20 November 2012

Hosting Web Application using Azure IaaS capabilities - Part 4


In previous posts we had completed creating Web Server, Database Server and installed a sample application. We also created image from the Web Server. In this post, I plan to show creating four VMs using custom images created from Web Server and load balance all of them.

By looking at this, we can compare with the Azure PaaS environment by deploying a Web role with more then one instances. While accessing the url of the Web Role, the request will be load balanced across the instances. But deploying database server on Web Role will not be possible, instead we can to use SQL Azure Database or an SQL Server located in on-premise or an Azure VM.

Creating Virtual Machines from the Custom Image

We have created image from the VM which is customized as per our needs. Now we can use this image to host multiple instances of VMs.

Step 1: Create a new VM from the custom image created in previous section and add the same into the cloud services created in the first part. The following screenshots shows the walkthro’.


Selecting the custom image (Fig - 3)


Connecting to the database server (Fig - 5)




As we see in these images, I created a VM from the custom image which was created in previous sections (Fig - 3). I also configured by connecting the existing Northwind database server (Fig - 5), so both will sit under same cloud service and the database server can be connected from the NorthwindFE.

In this same way, we can use this custom image for creating multiple VMs. For this POC, I wish to create four instances in which one from Management portal (just created) and three from power shell command (below steps).

Step 2: I use power shell command for creating one instance (NorthwindFE2) and add to the cloud service (WebFarm) as below.
Set-AzureSubscription -SubscriptionName "Subscription-1 Introductory special" -CurrentStorageAccount azurevpntest

$iisimage = 'NorthwindFEImage'

$iisvm = New-AzureVMConfig -Name 'NorthwindFE2' -InstanceSize Small -ImageName $iisimage -AvailabilitySetName 'NorthwindAvSet'  |
 Add-AzureProvisioningConfig -Windows -Password 'password@123'

# Create VMs and add with existing cloud service
New-AzureVM -ServiceName 'WebFarm' -VMs $iisvm

In this script, I have created a VM under existing cloud service WebFarm But we still not configured both the VMs (NorthwindFE1 and NorthwindFE2) to be load balanced (one created from Management Portal and another from Power Shell just now). I am also planning to create another two instances from Power Shell and configure each of them load balanced.

Note: WebFarm is the cloud service we created previously with two VMs NorthwindBE and NorthwindFE. Later, we created image out of NorthwindFE. Now we are creating VMs from the image created under the same cloud service WebFarm.

Step 3: Below script is used for creating another two instances NorthwindFE3, NorthwindFE4 with configuring them under load balance.

Once the VMs created, I am getting the existing VMs NorthwindFE1, NorthwindFE2 and adding them under load balance.


Set-AzureSubscription -SubscriptionName "Subscription-1 Introductory special" -CurrentStorageAccount azurevpntest

$iisimage = 'NorthwindFEImage'

#$iisvm = New-AzureVMConfig -Name 'NorthwindFE2' -InstanceSize Small -ImageName $iisimage -AvailabilitySetName 'NorthwindAvSet'  |
# Add-AzureProvisioningConfig -Windows -Password 'password@123'

# Adding 3rd VM
$iisvm1 = New-AzureVMConfig -Name 'NorthwindFE3' -InstanceSize Small -ImageName $iisimage -AvailabilitySetName 'NorthwindAvSet'  |
    Add-AzureEndpoint -Name web -LocalPort 80 -PublicPort 80 -Protocol tcp -LBSetName web -ProbePath '/' -ProbeProtocol http -ProbePort 80 |
 Add-AzureProvisioningConfig -Windows -Password 'password@123'

# Adding 4th VM
$iisvm2 = New-AzureVMConfig -Name 'NorthwindFE4' -InstanceSize Small -ImageName $iisimage -AvailabilitySetName 'NorthwindAvSet'  |
    Add-AzureEndpoint -Name web -LocalPort 80 -PublicPort 80 -Protocol tcp -LBSetName web -ProbePath '/' -ProbeProtocol http -ProbePort 80 |
 Add-AzureProvisioningConfig -Windows -Password 'password@123'

# Create VMs and add with existing cloud service
New-AzureVM -ServiceName 'WebFarm' -VMs $iisvm1, $iisvm2

# Adding 1st VM into Loadbalence
Get-AzureVM -Name NorthwindFE1 -ServiceName WebFarm |
    Add-AzureEndpoint -Name web -LocalPort 80 -PublicPort 80 -Protocol tcp -LBSetName web -ProbePath '/' -ProbeProtocol http -ProbePort 80 |
    Update-AzureVM

# Adding 1st VM into Loadbalence
Get-AzureVM -Name NorthwindFE2 -ServiceName WebFarm |
    Add-AzureEndpoint -Name web -LocalPort 80 -PublicPort 80 -Protocol tcp -LBSetName web -ProbePath '/' -ProbeProtocol http -ProbePort 80 |
    Update-AzureVM
Note: Now, I have completed creating four VMs one from both Management Portal and three from Power Shell to show the different options of creating VMs. I also showed creating one VM without adding to load balance and configuring it after. So all those are for just to show the options, we can choose one of them (Ex: - add all those VMs using power shell at a single run as a whole).

Step 4: Once all those completed successfully, navigate to the portal and verify the VMs properties and the endpoint settings.


Step 5: Now open the browser and access the url of the application. It must show the application as below.


As we see, the browser shows the response come from NorthwindFE4 (computer name). We can try to navigate other pages in the GridView and do some operation, it must work properly.

When we access the same url from another browser window or from other systems, it must get the response from any instances among the four. The request will be diverted based on the load on each of the instances.

Removing a VM from the cloud services

We can remove a particular VM by deleting the same Management Portal or can use power shell script.
# Removing NorthwindFE4 VM from the cloud service WebFarm
Remove-AzureVM -ServiceName WebFarm -Name NorthwindFE3

# Getting this Disk Name associated with the VM
$VMDisks = Get-AzureDisk | Where {$_.AttachedTo.RoleName  -eq  'NorthwindFE3'}

$VMDisks | foreach {

# Deleting the disk and VHD associated for the VM
Remove-AzureDisk -DiskName $VMDisks.DiskName -DeleteVHD

## To delete only the disk associated for a VM
#Remove-AzureDisk -DiskName $DiskName

}

From the last four posts, We understand how to create a Database server nad Web server under a same cloud service and create image from Web Server. We also used the image for creating multiple instances. This help us to host a custom application using IaaS feature with out creating a VPC on cloud.

The other links on Hosting Web Application using Azure IaaS capabilities:
  1. Hosting Web Application using Azure IaaS capabilities - Part 1
  2. Hosting Web Application using Azure IaaS capabilities - Part 2
  3. Hosting Web Application using Azure IaaS capabilities - Part 3
  4. Hosting Web Application using Azure IaaS capabilities - Part 4

0 Responses to “Hosting Web Application using Azure IaaS capabilities - Part 4”

Post a Comment