Find a course

Module 2: Core Building BlocksLesson 4 of 1211 min

Compute: Virtual Machines, Containers and Functions

Understand virtualization, choose virtual machine sizes, see why containers and Kubernetes became popular, and know when to use each kind of compute.

Step 1 of 13Learn

One physical server, many machines

Cloud compute rests on virtualization. A physical server with, say, 128 CPU cores and 1 TB of memory runs a thin layer of software called a hypervisor, which divides it into many isolated virtual machines (VMs). Each VM behaves like a complete computer with its own operating system, virtual CPUs (vCPUs), memory, disks and network card, and has no idea that other customers' VMs share the same hardware.

In the cloud, a VM is often called an instance. You choose:

  • An image: the operating system and any preinstalled software, such as Ubuntu Linux or Windows Server.
  • An instance type or size: how many vCPUs and how much memory. Providers offer families tuned for different jobs: general purpose (balanced), compute optimized (more CPU per GB of memory, for number crunching), memory optimized (for large databases and caches), storage optimized and accelerated instances with GPUs for machine learning and graphics.
  • Storage volumes and networking settings.

A few minutes later the instance is running and you connect with SSH (Linux) or Remote Desktop (Windows). You're billed while it runs, usually per second or per hour, so stopping instances you don't need, such as development servers overnight, saves money immediately.

VMs give maximum control and run almost anything, but you manage the operating system: patches, security settings, monitoring and software installation.

Step 2 of 13Practice · Diagram

Virtualization, top to bottom

Tap the layer that divides one physical server into many virtual machines.

Tap the shape that answers the question, then press Check.

Virtualization, top to bottomLayer diagram: Apps, Guest operating systems, Hypervisor, Physical server.AppsGuest operating systemsHypervisorPhysical server
Apps

Each customer's software.

Guest operating systems

Each VM runs its own OS.

Hypervisor

Splits the server and keeps VMs isolated.

Physical server

CPU cores, memory, disks, network cards.

Step 3 of 13Learn

Choosing the right size

Choosing an instance type is a balancing act. Too small and the application is slow or crashes; too large and you pay for capacity that sits idle. Many organizations find that a large share of their cloud servers are oversized, sometimes running at 10–20% CPU all month.

A practical approach:

  1. Start with an educated guess based on what the application used before, or a general-purpose size.
  2. Measure CPU, memory, disk and network use under realistic load with the provider's monitoring tools.
  3. Rightsize: move to a smaller size if usage stays low, or a different family if one resource is the bottleneck. A database that's short on memory but barely using CPU belongs on a memory-optimized type, not a bigger general-purpose one.
  4. Repeat as the application changes.

Two ways to get more capacity come up constantly:

  • Scale up (vertical scaling): move to a bigger instance. Simple, but there's a ceiling, it usually needs a restart, and one large machine is still a single point of failure.
  • Scale out (horizontal scaling): add more instances of the same size behind a load balancer. This is how cloud apps handle large and changing loads, and it improves resilience, but the application must be designed to run as several copies.

Step 4 of 13Practice · Sort into groups

Sort each change by whether it is scaling up (vertical) or scaling out (horizontal).

Tap an item, then tap its group (or drag it there).

Step 5 of 13Compare

Scaling up vs scaling out

AspectUp (vertical)Out (horizontal)
What changesA bigger machineMore machines
LimitThe largest instance typePractically very high
DowntimeOften a restartNone: add instances behind a load balancer
If one failsEverything stopsOthers keep serving

Step 6 of 13Learn

Containers and Kubernetes

A container packages an application together with everything it needs, its libraries, runtime and settings, into a single image that runs the same way on a laptop, a test server or in the cloud. That ends the classic "it works on my machine" problem.

Containers vs. VMs: a VM virtualizes the hardware and carries a full operating system, often gigabytes in size and taking a minute or more to boot. Containers share the host's operating system kernel and isolate only the application, so they're typically megabytes in size and start in seconds or less. One VM can run dozens of containers. The trade-off is weaker isolation than full VMs, which is why cloud providers often run containers inside VMs.

Docker popularized containers. When you run hundreds of containers across many machines, you need something to decide where each runs, restart failed ones, scale them and connect them. That's a container orchestrator, and Kubernetes, originally developed at Google and now open source, is the dominant one. All major clouds offer managed Kubernetes (such as EKS, AKS and GKE) and simpler serverless container services that run a container without you managing any cluster.

A common modern design is microservices: an application split into small services, each in its own container, that can be developed, deployed and scaled independently. It's powerful for large teams, but adds complexity that small applications often don't need.

Step 7 of 13Compare

VMs vs. containers vs. serverless functions

AspectVirtual machineContainerServerless function
What you manageOperating system and everything aboveContainer image; orchestration unless managedOnly the function code
Startup timeTens of seconds to minutesSeconds or lessMilliseconds, plus occasional cold starts
Typical sizeGigabytesMegabytesSmall code package
BillingPer second or hour while runningPer resources of the hosts or tasksPer request and compute time
Best forLegacy apps, full control, special OS needsPortable apps and microservicesEvent-driven and spiky workloads

Step 8 of 13Practice · Match the pairs

Match each term to its description.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Hypervisor
  2. Instance type
  3. Container image
  4. Kubernetes
  5. Image (VM)

Step 9 of 13Practice · True or false

Containers usually start faster than virtual machines because they share the host's operating system kernel instead of booting their own operating system.

Step 10 of 13Note

Step 11 of 13Compare

Pets vs cattle

AspectPetsCattle
Names"zeus", "athena"web-001 to web-040
Built byHand, over yearsAutomation, from an image
When sickNursed back to healthReplaced automatically
Fits the cloud?PoorlyWell: autoscaling and self-healing

Step 12 of 13Practice · True or false

Stopping a development VM overnight usually stops the compute charges for those hours, though attached storage keeps billing.

Step 13 of 13Practice · What would you do?

What would you do?

A company's monitoring shows a VM running its reporting app at 8% CPU and 20% memory around the clock. The VM is a large, memory-optimized type. What should they do?