Overview

3 Using Virtual Machines

Virtual machines (VMs) in Azure are a core Infrastructure-as-a-Service building block that provide full control of an operating system without managing physical hardware. They suit a wide range of workloads, from custom apps to legacy software, and support many Windows and Linux images from the Azure Marketplace. Azure abstracts the hardware, offers pay-as-you-go pricing, and charges separately for data egress, while ingress is free. You can connect and administer VMs using RDP (commonly for Windows), SSH (preferred for Linux), or Azure Bastion for private, browser-based access without exposing the VM to the public internet. Although you own the software lifecycle on the VM, services like Azure Automanage and managed identities help apply best practices, reduce operational overhead, and securely authenticate to other Azure resources without secrets.

Creating a VM in the Azure Portal involves choosing a subscription/resource group, region, availability options (zones or sets), an OS image (for example, Ubuntu LTS), and a right-sized SKU to balance performance and cost. Region choice affects pricing, features, and availability options; Azure Resource Mover can help relocate resources later. You configure secure admin access (SSH keys are recommended), open only required inbound ports, select disk types (HDD/SSD) and encryption, and attach data disks as needed. Networking requires a VNet (and optionally a public IP), with traffic filtered by Network Security Groups; load distribution can be added later via Azure Load Balancer or Application Gateway. Cost optimizations include auto-shutdown, Spot VMs for interruptible workloads, and reserved instances for 1–3 year commitments. The same deployment can be scripted quickly via Azure CLI once you understand the choices.

Operating VMs effectively means scaling vertically (resize) or horizontally (scale sets), designing for resilience with availability zones/sets, and enforcing governance with Azure Policy (for images, regions, managed disks, and more). For secure administration, Bastion minimizes public exposure. Observability is delivered by Azure Monitor, which collects metrics, logs, and traces, surfaces VM Insights, and integrates with Log Analytics for KQL-based investigations. Alerts can be driven by metrics, logs, activity events, or dynamic thresholds (“smart alerts”) that learn normal behavior and reduce noise. The Azure Monitor Agent, configured with Data Collection Rules and deployable at scale via Azure Policy, standardizes telemetry from Windows and Linux guests. Together, these practices help you optimize performance, reliability, and cost throughout a VM’s lifecycle.

Azure abstracts all the hardware layers when using a VM.
Azure virtual machine overview.
Ingress and egress traffic.
Remote Desktop data flow.
Downloading an RDP connection file for an Azure VM.
Using either SSH or Bastion to connect to a VM.
Self-manage your VM and be in charge of policies and configurations, or use Azure Automanage to let Azure apply update patches and apply security best practices.
Azure Automanage configured for a VM.
Create a new Virtual Machine.
The first part of the wizard for creating a new VM.
Set resource group and name for the VM.
Choose region and availability options.
Azure availability zones with separate cooling, power, and network.
An availability set with 9 VMs, 6 update domains and 3 fault domains.
Choose the latest Ubuntu LTS version as VM image.
Azure Marketplace options for VM images.
Balance the need for compute resources with the cost.
Select a small relatively inexpensive VM size, such as Standard_DS1_v2.
Use the SSH key pair as authentication to improve security.
Select the ports you want to open on the new VM.
Create OS and data disks for the VM.
VMs need to connect to a network to access the Internet and other Azure services.
The networking tab for the VM.
Choose one of two load balancing options, if required.
The first part of the Management tab properties.
Using a managed identity to authenticate access between Azure resources.
Use auto-shutdown whenever you can.
Always double-check the VM price is right.
The Portal page for changing VM size and type.
An Azure availability set with 3 fault domains and 5 update domains.
The single policy assigned to the new ActionVM.
Connect to the VM only using the Microsoft Azure network.
Percentage CPU usage shown as a graph for the ActionVM in the Metrics dashboard
Azure Insights for the ActionVM
An example KQL query in the Azure Log Analytics workspace for the ActionVM
Create an alert rule in Azure Monitor Alerts
Select the resource for the Alert, in this case our ActionVM
Smart alert configuration when creating it
Create a new action group with an action type
Choose the action type and give the alert a name

Summary

  • Virtual machines (VMs) are core to Azure’s Infrastructure-as-a-Service (IaaS) offerings and give you full control over your compute environment without buying any hardware.
  • You can create VMs using the Azure Portal, Azure CLI, PowerShell, or templates, depending on your preference and level of automation.
  • Choosing the right region for your VM affects price, performance, and availability options—pick wisely or prepare to meet the Azure Resource Mover.
  • Azure VMs support a wide range of operating systems and specialized images from the marketplace, from Ubuntu to blockchain-ready setups.
  • The size of a VM determines its cost and capacity—start small and scale as needed to avoid spending your entire budget on idle CPU cycles.
  • VMs need a network to function; attaching them to a virtual network (VNet) ensures connectivity to the internet, services, and other resources.
  • Opening ports like SSH or RDP during setup allows remote access—but don’t forget to lock things down with a network security group (NSG).
  • Load balancers and application gateways let you distribute traffic across multiple VMs for better performance and availability.
  • You can connect to a VM using RDP, SSH, or Azure Bastion depending on your OS and security posture.
  • Azure Automanage helps reduce manual effort by automatically applying best practices around updates, monitoring, backup, and security.
  • Auto-shutdown is your best friend when it comes to saving money—turn off your VMs when they’re not in use.
  • Spot instances let you run workloads at massive discounts, but be prepared for Azure to reclaim the VM at any time.
  • Reserved instances offer significant savings if you can commit to running a VM for one or three years.
  • Azure Monitor collects real-time metrics like CPU, memory, and network usage, helping you detect problems before users do.
  • Log Analytics gives you powerful querying capabilities to investigate issues across all your VM logs using Kusto Query Language (KQL).
  • Smart alerts help you respond to problems quickly with notifications based on metrics, logs, or even AI-powered dynamic thresholds.
  • Azure logs include activity logs, diagnostics, and guest OS logs, each offering a different view into what’s happening inside and around your VM.
  • With a few simple KQL queries, you can investigate everyday issues like unexpected reboots or login failures across multiple VMs.
  • The Azure Monitor Agent (AMA) is the modern way to collect telemetry, and it can be deployed manually or automatically using Azure Policy.
  • Without monitoring agents, your VMs are silent. With them, you gain full visibility and control over performance, reliability, and cost.

FAQ

What is an Azure Virtual Machine and when should I use one?A virtual machine (VM) in Azure is an Infrastructure-as-a-Service (IaaS) compute resource that gives you full control over the operating system and software without owning hardware. Use VMs when you need OS-level control, to run custom or legacy software, or when workloads don’t fit higher-level PaaS services. Azure abstracts the hardware, letting you size, scale, and pay only for what you use.
What’s the quickest way to create a Linux VM?In the Azure Portal, go to Virtual machines, select Create, pick an Ubuntu LTS image, choose a small size (for example, Standard_DS1_v2), authenticate with an SSH key, and enable SSH (port 22). Or use Azure CLI: az vm create -n AzureVM -g ActionRG --image UbuntuLTS --vnet-name ActionVNet --generate-ssh-keys.
How do region and availability choices affect my VM?Region impacts price, available sizes, and features; the same VM can cost significantly more in one region than another. For resiliency, use Availability Zones (physically separate datacenters in a region) or Availability Sets (fault/update domains) to avoid single points of failure. If you chose the wrong region later, Azure Resource Mover can help migrate supported resources.
What are ingress and egress, and how do they affect costs?Ingress is data into Azure and is free. Egress is data leaving Azure (to the internet, another availability zone, or another region) and is billed per GB. Keep an eye on egress to avoid surprise costs, and consider architecture that minimizes cross-zone or cross-region traffic.
How can I connect to my VM: RDP, SSH, or Bastion?RDP (port 3389) is typically used for Windows desktops; SSH (port 22) is preferred for Linux and is command-line based. Azure Bastion lets you RDP/SSH through the Azure network without exposing a public IP, improving security. You can download an RDP file from the Portal, use SSH keys for Linux, or connect via Bastion directly in the browser.
What are best practices for securing VM access and networking?Prefer SSH keys over passwords, and limit open inbound ports to only what you need. Use Network Security Groups (NSGs) and, for maintainability, associate them at the subnet/VNet level rather than the NIC where possible. Avoid exposing RDP/SSH to the internet; use Azure Bastion for private access and be cautious with public IPs.
How do I choose an OS image and VM size?Pick a stable, supported image (for example, Ubuntu LTS or a Windows Server SKU); the Marketplace offers thousands of specialized images if needed. Start with a small, cost-effective size and adjust based on observed metrics. Families include general-purpose, compute-optimized, memory-optimized, storage-optimized, GPU, and high-performance; choose to match your workload.
What disk and encryption options should I consider?For the OS disk, choose Premium SSD for performance, Standard SSD for balanced cost/perf, or HDD for low-cost, light workloads. All managed disks are encrypted at rest; you can use platform-managed keys or customer-managed keys (and optionally enable double encryption). Add data disks as needed; managed disks are locally redundant with multiple copies in the datacenter.
Can I resize or scale my VM later, and how do I handle load?You can vertically scale by changing the VM size (scale up or down) and horizontally scale by adding instances in a VM scale set. For traffic distribution, use Azure Load Balancer (layer 4, high performance) or Application Gateway (layer 7 with URL-based routing). Some load-balancing integrations require the balancer to exist before VM creation.
How do I monitor, maintain, and control costs for VMs?Use Azure Monitor and VM Insights for metrics, Log Analytics with KQL for deep diagnostics, and Smart Alerts with dynamic thresholds to detect anomalies. Install the Azure Monitor Agent with Data Collection Rules to control what telemetry is collected. Reduce costs with auto-shutdown, Spot VMs for interruptible workloads, and Reserved Instances for 1–3 year commitments; always review estimated price before creation and watch egress. Azure Automanage can apply best practices for backup, updates, security, and configuration to reduce operational overhead.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Microsoft Azure in Action ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Microsoft Azure in Action ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Microsoft Azure in Action ebook for free