Course map

Topic 179 / Core

Virtual machines

Chapter 11.2 · Compute: VMs, Containers, Serverless

What and why

A single physical machine can run only one operating system directly on its hardware, yet cloud providers need to sell many isolated, independently configurable "machines" from one physical box. A virtual machine (VM) virtualizes hardware so a hypervisor runs multiple guest operating systems on one physical host, each believing it owns dedicated CPU, memory, and disk. Builds on: → 4 (operating system fundamentals).

Diagram

Physical hardware
      │
  Hypervisor
   ├── Guest OS A + App A   (fully isolated kernel)
   ├── Guest OS B + App B   (fully isolated kernel)
   └── Guest OS C + App C   (fully isolated kernel)

How it works

  1. A hypervisor partitions physical CPU, memory, and I/O among guest VMs and enforces isolation between them — one guest crashing or being compromised does not, by design, affect another.
  2. Each VM boots a full operating system kernel of its own, independent of the host's and of other guests' — strong isolation, but a slow start (a full OS boot: seconds to minutes).
  3. A VM is provisioned from a machine image — a snapshot of a disk with an OS and whatever software was baked into it — and can be resized (usually requiring a restart) or replaced.
  4. VMs attach block storage (→ 178) as virtual disks, persistent independent of the VM's lifecycle if configured that way, so a VM can be destroyed and recreated without losing its data disk.
  5. Because isolation happens at the hardware-virtualization layer, a VM can run any OS and software stack the hypervisor supports — the strongest isolation, least restrictive compute option, at the cost of the most operational burden (OS patching, kernel configuration) and the slowest scaling.

Practical example

(numbers illustrative). Booting a fresh VM from an image typically takes 30–90 seconds before the OS is ready to accept traffic, versus roughly 1–2 seconds for a container (→ 180) using an already-running kernel. For a workload that scales up and down every few minutes, that gap compounds into real latency before new capacity is usable — one reason containers displaced VMs as the default deployment unit for stateless services, while VMs remain the choice when the isolation boundary itself (a different kernel, a licensing requirement, a compliance boundary) is the point.

When to use it

  • Use VMs when you need a specific OS/kernel, strong isolation between tenants or workloads, or software that assumes it owns a whole machine.
  • Use VMs as the substrate underneath other compute — every container runtime and most Kubernetes nodes run on VMs, even when your own workload runs higher up the stack.
  • Avoid VMs as the deployment unit for a stateless service that scales frequently — the boot time and per-instance OS management cost more than containers (→ 180) for no added benefit.
  • Failure scenarios: treating a VM as a pet, not cattle — manual configuration drift accumulating until no one can safely recreate it from the image alone (→ 185 is the fix); forgetting a VM is still one failure domain unless placed across AZs (→ 175) behind a load balancer (→ 92).
  • Simpler alternative: for most application workloads today, a container on a managed compute platform removes the OS-patching burden a raw VM carries — reach for a VM specifically when something about the workload needs that lower-level control.

Practice

(mechanism kind — predict-then-verify; 15–20 min, no lab services; paper exercise by default). On paper, walk one VM through its lifecycle: created from a base image, configured, running an app, destroyed, recreated from the same image. For five artifacts — the OS, an installed package, the app's binary, its in-memory state, and data on a separately attached persistent disk — predict what survives the recreation and why. Optional hands-on, if you already have access to a local VM tool or a provider's free tier: provision a VM, run a trivial HTTP server, destroy and recreate it, and check your predictions. Done when you can state exactly what did and didn't survive recreation.

Key takeaway

A VM virtualizes a whole machine, giving the strongest isolation and broadest compatibility at the highest operational and startup cost. Done when you can: explain why VM isolation is stronger but slower than a container's, and when that trade is worth it. Used next in → 180 (containers, the lighter-weight alternative), → 181 (Kubernetes nodes are usually VMs underneath).

References

None — this topic makes no external claims.

Source directory

Search the guide