Deploying Virtual Machines in Microsoft Azure

Deploying Virtual Machines in Microsoft Azure

Congratulations! If you’ve made it this far in the Microsoft Azure Series, you’re finally ready to start deploying virtual machines in Microsoft Azure. Let’s face it, the whole series has led up to this post because most of you are probably looking at getting started in Azure with the virtual machine. It’s familiar and can house applications, databases, data or whatever you’ve been housing in in your on premises data center. If you’re trying to benchmark Azure with you’re own data center apps, virtual machines are probably where you’ll spend your time. As you learn more about the the platform, Azure’s PaaS offerings might be more heavily used to prevent you from having to manage those pesky operating systems but for now we’re focusing on the VM.

Deploy

In the new portal (formerly called the ARM portal) click the “New” button. Select Virtual Machines and then select your Featured App. The feature app an contain bare operating systems in a variety of versions and flavors.

AzureVM_1

Once you’ve selected an app, review the terms and select a deployment model. We’re focusing on the new portal for this series primarily, so choose resource manager.

AzureVM_2

Now a new set of “blades” opens and we’ll need to enter some information.

NOTE: These options might vary a bit depending on the location and the operating system.

Enter a server name, and a disk type of either SSD or HDD. Then enter a username for the person who will have administrator access on the box. If you choose a linux distribution you may need to select an authentication type so that you can use an SSH key instead of a password. As with all Azure resources, choose a resource group, and then finally select a location.

AzureVM_3_2

The next screen will show you some recommended “t-shirt” sizes for the virtual machine. Select the size that is appropriate for your workload.AzureVM_4

On the next blade we need to select some placement information. Select the disk type, storage account, VNet and subnet, public IP address if needed and a security group. You can also enable monitoring for this machine. Monitoring will allow you to track information about the performance of the virtual machine and possibly alert based on those metrics. Another cool thing we can do on this blade is add a virtual machine extension. Extensions allow you to have some automated tasks performed on your virtual machine like install the Chef Client. To learn more about extensions check out https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-extensions-features/. You can finally select the availability group that the machine should belong with so that your app can withstand an outage of a singe Azure zone.

AzureVM_5

Review the settings and click create.

AzureVM_6

 

In a few moments your machine will be built and you’ll be able to RDP or SSH into it with the credentials provided in the setup screens. If you are unable to login, check to make sure your subnet is reachable and that no network security groups are blocking the RDP or SSH traffic to the new machine. Install your apps and have fun with your new virtual machine.

Deploy from PowerShell

If you’re one of those people who love to do their work from the command line, or you want to programmatically deploy your servers for an application pipeline or something, you can also deploy your virtual machines through PowerShell. Here is some sample code to get you started.

The code below requires you to enter in a few variables and will deploy a virtual machine in the Azure Resource Manager (new) Portal. It requires you to login and enter local administrator credentials for the machine. You will be prompted to enter these two sets of credentials unless you modify the below code. You may also download this code from my git repo: https://github.com/theITHollow/AzureRMDeployVM

#Azure Account Variables
$subscr = "AZURERM"
$StorageAccountName = "AZURERMSTORAGEACCOUNT"
$StorageResourceGroup = "AZURESTORAGERESOURCEGROUP"

#set Azure Subscriptions and Storage Account Defaults
Login-AzureRmAccount
Get-AzureRmSubscription -SubscriptionName $subscr | Select-AzureRmSubscription -WarningAction SilentlyContinue
$StorageAccount = Get-AzureRmStorageAccount -name $StorageAccountName -ResourceGroupName $StorageResourceGroup | set-azurermstorageaccount -WarningAction SilentlyContinue

##Global Variables
$resourcegroupname = "AZURERESOURCEGROUPNAME"
$location = "AZURERMLOCATION"

## Compute Variables
$VMName = "AZURERMVIRTUALMACHINENAME"
$ComputerName = "AZUREMACHINENAME"
$VMSize = "AZURERMSIZE"
$OSDiskName = $VMName + "OSDisk"

## Network Variables
$VNetName = "AZURERMVNET"
$Subnet1Name = "AZURERMSUBNET1"
$Interface1Name = $VMName + "_int1"


###########################################################
#Do Not Edit Below This Point                             #
###########################################################

## Network Interface Creation
$PIp1 = New-AzureRmPublicIpAddress -Name $Interface1Name -ResourceGroupName $ResourceGroupName -Location $Location -AllocationMethod Dynamic -WarningAction SilentlyContinue
$VNet = Get-AzureRmVirtualNetwork -name $VNetName -ResourceGroupName $resourcegroupname -WarningAction SilentlyContinue
$Interface1 = New-AzureRmNetworkInterface -Name $Interface1Name -ResourceGroupName $ResourceGroupName -Location $Location -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $PIp1.Id -WarningAction SilentlyContinue

## Create VM Object
$Credential = Get-Credential
$VirtualMachine = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize -WarningAction SilentlyContinue
$VirtualMachine = Set-AzureRmVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate -WarningAction SilentlyContinue
$VirtualMachine = Set-AzureRmVMSourceImage -VM $VirtualMachine -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest" -WarningAction SilentlyContinue
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $Interface1.Id -WarningAction SilentlyContinue
$OSDiskUri = $StorageAccount.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd" 
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -Name $OSDiskName -VhdUri $OSDiskUri -CreateOption FromImage -WarningAction SilentlyContinue
$VirtualMachine.NetworkProfile.NetworkInterfaces.Item(0).Primary = $true 

## Create the VM in Azure
New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $VirtualMachine -WarningAction SilentlyContinue

 

One Response to Deploying Virtual Machines in Microsoft Azure

Leave a reply