Virtualization and Containerization
1. Hypervisors
A hypervisor (Virtual Machine Monitor) is software or firmware that enables multiple
operating systems to run concurrently on a single physical machine by abstracting
hardware resources.
• Type I (Bare Metal Hypervisor):
- Runs directly on the hardware.
- Examples: VMware ESXi, Microsoft Hyper-V, Xen.
- High performance and security.
• Type II (Hosted Hypervisor):
- Runs on top of a host operating system.
- Examples: Oracle VirtualBox, VMware Workstation.
- Easier to use but slightly less efficient.
Diagram:
[Hardware] → [Hypervisor Type I] → [VMs]
[Hardware] → [Host OS] → [Hypervisor Type II] → [VMs]
2. KVM, QEMU, Xen
• KVM (Kernel-based Virtual Machine): Linux kernel module that turns Linux into a
hypervisor.
• QEMU: Open-source emulator and virtualizer; often used with KVM for hardware
acceleration.
• Xen: Type I hypervisor; widely used in cloud platforms (e.g., AWS EC2).
3. Containers
Containers provide OS-level virtualization, isolating applications using shared kernel
features like namespaces and control groups.
They are lightweight compared to VMs.
• Docker: Popular container platform for packaging and running applications.
• LXC (Linux Containers): Lightweight virtualization using kernel namespaces and cgroups.
• systemd-nspawn: Container tool for spawning lightweight containers using systemd.
Diagram:
[Host OS + Kernel] → [Containers: App1, App2, App3] (Shared kernel, isolated user-space)
4. OS-level Virtualization and Namespaces
Namespaces provide process isolation at the OS level by restricting visibility of system
resources:
• PID Namespace – Isolates process IDs.
• Mount Namespace – Isolates filesystem mount points.
• Network Namespace – Provides isolated network interfaces.
• IPC Namespace – Isolates inter-process communication.
• UTS Namespace – Isolates hostname and domain name.
• User Namespace – Isolates user and group IDs.
5. Activity: Deploy and Configure Docker Containers
Objective: Learn how to deploy and configure Docker containers with various images.
Steps:
1. Install Docker on the host machine.
2. Pull images from Docker Hub (e.g., nginx, mysql, ubuntu).
Command: docker pull nginx
3. Run containers from images.
Command: docker run -d -p 80:80 nginx
4. Inspect running containers.
Command: docker ps
5. Configure multiple containers to interact (e.g., web server + database).
6. Use docker-compose to define multi-container applications.
7. Stop and remove containers when not needed.