How to Create Virtual Machine in Azure Step by Step

How to Create Virtual Machine in Azure Step by Step

07 Aug 2024
Intermediate
11.1K Views
22 min read
Learn with an interactive course and practical hands-on labs

Free Azure Course: Best Free Online Microsoft Azure Courses

Azure virtual machines are Infrastructure as a service type offering from Microsoft which allows us to create VMs on cloud by allocating the required compute power and storage capacity. We can also set up a private network for these VMs and allow inbound and out bound connections to different other networks.

If you want to know more about Azure Virtual Machine, please follow previous article Understanding Azure Virtual Machines.

You can also consider doing our Microsoft Azure Certification from ScholarHat to upskill your career. Azure Virtual Machines are suitable for choosing as a desired resource for development environment as it provides more controlling power on the environmental features such as IIS as compared to Azure Platform as a service module. We can create a VM in many ways –

  • From the Azure Portal

  • Azure CLI

  • ARM templates

Steps to Create an Azure Virtual Machine (VM)

To get started with this, lets create a VM using the Azure portal.

  1. Login to the Azure Portal.

  2. Click on Create Resource and select Windows Server 2016 Datacenter.

    Steps to Create an Azure Virtual Machine (VM)
  3. On the Create a VM screen, Fill in the Subscription, resource group name and VM name and image.

    On the Create a VM screen, Fill in the Subscription, resource group name and VM name and image.
  4. Click on Change Size hyperlink and choose the desire configuration. A total of 145 options are currently available with different configuration and prices. Not all options are available in all regions. Please select your region accordingly. For now, we will change the region from South India to South east Asia. By default, Standard DS1 v2 size will be selected.

    Steps to Create an Azure Virtual Machine (VM)
  5. Fill in the administrator account credentials and Inbound ports.

    Steps to Create an Azure Virtual Machine (VM)
  6. We can create the VM with this much of information. But we do have other configurable sections, if required. Click on Next button to go to Disks section.

    Steps to Create an Azure Virtual Machine (VM)
  7. In this section, we first need to select the OS disk type – Here we have 3 options.Premium SSD, Standard SSD and Standard HDD. Premium SSD are solid state disks which has high IOPS and suitable for high-performance systems. Standard SSD are also backed by solid-state disks but has low performance as compared to premium one. And Standard HDD are supported by magnetic drives and are used when accessing data is less frequent.

  8. Use Unmanaged Disks options allows the control over the disks used in VM. If it is required to store VHDs in own storage account then we should choose No option and connect to storage account which should be used to store disks. By Default, it is selected as No as Azure Manages the disks and we do not have access to the disks.

  9. Click on Next to go to Networking section.

    Steps to Create an Azure Virtual Machine (VM)

    Create a Virtual Network for the VM and assign a subnet to it. A public IP address is also required in order to communicate to this VM from via internet.In a Network security group, the basic option allows to configure inbound ports but with advanced option we can create a network security group and define inbound and outbound rules to different ports.

  10. Click on Next to configure management section.

    Steps to Create an Azure Virtual Machine (VM)

    Boot Diagnostics logs startup events and is helpful to trace in case VM does not starts by seeing logs.OS guest diagnostics are generally written to an external storage account and helpful in case of creating alerts. Enabling Manage Service Identity will allow user management through Azure AD to access the VM.Auto Shut down feature is to shut down the VM during off-hours in order to reduce bills. We can enable Backup with Recovery Service Vaults. We can assign a back up policy which defines the frequency of backups and their retention period.

  11. Click Next to go to Guest Configs.This is generally used to bring the VM in a desired state after initialization. For example, we can install some extension which can run custom PowerShell scripts on start up.

  12. Click on Next to go to Tags sections. Tags are like dictionary objects with Name Value pair to group similar resources by providing same tags. This can also be useful to see consolidated billings by applying same tag to multiple resources in a resource group.

  13. Click on Next and review all the settings selected. Now click on create.

    Steps to Create an Azure Virtual Machine (VM)
  14. Go to All Resources section on left panel and see the created resources. We will find below resources created:

    • Virtual machine

    • OS Disk

    • Network Interface

    • Public IP

    • Network Security Group

    • Virtual Network

    • Storage Account

    • Recovery Service Vault

  15. Click on Virtual machine to get the RDP file. Check if you are able to log in to the VM with the administrator account entered in step 5.

Deploying ASP.NET Application to a Windows VM

In order to run and deploy an ASP.Net application, we need to first make sure that VM has all necessary dependencies to run the app.

  1. Log in to the VM just created in previous section.

  2. Open Windows PowerShell in administrative mode and run below command

    Install-WindowsFeature Web-Server,Web-Asp-Net45,NET-Framework-Feature
    
  3. Restart the web server so that system PATH updates take effect

     net stop was /y
     net start w3svc
    
  4. For Windows Server Virtual machine, use the Add Roles and Features wizard on the right click of Server name in Server Manager. On the Server Roles step, check the box for Web Server (IIS).

    Deploying ASP.NET Application to a Windows VM
  5. Install web deploy on the server to publish code into the VM.To install Web, Deploy, use the Web Platform Installer (WebPI). In the Web Platform Installer, you find Web Deploy in the Applications tab.

    Deploying ASP.NET Application to a Windows VM
  6. Go to Azure portal and change the IP type as static.

  7. Add an Inbound rule to Network Security group of type TCP for port 8172 which is used to web deploy into IIS.

    Deploying ASP.NET Application to a Windows VM
  8. Open Visual Studio and create a new Asp.Net MVC application.

  9. Right click on project file and publish.

    Deploying ASP.NET Application to a Windows VM
  10. In the Publish window, Select IIS, FTP, etc. option.

    Deploying ASP.NET Application to a Windows VM
  11. Click on publish button at the bottom.

  12. Fill the details of server name, site name administrative credentials and Destination URL and validate. A green tick will appear if the connection to remote VM is succeeded.

    Deploying ASP.NET Application to a Windows VM
  13. Click on Save to start publishing. Once it completes, the browser opens the URL with deployed code.

    Deploying ASP.NET Application to a Windows VM

Adding Custom Domains

By default, Azure VMs are accessed via the IP address. But we can also provide DNS to the Azure VMs.

  1. Go to the Public IP resource in Azure Portal and click on Configuration section.

    Deploying ASP.NET Application to a Windows VM
  2. Provide the DNS name and browse the link on browser. It displays the deployed application.

  3. Now, we can add a custom domain to this VM by following the next steps.

  4. Go to the DNS Provider website and enter the DNS records section.

  5. Add and entry of type CNAME with values as obtained at step 2.

    Deploying ASP.NET Application to a Windows VM
  6. The web application deployed on Azure VM is now available on the custom domain.

Summary

Choosing Azure Virtual machines as the development and deployment option in cloud gives a lot of flexibility and control over environment. We can increase or decrease the size of VM based on the load requirement and trace minute level events through boot diagnostics and guest diagnostics. With the option to configure network security group with subnets, it is possible to open and close ports as per inbound and outbound rules to ensure a highly secured system. Unlimited Azure online training will enable you to become a master in Azure services.

Take our Azure skill challenge to evaluate yourself!

In less than 5 minutes, with our skill challenge, you can identify your knowledge gaps and strengths in a given skill.

GET FREE CHALLENGE

Share Article
About Author
Rupesh K. Roy (Author, Speaker and Microsoft Certified Trainer)

He is an Author, Technology Speaker and Microsoft Certified Trainer on .Net and Azure platforms. He has more than 5 years of industry expertise and has worked as a developer with the most prominent companies on Azure, .Net Core and React JS. He is passionate about learning and sharing new technical stacks.
Accept cookies & close this