Azure, Technology

13. Azure Virtual Machines

Create a Virtual Machine

Creating a VM through Azure Portal

In this example we will create a Windows 2016 Server.

From the Azure Portal:

  1. Click on Create a Resource
  2. Select Windows Server 2016 Datacentre
  3. Set the basic options: Subscription, Resource Group, VM Name, Region (price varies slightly)
    Azure Spot Instance: this is for low priority resources only. You will get this cheap but if a higher paying customer comes a long you will get booted off. Kind of like standby by tickets for a flight…
  4. Set the VM size
  5. Inbound Port Rules: Set the ports you want. EG: http, ssh, RDP
  6. Select the disk type and encryption
  7. Data disks are additional disks to the System drive
  8. Network settings – Leave them as default (see separate section on networking)
  9. Auto shutdown: this has handy for testing devices. You set it to auto shutdown so it isn’t running constantly and running up costs
  10. Once you have set the basic settings click on “Create”

This will create the VM and the resources that go along with it such as:

  • Disk
  • Network card
  • Network security group
  • Public ip address

Create a VM in PowerShell

#Create a Windows 2016 VM that uses virtual network “myVnet”

New-AzVm `
 -ResourceGroupName "vm-networks" `
 -Name "dataProcStage1" `
 -VirtualNetworkName "myVnet" `
 -SubnetName "default" `
 -image "Win2016Datacenter" `
 -Size "Standard_DS2_v2"
 -OpenPorts 80,3389,443,22

It will prompt you for admin credentials on creation

Connecting to a VM

  1. Go the new VM in Azure portal
  2. Click on Connect
  3. Select RDP
  4. Enter the credentials you set when creating the VM


VM Availability

SLA for VMs

Even with no availability options set for a VM, the guaranteed up time of your VMs is as follows:

  • For any Single Instance Virtual Machine using Premium SSD or Ultra Disk for all Operating System Disks and Data Disks, we guarantee you will have Virtual Machine Connectivity of at least 99.9%.
  • For any Single Instance Virtual Machine using Standard SSD Managed Disks for Operating System Disk and Data Disks, we guarantee you will have Virtual Machine Connectivity of at least 99.5%.
  • For any Single Instance Virtual Machine using Standard HDD Managed Disks for Operating System Disks and Data Disks, we guarantee you will have Virtual Machine Connectivity of at least 95%.



Availability Options

You can set the availability options for a VM when you are creating it, it cannot be set after the VM is created.


  1. Availability Set: This is where you have 2 or more VMs in a set to provide high availability. There is a Load Balancer in the availability set that distributes traffic between the VMs. These VMs in an Availability Set have a higher guaranteed uptime at 99.95%. You don’t pay for the Availability set, but you do pay for the extra VMs in the set.
  2. Availability Zones:  An Availability Zone is a physically separate zone, within an Azure region. There are three Availability Zones per supported Azure region. Each Availability Zone has a distinct power source, network, and cooling. By designing your solutions to use replicated VMs in zones, you can protect your apps and data from the loss of a data centre. If one zone is compromised, then replicated apps and data are instantly available in another zone. These have a guaranteed uptime of 99.99%


VM Monitoring

Basic Monitoring

If you go to the VM and then click on “Overview” you will get some basic monitoring like CPU, Network, Disk bytes and disk operations

Detailed Monitoring & Diagnostics

See section 6.1 as this covers very similar information

For more detailed monitoring and diagnostics go to the VM -> Monitoring -> Diagnostic Settings

To use this you must first set it up. This is done by clicking on “Enable Guest Level Monitoring”. What this does:

  • Installs an agent on the VM
  • Reboots the VM

This agent then pulls diagnostic data from the VM and puts it in a Storage Account. You can then query it and send it to other applications.


  • Performance Counters: here you can set the sample rate in seconds and the units to use (EG: percent)
  • Log: this is similar to the Windows Event viewer. You can select which logs and levels to collect.


VM Custom Script Extension

When you create a VM through the portal there is an option called “Extensions” which allows you to run a script after the VM has been setup. This allows you to do things like:

  • Install applications
  • Copy files to the VM
  • Open ports


You can manage the Extensions on a current VM by going to VM -> Extensions. Here you can see the current extensions installed and also have the option to add new extensions.

Azure Bastion Service

Bastion is a method of connecting to a VM. You connect to the Bastion server in order to connect to your VMs. This allows you to turn off public RDP & SSH access on your VMs which makes them more secure. The Bastion service does not need a public IP.

Setting up Bastion:

  • Create VM with the Bastion service (do this through the VM section)
  • Create a separate subnet for Bastion services

Once created, click on connect  and it logs in using an remote session through the web browser.


Virtual Machine Scale Sets

One of the great things about cloud computing is being able to scale your machines as you need. A virtual machine scale set allows you to do this easily.

Virtual Machine Scale Sets

Basically this is 2 or more VMs running behind a load balancer. It is provided as a service in a single package. You can find this in the Market Place

This service charges you for the VM’s used, there is no extra charge for the scaling service.

“Azure virtual machine scale sets let you create and manage a group of load balanced VMs. The number of VM instances can automatically increase or decrease in response to demand or a defined schedule. Scale sets provide high availability to your applications, and allow you to centrally manage, configure, and update a large number of VMs. With virtual machine scale sets, you can build large-scale services for areas such as compute, big data, and container workloads.”

By default there is a limit of 100 instances per scale set.

Creating a Virtual Machine Scale Set:

  • From the “Virtual Machine Scale Set” page, click on “Create”
  • A lot of the options here are similar to creating a VM (name, Resource Group, region, Image, size etc..)
  • Scaling: on this tab you get to select the “initial instance count” (number of VMs) in the set. You can set the “Scaling Policy” to manual, or Custom. Custom allows you to set parameters around when a VM is added or removed. You can set this using thresholds of CPU usage. EG: If CPU usage it at 75% for 2 mins, add extra VM. If it drops below 30% for 2 mins remove a VM.
  • Health Tab: here you can set up monitoring for an application such as HTTP on port 80.
    – Automatic repair policy: this option can recreate a VM instance that is deemed “Unhealthy” from the monitoring options you have selected.
  • Advanced Tab: By default there is a limit of 100 instances per scale set but you can increase that on this page. You also have options about spreading this among different zones and data centres.


Stop and Start a VM with Powershell

Stop-AzVM -resourceGroupName "myRG" -name "MyVM"

Start-AzVM -resourceGroupName "myRG" -name "MyVM"

1 thought on “13. Azure Virtual Machines

  1. Hi Sean,

    Can we connect to the azure VM without using Public IP address while using RDP??

    Is there any solution apart of Azure Bastion?


Leave a Reply

Your email address will not be published. Required fields are marked *