Creating a VM in Azure

In this section, we will learn to create a VM in Azure. Developers need VMs all the time. If you are wondering what I mean, just imagine that you wanted to try out out some new version of a tool or software that is not yet production-ready and you do not wish to try it out on your own laptop due to probable instability issues this new untested software may cause. I always do so, whenever I am trying out nightly builds of products or getting hands-on with any new product. Azure provides you with great flexibility and choice. There are numerous choices and configurations available to select the operating system that you want and the size that you require. We, being passionate .NET developers, may want a VM which has the great Visual Studio 2017 installed, so that we can start developing as soon as we provision the VM. To this end, we will learn to create a VM in Azure. To do so, let's perform the following steps:

  1. On the left panel (hub) of the Azure management portal, click on Virtual machines. Ensure you click on Virtual machines and not Virtual machines (classic). We will discuss the difference between classic and the resource manager later in this section.
    You will see a Virtual machines screen, which lists all the virtual machines that you have as well as providing the user interface to Add a virtual machine, Start, Stop, Delete, and Restart a virtual machine, as shown in the following screenshot:
  1. Click on the Add button. This will open a new fly-out on the right side, displaying a number of virtual machine images to choose from. This fly-out is what we call a blade. You can have Red Hat Linux, Windows Server, Ubuntu, or anything else based on your requirements. Since we need a Windows 10 machine with Visual Studio 2017 Community Edition installed, let's search for Visual Studio 2017. This shows the following list of results:
  1. Select the image that best suits your needs. On doing so, a new blade will appear displaying the details of the virtual machine image, its publisher, useful links, last updated date, its desktop screenshot, deployment model, and so on. Always select the deployment model as Resource Manager as it gives you the ability to automate with PowerShell, unlike Classic. This blade can be seen in the following screenshot:
  1. On clicking the Create button, the following screen will display, which has four basic steps to create a virtual machine:
    1. Basics
    2. Size
    3. Settings
    4. Summary

The Basics section gathers fundamental information about the virtual machine to be created, such as:

    • Name: The name of the virtual machine, which has to be unique.
    • VM disk type: This can be solid-state drive (SSD), which offers consistent, low-latency performance and is ideal for production use or standard disks (HDD) that are backed by magnetic drives and are preferred for applications where data is accessed infrequently. 
    • User name: The username to log in to the virtual machine.
    • Password, Confirm password: These should be the same as the user name and this password will be used with the username to log in to the virtual machine.
    • Subscription: This is auto-populated. If you have numerous subscriptions, you can choose the one with which you wish to create the virtual machine.
    • Resource group: A resource group is a collection of resources that share the same life cycle, permissions, and policies. For better management, you can choose to Create new or reuse an existing resource group.
    • Location: The Azure data center that you wish to use for creating the virtual machine. Based on your location or your customer's location, you may want to choose the closest location for performance and low latency. Click OK:
  1.  In the Size section, choose the size that suits your needs. Azure lists recommended sizes in the blade, but if it doesn't fit your requirements, click on View all and you will see a lot more configurations to choose from. You can also customize the supported hard disk type, minimum CPU, and memory by moving the slider bars against these parameters. Azure lists CPUs, memory, number of data disks, disk size, and other included features with an important parameter for the cost in local currency that you would need to shell out per month to use it, so use this wisely. Once you nail down on size, click Select:
  1. The Settings section includes important yet auto-populated settings for the VM. Some important ones are discussed here:
    • Availability set: Azure has an availability SLA of 99.95%. For high availability of the virtual machine, it is recommended to have redundancy and group two or more VMs in an availability set. The advantage is that in the event of planned or unplanned maintenance, at least one virtual machine will be available, meeting the Azure availability SLA of 99.95%. This setting cannot be changed after the virtual machine is created. In our case, we do not need this, so we will go with the default value of None.
    • Use managed disk: This feature may not be available in all the regions. When this is set to Yes, Azure automatically manages the availability of the disks to provide data redundancy and fault tolerance. 
    • Auto-shutdown: This feature is very important, at least financially. While your virtual machine is running, every minute, so keep it switched on only when you need it to keep your bills affordable. If you enable auto-shutdown, you can configure the VM to shut down daily at a specified time. For example, if the VM is being used only during office hours, it makes perfect sense to shut it down out of office hours and save on money. The Settings blade is shown in the following screenshot:
  1. Click OK. A Summary page with all the settings will be displayed in the Summary blade along with terms of use. If you agree to it, click Create and your virtual machine will start to be created. You will be taken to your Dashboard page, which will now has a new tile added with the name of your virtual machine and it will show the status of this resource. Within a matter of a few minutes your virtual machine will be provisioned. Once it is provisioned, you will get a notification stating that the virtual machine is successfully deployed and the dashboard tile of the virtual machine will display the state as Running
  2. Click on the tile of the virtual machine that we have created. It will take us to the Overview blade of the virtual machine, as shown in the following screenshot:

You will see the following options:

    • Connect: On clicking Connect, the Remote Desktop Protocol (RDPfile will be downloaded. Clicking on this downloaded RDP will enable remote desktop connection to the virtual machine, after providing the username and password that you used while creating the virtual machine.
    • Start: Starts the virtual machine, if it's not started. The button will be enabled only if virtual machine is not running. 
    • Restart: Restarts the virtual machine. 
    • Stop: Stops the virtual machine and deallocates it.
    • Capture: This can be used to create a virtual machine image. We generally use it if we need a base image with additional configuration. 
    • Move: To move the virtual machine to another resource group or subscription.
    • Delete: To delete the virtual machine.
    • Refresh: To refresh the status of the virtual machine.
Azure has great documentation and cool training videos. They also have getting started guides and architecture recommendations to create and use Azure resources. You can find the documentation, the SDK, on the Azure site at https://docs.microsoft.com/en-us/azure/. Training, webinars, events, code samples, videos, whitepapers, and case studies can be found at https://azure.microsoft.com/en-us/resources/.

With this, we have created our very first virtual machine on the cloud (Azure) and we can use it as well by clicking the remote desktop file that we downloaded. On clicking the .rdp file, it will prompt for the username and password in the standard way as any other remote desktop connection does. It's just that this virtual machine is hosted in the cloud, in Azure. Once you are logged in, you can use it the way you want. Remember, once the virtual machine is started, irrespective of whether you use it or not, it starts costing you. So, if you wish to be cost-efficient, ensure you turn it off when you are not using it and start it when you do. This concludes our discussion on virtual machines. Next, we will see how we can use PowerShell to automate resource creation and management in Azure.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset