Creating and Managing Virtual Machines
This course will show you how to create and manage virtual machines in the Azure ecosystem.
By the end of this course, you'll have gained a firm understanding of the key components that comprise the Azure virtual machine ecosystem. Ideally, you will achieve the following learning objectives:
- How to create and manage virtual machines in the Azure environment.
- How to create and manage VM images, workloads, and more.
- How to monitor your Azure virtual machines.
This course is intended for individuals who wish to pursue the Azure 70-532 certification.
You should have work experience with Azure and general cloud computing knowledge.
This Course Includes
- 59 minutes of high-definition video.
- Expert-led instruction and exploration of important concepts surrounding Azure virtual machines.
What You Will Learn
- The concepts behind VM workloads.
- How to create and manage Azure VM images.
- Azure VM configuration management.
- Azure VM networking.
- How to scale Azure virtual machines.
- How to design and implement Azure VM storage.
- How to monitor your Azure virtual machines.
Hello, and welcome back. In this section, we'll cover configuration management of Azure virtual machines.
This section will deal with three distinct areas of configuration management. Firstly, we'll look at custom script extensions and PowerShell desired state configuration. Next, we'll look at using dedicated configuration management tools such as Puppet. And finally, we'll look at enabling Visual Studio remote debugging, useful if you have a dot NET application running on a VM.
The virtual machine agent is installed by default on both Windows and Linux version machines in Azure, and allows OS-specific extensions to be added to the virtual machine, which can enable powerful configuration possibilities. We'll now look at a couple of these extensions in more detail.
Custom script extensions allow us to download and execute arbitrary PowerShell scripts on a virtual machine. These scripts can do anything, from creating folders in the virtual machine, to downloading and installing software. It's entirely up to you. You can apply the extension when creating the virtual machine, or can retrospectively add it when the virtual machine is running.
We'll now see how to execute a custom script from the portal, but you can also execute this from a PowerShell script itself. To activate the extension on the pre-existing VM, we first navigate to the settings panel, and then choose extensions. We'll be presented with the current extensions, but we can also select add to apply a new one. We'll then see a custom script extension which, in turn, will prompt us for the local PowerShell file and any optional arguments to supply it. Once we select the script, the portal will automatically upload the script into storage before deploying and executing it on Azure. Once we select the script, the portal will automatically upload the script into storage before deploying and executing it on the VM. We can now see that the extension has been added to the virtual machine.
Let's now discuss the second way of executing scripts on the virtual machine: PowerShell desired state configuration. PowerShell desired state configuration, or DSC, is a way in which you can declaratively specify the state of a set of virtual machines, or nodes, as a configuration file that contains a number of resources, and then repeatedly apply that state onto a given virtual machine.
PowerShell DSC supports many different types of resources, some of which are shown here. For example, we could use DSC to ensure MongoDB is installed and configured whenever the script is run, and create a user account with permissions to access the database. You can also create custom resources yourself, through a PowerShell module containing a script manifest on the MOF schema. DSC allows us to repeatedly run the same script, multiple times, safely. It won't reinstall the same component if it's already been applied. DSC will ensure that all of the configuration steps are correctly applied, and will even tell you if the configuration has drifted from what it should be since the last time it was applied.
Local configuration manager is the engine by which DSC facilitates the interaction between resources and configurations. The LCM regularly polls the system, using the control flow implemented by resources, to ensure that the state laid out by the configuration is maintained.
Here's an example DSC PowerShell script. Note the use of the configuration keyword, which has been added to PowerShell as part of DSC. Underneath this, are one or many nodes, which in turn contain a number of resources. In this example, our single resource will ensure that the FTP server is activated on the VM.
The first stage to publish a DSC configuration is to package it up. We use the publish Azure, VM DSC configuration, PowerShell command for this. This outputs a zip file containing the configuration file, sample.ps1, as well as a manifest. If you have dependencies that are required, such as PowerShell modules, you'll need to add them to the zip yourself. Navigate though the Azure portal to create a new extension, this time selecting PowerShell desired state configuration, populating these fields and confirming an executed configuration file on the virtual machine. The script will now run on the desired virtual machine. Note that a managed object format, or MOF file, M-O-F, will be created after running deployment as part of this action.
Chef and Puppet are two configuration management tools that preceded PowerShell DSC. They are both popular, particularly in the Linux world, where DSC, which requires the PowerShell DSC feature running on the client OS. Puppet and Chef use a client-server mechanism. Each client runs an agent to receive the configuration commands, and a central server that provides centralized management reporting for all clients.
Creating a Puppet environment is relatively easy. Firstly, we create a Linux Puppet enterprise virtual machine from the marketplace. This acts as the master node. Secondly, we create a plain Windows server virtual machine from the marketplace. This acts as a client node. And then finally, we add the Puppet extensions to the client virtual machine, just like we did earlier for PowerShell or custom scripts during the creation of the extension. We then supply the fully-qualified address of the Puppet master node.
In this demo, we'll illustrate how to attach a remote debugger to an Azure virtual machine. Debugging a virtual machine is often useful, as you may have a .NET application installed and running on it, or perhaps have elected to host a website in IS mode. These are simple to debug in Azure. We've already provisioned a virtual machine in Azure, and using the server explore in Visual Studio, we'll connect the debugger to it.
I'm going to show you how you can attach a debugger to a process on a VM. First of all, we're going to right-click on the VM here. And we're going to enable debugging. We click yes. And note that it's now in the process of adding the VS 2015 debugger extension to the VM. Once it's done, we'll then have another look at the menu options. Now it's finished adding that extension. I'm going to go ahead and right-click again on our VM, and we can see there's a few more options that are available now. I'm going to select the attach debugger option. Now we can see a list of all the running processes on the machine, and I'm able to select any one of them to attach the debugger to. From there, we can set up break points and inspect values just like one would do locally.
Stay tuned for the next section, where we'll learn how we can configure the networking stack of a VM.
About the Author
Isaac has been using Microsoft Azure for several years now, working across the various aspects of the service for a variety of customers and systems. He’s a Microsoft MVP and a Microsoft Azure Insider, as well as a proponent of functional programming, in particular F#. As a software developer by trade, he’s a big fan of platform services that allow developers to focus on delivering business value.