Virtual Machines and Instances
Managed virtual servers on shared hardware
A VM is a virtual computer that runs an operating system on shared physical hosts. Cloud providers expose them as instances (EC2), VMs (Azure) and Compute Engine (GCP) with sizes, images and networking.
What you will learn
- Explain how instances map to a hypervisor and shared physical hosts
- Compare instance naming across AWS, Azure and GCP
- Describe disks, images, networking and metadata on a VM
Promises hardware abstraction: you provision a size (CPU/RAM), pick an OS image, attach disks, join a network, and get a virtual machine that can be started, stopped and replaced — all without owning a rack.
What is this?
Cloud VMs are virtual machines backed by a hypervisor (Nitro/KVM/Hyper-V) running on massive fleets of physical hosts. AWS calls them EC2 instances (m5.large, t3.small); Azure calls them VMs (Standard_D8s_v5); GCP calls them Compute Engine instances (e2-standard-4). Each instance has vCPUs (virtual cores), memory, local/ephemeral or attached persistent disks, at least one NIC on a VPC/VNet, a metadata service for instance facts and credentials.
Why do you need it?
- Instant compute without capital expenditure or lead time.
- Resizable: change family/size to match workload need.
- OS isolation lets teams run arbitrary software safely.
- Per-second/per-minute billing and autoscaling remove idle waste.
Mental model
Renting an apartment with shared plumbing and electricity
Cloud virtual machines
You control your unit (the OS, apps, files) and only pay for your floor space, while the building (the physical host, network, power) is shared, maintained and metered by the landlord.
How it works
- A hypervisor multiplexes one physical host among many VMs, enforcing isolation on CPU, memory and I/O.
- You request an instance type: a hardware profile with vCPUs, memory, network bandwidth and local SSD options.
- The image (AMI/Azure image/Compute Engine image) boots the VM with a chosen OS and configuration.
- Persistent disks are network-attached storage (EBS, managed disks, Persistent Disk) that survive stop/start.
- The metadata service (IMDS) gives every instance its identity, tags, user-data and short-lived role credentials.
One boot-to-run VM flow.
Examples
Launch a compute instance everywhere
# AWSaws ec2 run-instances --image-id ami-12345678 --instance-type t3.micro --key-name dev --count 1# Azureaz vm create -n web-01 -g app-rg --image UbuntuLTS --size Standard_B1s --generate-ssh-keys# GCPgcloud compute instances create web-01 --machine-type=e2-micro --zone us-central1-a --image-family ubuntu-2204-ltsAll three treat a VM as an API resource: a size, an image, a network and a key. The cloud schedules, runs and bills it.
In production
- A platform team runs a fleet of t3.medium EC2 for web tiers behind an ASG + ALB.
- Azure burstable B-series VMs handle dev and CI spikes at low base CPU.
- GCP e2-standard instances run batch workers started by Cloud Scheduler.
Best practices
- Use AMIs/images from a pipeline so every VM is exactly reproducible.
- Attach tags to instances and disks for cost and ownership.
- Put instances behind managed groups (ASG/VMSS/MIG) instead of standalone VMs.
- Disable password auth; use SSH keys backed by your IdP.
Common mistakes
- Treating VMs as pets: patching, fixing and naming them as unique snowflakes.
- Choosing huge instance types 'just in case' instead of autoscaling small ones.
- Forgetting instance metadata (IMDSv1) open to SSRF attacks.
- Mixing sizes of a family and making capacity planning guessing work.
Common issues
Instance unreachable via SSHSecurity group/firewall or key mismatch
Check SG inbound 22, NACL return rules, and that the key matches the one provided at launch.
Insufficient capacity when launchingRegion/AZ out of capacity for that instance type
Add capacity across AZs or switch instance type; use On-Demand Capacity Reservations for critical fleets.
Debugging tips
- Cannot reach instance? Check SG/NSG/firewall rules, route tables and NACLs, not just the OS.
- Slow boot: inspect cloud-init/user-data logs in /var/log.
- No SSH? Verify key permissions, allowlists and the instance's public IP assignment.
- Terminate + relaunch is often faster to debug than 'fixing' a broken instance.
Interview checkpoint
Hands-on lab
- Launch, inspect and terminate a compute instance on any provider
- Use the metadata service for instance facts
- Understand stop vs terminate and billing implications
Provision Your First Cloud VM from the CLI
25 min · beginner
Quick quiz
What enforces isolation between cloud VMs sharing a physical host?