Sunday 22 March 2015

Creating VM through PowerShell Part II (Custom Create)

This is continuation of my previous article “Creating VM through PowerShell Part I (Quick Create).

In this article, we will see how to create Virtual Machine through Azure PowerShell.

Following are the syntax to be used to deploy “Custom Create” VM in Microsoft Azure through Azure PowerShell:

$adminUser = "Username"
$password = "Password"
$serviceName = "Service_Name"    # ServiceName means CloudService name e.g. “squons”
$location = "Location_Name"    # In which location you want to deploy your VM e.g. "West US"
$size = "Size_Name"                        # Size/Tier name e.g. “Small/Medium/Large” etc
$vmName = "VM_Name"            # Name or Virtual Machine e.g. “SQUONS-VM1”

$imageFamily = "Windows Server 2012 R2 Datacenter"
$imageName = Get-AzureVMImage |
                                                             where { $_.ImageFamily -eq $imageFamily } |
                                                             sort PublishedDate -Descending |
                                                             select -ExpandProperty ImageName -First 1

New-AzureVMConfig -Name $vmName `
                                     -InstanceSize $size `
                                     -ImageName $imageName |

Add-AzureProvisioningConfig -Windows `
                                                   -AdminUsername $adminUser `
                                                   -Password $password |

Add-AzureDataDisk -CreateNew `
                                  -DiskSizeInGB 10 `
                                  -LUN 0 `
                                  -DiskLabel "data" |

Add-AzureEndpoint -Name "RDP" `
                                  -Protocol tcp `
                                  -LocalPort 3389 `
                                  -PublicPort 49913 |

New-AzureVM -ServiceName $serviceName `
                          -Location $location

Following figure depicts the PowerShell command used to deploy VM in Microsoft Azure:


To check the VM status through Azure PowerShell, use the below command:

PS C:\> Get-AzureVM


To know more about step by step of each and every component used while deploying VM, you can refer to http://squons.blogspot.in/2015/03/creating-virtual-machine-in-microsoft.html.

To see how to "Quick Create" VM through Azure PowerShell, goto http://squons.blogspot.in/2015/03/creating-vm-through-powershell-part-i.html.

Creating VM through PowerShell Part I (Quick Create)

There are many ways to create VM in Microsoft Azure as listed below:

  1. Azure Management Portal
  2. Azure PowerShell
  3. Azure cross-platform command line tools like xplat-cli
  4. Management REST-API

I have already made separate article for VM creating through Azure Management Portal, which you can refer to http://squons.blogspot.in/2015/03/creating-virtual-machine-in-microsoft.html.

In this article, we will see how to create Virtual Machine through Azure PowerShell.

But what do you mean by Azure PowerShell.

To understand this, let’s first understand what Microsoft Windows PowerShell is.

Windows PowerShell is a .NET framework which help us to automate and manage configuration through command line shell or scripting language.

Likewise, we have Azure PowerShell which is powerful scripting tool used to automate, control, deploy and manage your workloads in Microsoft Azure.

To install and configure Azure PowerShell, go to http://azure.microsoft.com/en-in/documentation/articles/powershell-install-configure/.

In this article, we will be seeing how to create Virtual Machine through Azure PowerShell.

Following are the syntax to be used to deploy “Quick Create” VM in Microsoft Azure through Azure PowerShell:

$adminUser = "Username"
$password = "Password"
$serviceName = "Service_Name"     # ServiceName means CloudService name e.g. “squons”
$location = "Location_Name"    # In which location you want to deploy your VM e.g. "West US"
$size = "Size_Name"                    # Size/Tier name e.g. “Small/Medium/Large” etc
$vmName = "VM_Name"   # Name or Virtual Machine e.g. “SQUONS-VM1”
$imageFamily = "Windows Server 2012 R2 Datacenter"
$imageName = Get-AzureVMImage |
                                                            where { $_.ImageFamily -eq $imageFamily } |
                                                            sort PublishedDate -Descending |
                                                            select -ExpandProperty ImageName -First 1
New-AzureQuickVM -Windows `
                                    -ServiceName $serviceName `
                                    -Name $vmName `
                                    -ImageName $imageName `
                                    -AdminUsername $adminUser `
                                    -Password $password `
                                    -Location $location `
                                    -InstanceSize $size


Following figure depicts the PowerShell command used to deploy VM in Microsoft Azure:



To check the VM status through Azure PowerShell, use the below command:

PS C:\> Get-AzureVM


Here it ends with the article.

Below I have mentioned about an error which I encountered while deploying VM through Azure PowerShell.



To overcome this error, I used the following command:


Syntax:

PS C:\> Set-AzureSubscription –SubscriptionName "Sub_Name" -CurrentStorageAccount "Storage_Name"

To see how to "Custom Create" VM through PowerShell, go to http://squons.blogspot.in/2015/03/creating-vm-through-powershell-part-ii.html.


Saturday 21 March 2015

Types of Disks in Microsoft Azure

In Microsoft Azure whenever a Virtual Machine is deployed it is attached with some sought of disk that is in the form of VHD associated with Virtual Machine.

There are number of Disk types available with Azure Virtual Machine, in which some disk are attached along with the Virtual Machine when it is created and some can be added or removed later as and when required.

Types of Disk available in Azure are;

  1. Operating System Disk
  2. Temporary Disk
  3. Data Disk

(Note: This article talks about types of disks and not types of storage i.e. standard vs. premium storage)

Let see all the types of disk one by one.

1. Operating System Disk

Operating System Disk is a VHD which is attached by default with the Virtual Machine and it is labeled as C: drive which is a SATA drive. Default caching policy on the operating system disk is Read/Write. For performance sensitive applications it is recommended to use Data Disk instead of Operating System Disk. Whenever you add new disk to the Virtual Machine, make sure that the default caching policy should be selected as None.

Note: Maximum capacity of this disk is 127 GB. Moreover, its three copies are created to provide availability and if it is configured with Geo-Replication then its copies can be replicated between multiple sites.

2. Temporary Disk

As the name explains itself what kind of disk it is, it is not permanent/persistent disk which is attached with the Virtual Machine whenever it is created. It takes the drive letter D: in the VM. We should not store any data which we will be referring in future as its data is going to be lost whenever the VM is restarted or when there is any failure in the datacenter where it is deployed meets up with some hardware failure. So the VM is recreated on new host using its disk but the Temporary disk is not retained.
Temporary Disk can be utilized by storing the temporary files such as tempdb and/or Buffer Pool Extensions with the D Series VM where SSD is provided as a temporary disk with these series of VM’s.

Note: On Linux VM, the disk is typically /dev/sdb and is formatted and mounted to /mnt/resource by the Azure Linux Agent. 

3. Data Disk

A data disk is a VHD which is attached to Virtual Machine so as to save Application data or the data which you need to keep within VM. It is registered in VM as SCSI drive, which can be assigned any drive letter you want to keep. The number of Data disk that can be attached with the VM depends upon the tier/size of Virtual Machine you have deployed. Each Data disk has maximum capacity of 1 TB.

Note: To find more disk sizing and IOPS about the VM’s refer to this link https://msdn.microsoft.com/library/azure/dn197896.aspx

Types of Disk in Virtual Machine are demonstrated below:

I have deployed one test machine in Microsoft Azure named as “SQUONS-VM1” to carry out the demonstration.

The disk management console of my VM is depicted below, which has 127 GB Operating System Disk (C: drive) and 135 GB Temporary Disk (D: drive).


Same can be viewed on File Explorer.



Let’s begin with adding Data Disk into VM.

Following are steps to add Data Disk to VM:

1. Go to Virtual Machine console in Azure and select VM on which you need to attach Data Disk. Then on Command bar click on Attach and select Attach empty disk.



2. Then it will open a window, which contains your VM name and Storage Location & File Name. Storage Location & File Name are assigned automatically. Mention the Size of disk you want to attach to VM in GB and select “None” in Host Cache Preference.
Click.



3. Now it will start adding disk to your VM. 


4. Now take the RDP of your VM and verify whether the disk has been attached to your VM or not under disk management.
You will find a raw disk (Disk 2) is attached to your VM which not initialized and Unallocated.


5. Next we will initialize the disk, make it online and allocate it with some drive letter.

Follow the below steps to initialize your disk and allocate drive letter to disk:

   a.    Right click on Disk 2 and select Initialize Disk.


   b.    Make sure the Disk 2 is checked and select the partition style.
           Click OK.


  c.   Now Disk 2 becomes Online, Next step is to create a volume using the unallocated disk space.
          Right click on unallocated disk space and select New Simple Volume.



  d.  Click Next.


  e.  Here, you need to specify the disk size to be created as Volume (Drive) in MB.
         Click Next.


  f.  Assign the drive letter to the new Volume (Drive).
         Click Next.


  g.  Now format the volume (Drive) with NTFS file system and provide the label name for your Volume (Drive).
         Click Next.


  h.  Click Finish.


6. Now you can verify in disk management or file explorer whether the disk is Online and Allocated with drive letter or not.



Next moving further, let’s see how to detach Data Disk from VM.

Following are the steps to detach Data Disk from the VM:

1. Go to Virtual Machine console in Azure and select VM on which you need to detach Data Disk. Then on Command bar click on Detach Disk.


2. One window will open, wherein you need to select the disk name from the Attached Disks drop down menu which needs to be detached.
Click.

3. It will detach the Data Disk from the VM.


4. To verify the same, take the RDP of your VM from which you have detached the Data Disk and go to disk management or Windows explorer.



Note: In the process of attaching and detaching the Data Disk from Virtual Machine, your VM doesn’t restart.




Sunday 15 March 2015

Creating Virtual Machine in Microsoft Azure

In this blog we will walk-through creating Virtual Machine in Microsoft Azure.

Before starting with it, if you are just beginning with Microsoft Azure and haven’t registered with Azure then click on http://azure.microsoft.com/en-us/ to registered yourself and get Microsoft Azure trial for a month.

Once you are done with Azure signup and moving forward to explore Microsoft Azure, then go to https://manage.windowsazure.com/ for Azure Management portal.

So let’s begin with creating Virtual Machine in Azure.





Following are the steps to be followed to create new Virtual Machine on Microsoft Azure.

  1. Click New on the left bottom of the portal i.e. on Command bar.



  2. Select Compute then select Virtual Machine as we are creating new VM. Here we have two options to create Virtual Machine, wherein

      a. We select From Gallery because it provides the advanced option to create Virtual Machine.

      b. We have Quick Create, which is used to create Virtual Machine instantly as the name depicts without going through the advanced option. We will be having a look at Quick Create option at the end.
      Note: One cannot deploy Virtual Machine in the Virtual Network if he/she is using Quick Create option.

      Further article talks about creating VM using From Gallery, at the end of the blog I have talked about creating VM using Quick Create.

      I will be making a separate blog for Microsoft Azure Virtual Network, so keep posted.




  3. Choose an image i.e. an Operating System of which you want to create a Virtual Machine from the list of available images. Click arrow to continue.



  4. Now it will ask you to:

    1. a. Select the version release date of image you have chosen.

      b. Provide a Virtual Machine Name to your Virtual Machine which will be the hostname for the Virtual Machine.

      c. Select the Size of the Virtual Machine that you want to deploy with the help of drop down option which consist of range of combination of CPU Core and RAM according to your requirement

      d. Provide credential i.e. Username and Password that you will be using to login into the Virtual Machine. Click arrow to continue.




  5. Here you will configure following things: 

    1. a. You need to select the Cloud Service. Here you can select existing cloud service or if nothing exists you can leave drop down option as Create a new cloud service and create a new one by mentioning the cloud service name under the Cloud Service DNS Name. In short, it provides a namespace in Azure that leverage VM to be accessed from anywhere and ease to manage/configure/scale/monitor the component deployed on this service.

      b. Select Region/Affinity Group/Virtual Network which defines where (location) you actually want to deploy your virtual machine. Here with the Region, Affinity Group and Virtual Network is associated because whenever Affinity Group or Virtual Network is created that is linked with the region.
      Note: Affinity Group as the name suggests, it leverage us to group Azure services to optimize performance where all services and the Virtual Machines within an affinity group will be located in the same region. Here performance is optimized by placing the physical resources close to each other in the datacenter as possible.

      c. Select the Storage Account which is a secure account that provides access to Azure storage services and unique namespace for your storage resources. Here initially you need to create a fresh storage account later on you can point it to your existing storage account.

      d. Next you can set Availability Set for your Virtual Machine which is used when you are dealing with SLA and need to provide high availability of Virtual Machine even if there is a hardware failure in Microsoft Azure. Moreover it also leverages to scale up & scale down automatically depending upon the demands which grows or shrink and Azure charges only for extra resources that is consumed during peak. This is achieved via load balancing mechanism.

      Select None if you don’t want to set Availability Set.

      e. Then we have Endpoints, for understanding can be considered as a firewall which provides an interface to connect to our Virtual Machine which is deployed on Azure. By default RDP and PowerShell protocol ports are opened so as to access Virtual Machine.

      Click arrow to continue.



  6. Here by default Install the VM Agent is checked as it used to install and manage extensions that help you to interact with Virtual Machine and provide Microsoft & Trusted Third Party vendor to enable security, runtime, debugging, management, and other features you can take advantage of to increase your productivity with Azure Virtual Machines.

  7. Note: Don’t remove the tick from checkbox.

    Then we have some Configuration and Security Extensions to provide easy management of Virtual Machine through scripts and manage security capabilities of Virtual Machines by installing Antivirus for Virtual Machine support.

    Select Extensions depending upon the requirements and Click Complete to deploy your Virtual Machine in Microsoft Azure.



  8. After the Virtual Machine is created, it is visible on management portal under Virtual Machine moreover you can also see corresponding Storage Account under Storage and Cloud Service under Cloud Service which was created along with Virtual Machine.



  9. You can see your Virtual Machine status as Running under Virtual Machine Section and now you can access your Virtual Machine by selecting it from the Virtual Machine list and click Connect which is present on Command Bar.



  10. It will download a Remote Desktop Protocol file; open that file and click Connect to continue.



  11. Enter the Credentials for the administrative account on the virtual machine (as specified in steps no 4), and then click OK.  And Click Yes to verify the identity of the virtual machine.






  12. Ready to work with your Virtual Machine created in Microsoft Azure.
         

As promised earlier let’s look at how to create VM using Quick Create option.

Quick Create

To configure Quick Create Virtual Machine follow below snapshot, where you just need to mention the DNS name, Image to be used, Size of Virtual Machine, Credentials and Region/Affinity Group. Click Create A Virtual Machine to deploy your Virtual Machine.



In Quick Create, we cannot use the existing DNS name and also the Virtual Network to deploy the Virtual Machine.












Sunday 8 March 2015

Scaling Up/Down Microsoft Azure Virtual Machine

In our day to day activity we come across to a situation where we need to increase or decrease CPU/Memory depending upon the requirements.

So what if the same situation arises in Windows Azure, Can we modify Virtual Machine? Can we increase or decrease the CPU/Memory as and when required? Will it affect the state of Virtual Machine?

Here I have my standard A1 tier VM named as ‘squons-vm1’ in Azure, which is currently having 2 CPU cores and 3.5 GB memory as you can see in below figure.




I have taken RDP of my VM, depicting the CPU/RAM allotted to VM.


Now I will increase the size of Virtual Machine to 4 CPU cores and 7 GB memory from VM configure tab.
Following figure describe the configuration tab which is accessible through Virtual Machines list by clicking on desired VM name whose configuration needs to be changed.




As soon as after changing the VM size from A2 VM when you click on save button present on command bar it will display a message that Virtual machine could be restarted to take affect with respective changes made to the Virtual Machine.



Click yes to continue so that changes get applied on your VM and which will result in restart of VM or Click No to avoid changes getting applied.
For verifying the VM, I have taken RDP of my VM so as to ensure whether it remain intact or restarted.
After clicking yes you will find that the RDP session is lost and the VM is restarted.




After sometime you can able to take RDP of your VM and find upgraded VM with new configuration.
Following figure depicts the VM with new configuration.




Now let’s see what happen when we downgrade the Virtual Machine from current A3 standard VM to A1 standard VM which holds 1 CPU core and 1.75 GB memory.




Again go to respective VM configure tab and decrease the Virtual Machine size to A1 and click on save button so as to update the VM with changes.




Click Yes to continue so that changes get applied on your VM or Click No to avoid changes getting applied.
For verifying the VM, I have taken RDP of my VM so as to ensure whether it remain intact or restarted.
The respective VM gets restarted as soon you click Yes to continue and the RDP session is disconnected as you can find in below figure.




After sometime, take the RDP of the Virtual Machine and check the VM configuration. You will find that your Virtual Machine is degraded to A1 VM configuration as depicted below.




Note: The same kind of behaviour is seen with Amazon AWS, whereas Microsoft is coming with hot add and hot plug feature in Windows Threshold Server that is going to be released soon which allows adding memory and CPU on the go while Virtual Machine is running without affecting the VM process. Hence we can expect in future, Windows Azure to adopt the new Windows Threshold as a base to overcome the above mentioned problem as it is currently working on Windows 2012 Server.