Azure virtual machines

An Azure virtual machine gives you the flexibility of virtualization without having to buy and maintain the physical hardware that runs it. However, you still need to maintain the VM by performing tasks, such as configuring, patching, and installing the software that runs on it. This unit gives you information about what you should consider before you create a VM, how you create it, and how you manage it.

Azure virtual machines can be used in various ways. Some examples are:

  • Development and test – Azure VMs offer a quick and easy way to create a computer with specific configurations required to code and test an application.
  • Applications in the cloud – Because demand for your application can fluctuate, it might make economic sense to run it on a VM in Azure.
  • Extended datacenter – Virtual machines in an Azure virtual network can easily be connected to your organization’s network.

Design considerations for virtual machine creation:

  • Availability: Azure supports a single instance virtual machine Service Level Agreement of 99.9% provided you deploy the VM with premium storage for all disks.
  • VM size: The size of the VM that you use is determined by the workload that you want to run. The size that you choose then determines factors such as processing power, memory, and storage capacity.
  • VM limits: Your subscription has default quota limits in place that could impact the deployment of many VMs for your project.
  • VM image: You can either use your own image, or you can use one of the images in the Azure Marketplace.
  • VM disks: There are two components that make up this area. The type of disks which determines the performance level and the storage account type that contains the disks. Azure provides two types of disks:

    • Standard disks: Backed by HDDs, and delivers cost-effective storage while still being performant. Standard disks are ideal for a cost effective dev and test workload.
    • Premium disks: Backed by SSD-based, high-performance, low-latency disk. Perfect for VMs running production workload.

      And, there are two options for the disk storage:

      • Managed disks: Managed disks are the newer and recommended disk storage model and they are managed by Azure.
      • Unmanaged disks: With unmanaged disks, you’re responsible for the storage accounts that hold the virtual hard disks (VHDs) that correspond to your VM disks.

Virtual machine extensions

Windows VMs have extensions which give your VM additional capabilities through post deployment configuration and automated tasks.

  • Run custom scripts: The Custom Script Extension helps you configure workloads on the VM by running your script when the VM is provisioned.
  • Deploy and manage configurations: The PowerShell Desired State Configuration (DSC) Extension helps you set up DSC on a VM to manage configurations and environments.
  • Collect diagnostics data: The Azure Diagnostics Extension helps you configure the VM to collect diagnostics data that can be used to monitor the health of your application.

For Linux VMs, Azure supports cloud-init across most Linux distributions that support it and works with all the major automation tooling like Ansible, Chef, SaltStack, and Puppet.

Compare virtual machine availability options

Azure offers several options for ensuring the availability of the virtual machines, and applications, you have deployed.

Availability zones

  • A physically separate zone, within an Azure region. There are three Availability Zones per supported Azure region.
  • Azure services that support Availability Zones fall into two categories:
    • Zonal services: Where a resource is pinned to a specific zone (for example, virtual machines, managed disks, Standard IP addresses), or
    • Zone-redundant services: When the Azure platform replicates automatically across zones (for example, zone-redundant storage, SQL Database).

Availability sets

  • Composed of two additional groupings that protect against hardware failures and allow updates to safely be applied - fault domains (FDs) and update domains (UDs).

VM scale sets

Load balancer

  • Combine the Azure Load Balancer with an availability zone or availability set to get the most application resiliency.
  • Define a front-end IP configuration that contains one or more public IP addresses.
  • Virtual machines connect to a load balancer using their virtual network interface card (NIC).
  • Define load balancer rules for specific ports and protocols that map to your VMs to control traffic flow.

What is a fault domain?

A fault domain is a logical group of underlying hardware that share a common power source and network switch, similar to a rack within an on-premises datacenter. As you create VMs within an availability set, the Azure platform automatically distributes your VMs across these fault domains. This approach limits the impact of potential physical hardware failures, network outages, or power interruptions.

alt text

Update domains

An update domain is a logical group of underlying hardware that can undergo maintenance or be rebooted at the same time. As you create VMs within an availability set, the Azure platform automatically distributes your VMs across these update domains. This approach ensures that at least one instance of your application always remains running as the Azure platform undergoes periodic maintenance. The order of update domains being rebooted may not proceed sequentially during planned maintenance, but only one update domain is rebooted at a time.

alt text

Each virtual machine in your availability set is assigned an update domain and a fault domain by the underlying Azure platform.

For a given availability set, five non-user-configurable update domains are assigned by to indicate groups of virtual machines and underlying physical hardware that can be rebooted at the same time.

alt text

What if my size needs change?

Azure allows you to change the VM size when the existing size no longer meets your needs. You can resize the VM - as long as your current hardware configuration is allowed in the new size. This provides a fully agile and elastic approach to VM management. If you stop and deallocate the VM, you can then select any size available in your region since this removes your VM from the cluster it was running on.

Caution: Be cautious when resizing production VMs - they will be rebooted automatically which can cause a temporary outage and change some configuration settings such as the IP address.

Exercise: Create a virtual machine by using the Azure CLI

alt text

In this exercise you'll create a Linux virtual machine by performing the following operations using Azure CLI commands:

  • Create a resource group and a virtual machine
  • Install a web server
  • View the web server in action
  • Clean up resources

Prerequisites

Login to Azure and start the Cloud Shell

  1. Login to the Azure Portal and open the Cloud Shell.

    alt text

  2. After the shell opens be sure to select the Bash environment.

    alt text

Create a resource group and virtual machine

  1. Create a resource group with the az group create command. The command below creates a resource group named az204-vm-rg.

    az group create --name az204-vm-rg --location eastus
    
  2. Create a VM with the az vm create command. The command below creates a Linux VM named az204vm with an admin user named azureuser.

Create virtual machine

az vm create \
    --resource-group az204-vm-rg \
    --name az204vm \
    --image UbuntuLTS \
    --generate-ssh-keys \
    --admin-username azureuser \
    --public-ip-sku Standard

It will take a few minutes for the operation to complete. When it is finished note the publicIpAddress in the output, you'll use it in the next step.

Install web server

  1. By default, only SSH connections are opened when you create a Linux VM in Azure. Use az vm open-port to open TCP port 80 for use with the NGINX web server:

    az vm open-port --port 80 \
    --resource-group az204-vm-rg \
    --name az204vm
    
  2. Connect to your VM by using SSH. Replace <publicIPAddress> in the example with the public IP address of your VM as noted in the previous output:

    ssh azureuser@<publicIPAddress>
    
  3. To see your VM in action, install the NGINX web server. Update your package sources and then install the latest NGINX package.

    sudo apt-get -y update
    sudo apt-get -y install nginx
    
  4. When done type exit to leave the SSH session.

View the web server in action

Use a web browser of your choice to view the default NGINX welcome page. Use the public IP address of your VM as the web address. The following example shows the default NGINX web site:

alt text

Clean up resources

You can now safely delete the az204-vm-rg resource group from your account by running the command below.

az group delete --name az204-vm-rg --no-wait

Note: This operation takes on average 5 - 10 minutes

results matching ""

    No results matching ""