Overview of the course
What is a Virtual Machine?
Creating and Connecting to Azure VMs
Scaling Azure Virtual Machines
Design and Implement VM Storage
Configure Monitoring & Alerts for Azure VMs
Azure Resource Manager Virtual Machines
Virtual Machines are a very foundational and fundamental resource in Cloud Computing. Deploying virtual machines gives you more flexibility and control over your cloud infrastructure and services, however, it also means you have more responsibility to maintain and configure these resources. This course gives you an overview of why use virtual machines as well as how to create, configure, and monitor VMs in Azure Resource Manager.
Azure Resource Manager Virtual Machines: What You'll Learn
|Lesson||What you'll learn|
|Overview||Overview of the course and the Learning Objectives|
|What is a Virtual Machine?||Understand what are Azure Virtual Machines and what workloads are ideal for VMs|
|Creating and Connecting to Azure VMs||Learn to deploy Windows and Linux VMs as well as how to connect to these VMs|
|Scaling Azure Virtual Machines||Understand VM scaling, load-balancing, and Availability Sets in Azure Resource Manager|
|Configuration Management||Understand the basic concepts of Desired State Configuration and the options available to Azure VMs|
|Design and Implement VM Storage||Gain an understanding of the underlying Storage options available to VMs as well as Encryption|
|Configure Monitoring & Alerts for Azure VMs||Learn to monitor VMs in Azure Resource Manager as well as configure alerts.|
|Summary||Course summary and conclusion|
GitHub Code Repository
By now we’re actually quite familiar with VM Extensions. Though we’ve focused mostly on Configuration Management extensions there are many more as we’ve seen in the extension gallery and online as the number continues to grow. One of the most common extensions is the Azure VM agent extension which is deployed with newly provisioned Windows VMs. It allows Azure to query information about a VM to report status and other data about the VM state in addition to running other VM extensions. The VMAccess extension is an extension that allows us to do such things such as “Reset” our VM password from the Azure Portal or reset our SSH keys to our Linux VMs.
One other powerful VM Extension is the Custom Script Extension we saw earlier in the extension gallery. This VM extension once installed allows you to simply author a piece of code, place it on a storage account and have the VM execute this code locally. Let’s try this now.
Here we have our good’ole ExtensionVM windows server, and on this VM I’ve attached a Data Disk. Let’s connect to the machine a have a look. If we open File explorer we have our expected OS Disk which is the C:\ drive and D:\ drive for temp storage, but where is our other attached Data Disk. Let’s open Disk Management. We get a message saying that we must initialize a disk before the Logical Disk Manager can access it. Let’s hit Cancel. Let’s go back to Server Manager and navigate to File and Storage Spaces -> Storage Pools. As you can see we have “Primordial” storage available to us which is free space not yet converted to a useable Volume. This is a great opportunity to deploy a Custom VM Extension that will execute a custom script to turn this available space into a useable volume.
Back in the PowerShell ISE, I’ve written a short 4-line script called “InitializeDataDisk.ps1” to do just that. We first need to get the available disk which can be Pooled as we saw in Server Manager. We then need to create a new StoragePool called “StoragePool1” from our “StorageSpaces.” After that we create a new VirtualDisk which will be a Fixed, Simple disk which we’ll call “DataDisk”. Finally we’ll Initialize this new VirtualDisk and assign it a drive letter in addition to formatting this disk resulting in a useable NTFS Volume. Let’s go back to our Storage accounts and add this script to the same scripts container we created earlier. We click “Upload” and simply upload our script from our local computer.
All that’s left to do is write the PowerShell code to deploy our Custom Script Extension and invoke our InitializeDataDisk.ps1 script. Back in our PowerShell ISE window I want to show you a quick command to list VM Extensions. Let’s run Get-Command on the AzureRM.Compute module filtering on “Set” commands that end in “Extension”. There are several VM extensions we can see here including the VMAccessExtension, BginfoExtension, SqlServerExtension, etc. But we’re interested in the CustomScriptExtension.
The first thing we do is define our set of variables. We have the $resourceGroupName of our VM, our $vmName, the name we’d like to call the script stored in $extensionName, the $location of our VM, the $storageAccountName and $containerName where our script lives, and finally the script name itself.
Next all we need to do is deploy the Custom Script Extension using these values with an Azure PowerShell cmdlet called “Set-AzureRmVMCustomScriptExtension.” We’ve filled out the values using the variables we’ve defined above, but we also have an optional parameter called “Run” which we used to specify the actual command-line to use. This means that we could have passed different arguments to the command as specified by the “Run” parameter. Also know that the Set-AzureRmVMCustomScriptExtension has another ParameterSet that allows you to use a “-FileURI” parameter as opposed to “-FileName” which let’s you pull scripts from anywhere on the internet including a GitHub repo which is backed by source control. Let’s run this now.
Great! We have a success message from our PowerShell window. We may also Get the status of any deployed extension by calling “Get-AzureRmVmExtension” like so. Let’s also take a look in the Portal under Extensions and we see our new Custom Extension named “InitializeDiskScript” is successfully deployed. We can also use the dropdown menu to remove or uninstall this extension at any time or use the Remove-AzureRmVMExtension cmdlet.
Let’s hop on over to our VM to see if our InitializeDataDisk script did what we wanted. Let’s open up Disk Manager. And there we are, we have an initialized data disk on Volume F ready to use. Also in Server Manager when we can see that we have a new Storage Pool and Virtual Disk called DataDisk. And finally, opening up file explorer shows our new F:\ Drive.
Just like the DSC Extension, the VM Custom Extension stores log files in C:\WindowsAzure\Logs\Plugins\Microsoft.Compute.CustomScriptExtension). In the CustomScriptHandler file we can see the extension downloading the PowerShell script and executing it successfully. It even set the proper PowerShell ExecutionPolicy to Unrestricted for us to run our script file. Also, the extension downloads our script locally to the machine which is stored at C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtensions\<version>\Downloads folder.
This concludes our demo. If you’ve made it this far, congratulations! You now have a very good understanding of Configuration Management in Azure as well as Implementing and deploying VM Extensions. We’ve spent a fair amount of time back and forth between the Azure Portal and PowerShell, so rest assured you have a very well-rounded view of how these Azure features and components work.
Chris has over 15 years of experience working with top IT Enterprise businesses. Having worked at Google helping to launch Gmail, YouTube, Maps and more and most recently at Microsoft working directly with Microsoft Azure for both Commercial and Public Sectors, Chris brings a wealth of knowledge and experience to the team in architecting complex solutions and advanced troubleshooting techniques. He holds several Microsoft Certifications including Azure Certifications.
In his spare time, Chris enjoys movies, gaming, outdoor activities, and Brazilian Jiu-Jitsu.