Kubernetes vs Virtual Machines
Kubernetes vs virtual machines is a comparison between containers and full guest operating systems. Containers share one kernel. Virtual machines each carry a full guest system.
A virtual machine carries a full system
Each virtual machine boots its own guest operating system. That boot takes time and memory.
docker run --rm nginx:1.27 echo readyA container shares the kernel
A container uses the host kernel. It starts in under a second and uses little memory.
docker run --rm nginx:1.27 echo readyMany containers fit on one machine
Containers share one kernel. Dozens of containers can run where only a few virtual machines fit.
kubectl get podsKubernetes sits on top of containers
Kubernetes schedules containers across machines. Those machines can be physical or virtual.
kubectl get nodesExample
docker run --rm nginx:1.27 echo readyKey points
- Virtual machine: a whole computer in software, with its own guest operating system.
- Kernel: the core of an operating system that talks to the hardware.
- Container: a package that shares the host kernel instead of carrying its own.
- Hypervisor: the software that runs virtual machines on one physical machine.
- Use virtual machines to run different operating systems on one physical machine.
- Use containers to run many apps on one kernel with less overhead.
In this example, the command runs a container from the nginx image. The container prints the word ready and then stops. It shares the host kernel, so it starts fast and needs no guest operating system boot.
Note
Kubernetes runs on containers, not on virtual machines directly.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What does a virtual machine carry that a container does not?