Linux

Chapter 13
Virtualization, Containers and Orchestration

Post Graduate Program in Computer Science Engineering
Linux   •   Post Graduate

13. Virtualization, Containers and Orchestration

Introduction and Context

Linux has become the operating foundation for cloud computing, software-defined infrastructure, platform engineering and large-scale distributed systems. Modern services are rarely deployed directly onto a single physical server. Instead, computing resources are abstracted, divided, isolated and managed through virtual machines, containers and orchestration platforms. These technologies allow organizations to use hardware efficiently, deploy software rapidly and operate applications consistently across development, testing and production environments.

Virtualization and containerization are related but not identical. A virtual machine (VM) presents a complete virtual computer, including a virtual processor, memory, storage devices and usually a guest operating system. A container generally shares the host kernel while isolating processes, filesystems, networks and resource consumption. Orchestration systems such as Kubernetes coordinate large numbers of containers across a cluster of machines.

Linux is central to all three layers. The Kernel-based Virtual Machine (KVM) turns the Linux kernel into a hypervisor. Kernel namespaces and control groups (cgroups) provide the fundamental mechanisms used by containers. Linux networking, storage, security controls, service management and observability tools are essential to operating Kubernetes nodes. Consequently, understanding these technologies requires more than learning commands; it requires a model of how isolation, resource allocation, security and automation interact.

Learning Objectives

After completing this chapter, the learner should be able to:

1. Explain virtualization, hypervisors, virtual machines and containers.

2. Compare type 1 and type 2 hypervisors and identify the role of KVM and QEMU.

3. Describe how namespaces and cgroups implement process and resource isolation.

4. Explain OCI images, image layers, registries and container runtimes.

5. Apply Linux security, networking, storage and observability practices to containers.

6. Distinguish container management from Kubernetes orchestration.

7. Evaluate technical, operational, security and organizational trade-offs.

8. Diagnose common virtualization and container deployment problems.

From Physical Machines to Isolated Execution Environments

On a traditional server, applications share the same operating-system environment. They compete for CPU, memory, storage and network capacity, and a failure or configuration change in one application may affect others. Virtualization introduces an abstraction layer that allows several independent operating environments to execute on one physical machine.

A hypervisor, also called a virtual machine monitor, manages virtual machines and mediates access to hardware. It schedules virtual CPUs on physical CPUs, maps guest memory to host memory, provides virtual devices and controls the lifecycle of guests. The guest operating system behaves as if it owns a computer, although its operations are translated or assisted by the host virtualization system.

Type 1 hypervisors run directly on hardware. They are common in data centres because the virtualization layer is the primary operating environment. Type 2 hypervisors run as applications on a conventional host operating system and are common on developer workstations. The distinction is useful conceptually, although modern products may combine characteristics of both categories.

KVM is integrated into the Linux kernel and uses processor virtualization extensions such as Intel VT-x or AMD-V. The kernel module, commonly exposed through `/dev/kvm`, supplies core virtualization functions. QEMU commonly provides machine emulation, virtual devices and the user-space process representing a guest. In practical Linux deployments, KVM and QEMU are frequently used together, often managed through libvirt, `virsh`, virt-manager or cloud platforms.

A VM provides strong isolation because each guest has its own kernel. This makes VMs appropriate when workloads require different operating systems, kernel versions or strict administrative boundaries. The cost is additional memory, storage and boot overhead. A guest operating system also introduces patching, licensing, monitoring and image-management responsibilities.

Containers: Process Isolation Rather Than Hardware Emulation

A container is an isolated execution environment for one or more processes. Unlike a VM, a conventional Linux container does not contain a separate Linux kernel. The containerized process invokes the host kernel, while kernel mechanisms restrict what the process can see and do.

This distinction explains both the efficiency and the security model of containers. Containers usually start quickly and use fewer resources than VMs because they do not boot a complete guest operating system. However, a kernel vulnerability or unsafe privilege configuration can affect the host and other containers. Containers therefore provide isolation, but not automatically the same boundary as a separately managed VM.

The phrase “container” describes an execution model rather than a single product. An image is a packaged filesystem and metadata; a runtime creates and executes a container from that image; an engine may provide image management, networking and user-facing commands; and an orchestrator schedules workloads across machines. Separating these concepts helps administrators diagnose failures accurately.

Namespaces

Linux namespaces control what a process can observe. Important namespace types include:

  • PID namespaces provide an independent process-numbering view. A process may be PID 1 inside a container while having another process identifier on the host.
  • Mount namespaces provide an independent view of mounted filesystems.
  • Network namespaces isolate interfaces, routing tables, firewall rules and sockets.
  • User namespaces map user and group identifiers, potentially allowing a process to be root inside a namespace without being root on the host.
  • UTS namespaces isolate hostname and domain-name information.
  • IPC namespaces isolate System V IPC objects and POSIX message queues.
  • Cgroup namespaces provide a process view of its control-group hierarchy.

Namespaces are not complete security policies by themselves. For example, a process may be isolated in a PID namespace but still possess capabilities that allow dangerous operations. Secure containers combine namespaces with capabilities, seccomp filtering, mandatory access controls, filesystem restrictions and carefully selected privileges.

Control Groups

Control groups, or cgroups, organize processes and control their consumption of resources. Depending on the cgroup version and configuration, administrators can limit or account for CPU, memory, block I/O, process counts and other resources. Cgroups are essential for preventing a single workload from exhausting a node.

A memory limit is not merely a performance setting. If a process exceeds its effective limit, the kernel may reclaim memory or invoke an out-of-memory action. A container can therefore be terminated even when the physical host still has free memory, because the container’s cgroup limit has been reached. CPU limits generally control scheduling time rather than guaranteeing a particular processor frequency.

Cgroups also support hierarchy and delegation. Systemd, container engines and Kubernetes may all create cgroups. Administrators must understand which layer owns a cgroup and how limits are inherited; otherwise, apparently inconsistent resource measurements can result.

OCI Images, Runtimes and Registries

The Open Container Initiative (OCI) defines specifications for container images, runtimes and distribution. An image is normally composed of read-only layers and configuration metadata. Each layer represents a filesystem change, such as installing packages or adding application files. At runtime, a writable layer may be placed above the image layers using a union or overlay filesystem.

Layering promotes reuse and faster distribution, but it does not make images automatically small or secure. A deleted file may remain in an earlier layer, and package caches can increase image size. Multi-stage builds, minimal base images, explicit dependency management and regular cleanup improve image quality.

A registry stores and distributes images. Image references commonly identify a registry, repository and tag. Tags are convenient but mutable; a tag such as `latest` may point to different content at different times. Digest references identify content more precisely and support reproducible deployment. Organizations should use trusted registries, vulnerability scanning, signing or attestation mechanisms where appropriate, and access controls for private images.

A container runtime converts an image into a running process according to the OCI runtime specification. Low-level runtimes such as `runc` or compatible implementations create namespaces, cgroups and process environments. Higher-level tools coordinate images, networking, volumes and container lifecycle. Kubernetes commonly interacts with a container runtime through the Container Runtime Interface rather than directly invoking a particular engine.

Virtual Machines and Containers: A Decision Framework

The choice between VMs and containers should be based on workload requirements rather than fashion. VMs are advantageous when a workload needs a different kernel, stronger fault-domain separation, legacy operating-system support or a clear infrastructure boundary. Containers are advantageous when applications are designed for rapid deployment, process-level portability and high density.

A useful comparison considers five dimensions. First, the isolation boundary differs: VMs isolate guest kernels, while containers share the host kernel. Second, startup and resource overhead are generally higher for VMs. Third, portability has different meanings: a VM packages an operating system environment, whereas a container packages an application userspace but depends on kernel facilities. Fourth, lifecycle management differs: VM images are often treated as infrastructure artifacts, while container images are commonly built and promoted through software-delivery pipelines. Fifth, operational risk differs: containers simplify application packaging but increase the importance of image provenance, runtime privileges and cluster policy.

The technologies can also be combined. Many production Kubernetes clusters run their nodes as VMs. This provides a hardware and kernel boundary between groups of workloads while containers provide application-level packaging and scheduling inside each node. Such nested abstraction is not inherently wasteful; it can offer useful separation when its performance and operational costs are understood.

Container Security as a Layered System

Container security begins with the host. A patched kernel, restricted administrative access, secure boot practices where required, controlled services and reliable audit logging reduce the attack surface. The container runtime and orchestration control plane must also be patched and protected.

At the image layer, developers should minimize packages, avoid embedded credentials, use trusted base images, pin important dependencies and scan for known vulnerabilities. Scanning is valuable but imperfect: a vulnerability database may contain false positives, miss application-level flaws or identify a vulnerable library that is unreachable in practice. It should therefore be combined with software composition analysis, testing and runtime controls.

At runtime, containers should normally run as non-root users. Linux capabilities should be dropped unless specifically needed. Privileged mode, host-network mode, host PID namespaces and direct access to host devices should be treated as exceptional. Seccomp can restrict system calls, while SELinux or AppArmor can impose mandatory access-control policies. Read-only root filesystems and carefully scoped writable volumes reduce the impact of compromise.

Secrets should not be placed in images or source repositories. They should be supplied through an approved secret-management mechanism and rotated according to organizational policy. Network policies, service identities, mutual authentication and encryption in transit become increasingly important as services communicate across hosts.

Security decisions must also respect least privilege and separation of duties. Developers may build images, platform teams may manage clusters, and security teams may define policy. Excessive administrative access to a container engine can effectively become host-root access, so membership in groups such as a runtime administration group requires careful control.

Linux Networking and Storage for Containers

A container network namespace typically contains a virtual interface connected to a bridge or other virtual network on the host. Port publishing connects a host address and port to a process in the container. In multi-host environments, an overlay or routed network may connect workloads across nodes. The exact design affects performance, address management, service discovery and troubleshooting.

Linux administrators should understand virtual Ethernet pairs, bridges, routing tables, network address translation and firewall rules. A service that listens only on `127.0.0.1` inside a container may not be reachable through the expected interface. Similarly, a published port may be blocked by host firewall policy or may bind only to a particular host address.

Container writable layers are generally unsuitable for durable application data. Volumes, bind mounts and network storage provide different performance and lifecycle properties. A bind mount directly exposes a host path and therefore requires careful permission control. A managed volume can be easier to administer consistently. Stateful applications require attention to backup, replication, consistency, recovery time and recovery point objectives; placing a database in a container does not eliminate these responsibilities.

Kubernetes-Oriented Linux Administration

Kubernetes is a control system for scheduling and managing containerized workloads across a cluster. A cluster normally contains a control plane and worker nodes. The control plane stores desired and observed state, schedules workloads and exposes an API. Nodes run an agent, a container runtime and networking components that create the execution environment.

The central Kubernetes idea is declarative management. An administrator describes a desired state, such as the number of replicas, an image and resource requirements. Controllers continuously compare actual state with desired state and take corrective action. This differs from a script that performs a sequence of commands once; the controller model supports reconciliation after failures and changes.

A Pod is the smallest commonly scheduled unit. Containers in the same Pod share a network namespace and may share storage volumes. A Deployment manages stateless replicated Pods and supports controlled updates. A Service provides a stable abstraction for reaching a changing set of Pods. ConfigMaps provide non-secret configuration, while Secrets provide sensitive values, although their storage and access must still be protected. Persistent volumes and claims express storage requirements separately from a Pod specification.

Resource requests influence scheduling, while limits constrain runtime consumption. Incorrectly chosen requests may cause poor bin-packing or scheduling failure; incorrect limits may cause throttling or memory termination. Health checks also have distinct purposes: a liveness probe detects a process that should be restarted, while a readiness probe determines whether it should receive traffic. A startup probe can protect slow-starting applications from premature liveness failures.

Linux expertise remains essential on a Kubernetes node. Administrators investigate systemd services, kubelet logs, cgroup statistics, filesystem capacity, inode exhaustion, kernel messages, DNS resolution, certificate validity and network connectivity. The `kubectl` command is important, but it does not replace node-level diagnosis. A Pod may be healthy from the API perspective while the node is experiencing disk pressure, packet loss or kernel-level failures.

An Illustrative Case: Moving a University Analytics Service to a Cluster

Background

A university research group operates an analytics service used by several departments. The service consists of a web API, a worker process and a relational database. It currently runs on a single Linux server using manually configured services. Deployments are infrequent because researchers fear interrupting users, and resource usage varies substantially during examination periods.

Situation and Problem

The server experiences memory pressure during peak workloads. Configuration differs between development and production, and a failed deployment requires manual restoration. The group proposes moving every component into containers and placing them on Kubernetes immediately.

Analysis

The proposed solution offers benefits, but not every component has the same operational profile. The API and worker are relatively stateless and can be replicated. The database is stateful and requires tested backups, durable storage and recovery procedures. Containerizing it may be possible, but Kubernetes does not automatically provide database correctness or disaster recovery.

The team also discovers that the application image contains development credentials, runs as root and writes temporary files into its image filesystem. Resource requests are absent, so the scheduler cannot make reliable placement decisions. The host nodes are VMs, adding a second layer of resource allocation that must be measured.

Approach and Solution

The team first creates a minimal, versioned image for the API and worker. Credentials are removed from the image and supplied through a secret-management process. The containers run under non-root users with a read-only root filesystem and only the capabilities they require. Image scanning and signed promotion are added to the delivery pipeline.

The API receives explicit CPU and memory requests and limits. A readiness probe prevents traffic from reaching an instance until dependencies are available, while a liveness probe restarts processes that have become unresponsive. A Deployment manages several API replicas, and a Service provides stable internal access. Workers are scaled separately according to queue depth.

The database initially remains on a separately managed service with tested backups. Network policies restrict which workloads may communicate with it. The cluster is monitored for node memory, cgroup pressure, disk capacity, failed probes and deployment errors. A staging environment validates images and manifests before production promotion.

Outcome

Deployments become repeatable and can be rolled back to a known image digest. Peak API demand is handled by additional replicas, while worker capacity is adjusted independently. The database receives clearer operational ownership rather than being treated as an ordinary stateless container. The project does not remove all failures, but it makes assumptions explicit and improves recovery procedures.

Learning Points

The case demonstrates that containerization is not itself an architecture. Successful adoption depends on image discipline, resource modeling, security controls, observability, data management and an appropriate division between platform and application responsibilities. Declarative orchestration is most effective when the desired state is meaningful and operationally supported.

Challenges, Failure Modes and Professional Practice

A common mistake is to assume that a container is a lightweight VM. This leads to inappropriate kernel assumptions, weak security boundaries and poor troubleshooting. Another is to use mutable tags, making it difficult to determine which code is running. Running privileged containers, mounting the host filesystem, exposing the container engine socket or storing secrets in images can convert a limited application compromise into a host or cluster compromise.

Resource settings are another frequent source of failure. Missing limits can permit noisy-neighbour behaviour; limits that are too low cause repeated termination or throttling. Administrators should measure real workload behaviour and distinguish peak usage from average usage. Disk pressure may originate from image layers, container logs, deleted-but-open files or exhausted inodes rather than from application data alone.

Orchestration can also increase complexity. A small service may be easier to operate with systemd and a carefully managed VM than with a multi-node cluster. Kubernetes introduces APIs, controllers, networking, storage plugins, identity systems and upgrade dependencies. Its value is greatest when the organization needs its automation, scaling and reconciliation capabilities and is prepared to operate them responsibly.

Governance should define who may create images, approve registries, access production clusters, change network policies and retrieve secrets. Audit records must be protected and reviewed. Software licenses in base images and dependencies require attention. Data protection obligations may affect image storage, log retention, geographic placement and backup design. Operational convenience must not override confidentiality, integrity, availability or accountability.

Current Developments and Emerging Directions

Several developments are shaping Linux virtualization and container operations. Rootless containers reduce dependence on host-root privileges by mapping container users to unprivileged host identities, although not every feature and workload behaves identically in rootless mode. Confidential computing uses hardware-supported mechanisms to protect data during processing and may complement VM-based isolation. Lightweight virtual machines and sandboxed runtimes seek to combine container workflow with stronger isolation.

The software supply chain is receiving increasing attention. Reproducible builds, provenance attestations, signed artifacts, admission policies and continuous vulnerability assessment help organizations establish where software came from and whether it was modified. These controls are most effective when integrated into development and deployment processes rather than applied only after an incident.

Kubernetes administration is also moving toward policy automation, platform engineering and standardized internal developer platforms. eBPF-based tools provide new approaches to observability, networking and security by instrumenting kernel behaviour with less dependence on application changes. Such tools are powerful but require careful governance, kernel compatibility planning and protection against excessive data collection.

Best-Practice Principles

A mature Linux virtualization and container program generally follows these principles:

  • Select VMs, containers or both according to isolation, portability, performance and operational requirements.
  • Keep hosts, kernels, runtimes and control planes patched and minimize unnecessary services.
  • Build small, reproducible images and deploy immutable digests rather than uncontrolled mutable tags.
  • Treat namespaces as isolation mechanisms, not as a complete security boundary.
  • Apply least privilege through non-root users, reduced capabilities, seccomp and mandatory access controls.
  • Define resource requests, limits, health probes, logging and monitoring before production deployment.
  • Separate application packaging from durable data management and test restoration procedures.
  • Protect registries, secrets, runtime sockets, cluster credentials and administrative APIs.
  • Use staged rollouts, version control, policy review and tested rollback procedures.
  • Diagnose at the correct layer: application, container, runtime, node, network, storage or control plane.

Chapter Summary

Virtualization abstracts physical hardware into independently managed virtual machines, while containerization isolates processes using shared-kernel mechanisms. KVM, usually combined with QEMU and libvirt, provides Linux-based hardware virtualization. Containers depend on namespaces for visibility isolation, cgroups for resource control, filesystem layering for image construction and OCI specifications for portability.

VMs offer a separate guest kernel and generally stronger isolation, whereas containers provide efficient application packaging and rapid startup. The two can be combined, particularly when Kubernetes nodes run inside VMs. Secure container operations require host hardening, trusted images, least privilege, capability reduction, system-call filtering, mandatory access controls, protected secrets and network restrictions.

Kubernetes extends container management through declarative APIs, controllers, scheduling, Services, health probes, resource policies and persistent storage abstractions. Effective administration still depends on Linux knowledge: systemd, cgroups, namespaces, networking, filesystems, logs and kernel behaviour. The central professional lesson is that orchestration does not remove infrastructure responsibilities; it makes them more systematic and, at scale, more demanding.

Key Terms

Virtualization: Abstraction of physical computing resources to create independent execution environments.

Hypervisor: Software or firmware that creates and manages virtual machines.

KVM: Linux kernel technology that uses hardware virtualization extensions to run virtual machines.

QEMU: User-space emulator and virtualizer commonly used with KVM to provide virtual hardware.

Virtual Machine: A software-defined computer with virtual hardware and its own guest operating system.

Container: An isolated process environment that normally shares the host kernel.

Namespace: A Linux kernel mechanism that gives processes an isolated view of selected system resources.

Cgroup: A Linux mechanism for organizing processes and controlling or accounting for resource usage.

OCI: Open Container Initiative specifications for container images, runtimes and distribution.

Image: Layered filesystem content and metadata used to create a container.

Registry: A service that stores and distributes container images.

Container Runtime: Software that creates and executes containers from images.

Capability: A subdivided Linux privilege that can be granted or removed independently.

Seccomp: A Linux facility for filtering system calls available to a process.

Rootless Container: A container operated without requiring host-root privileges.

Kubernetes: A declarative platform for scheduling and managing containerized workloads.

Pod: Kubernetes’ smallest commonly scheduled unit, containing one or more cooperating containers.

Deployment: A Kubernetes controller that manages replicated, usually stateless, Pods.

Readiness Probe: A health check indicating whether a workload should receive traffic.

Resource Request: The resource amount used by Kubernetes when scheduling a workload.

Review Questions

Short Answer Questions

1. What is the principal difference between a type 1 and a type 2 hypervisor?

2. Why do containers normally start faster than virtual machines?

3. What information is isolated by a network namespace?

4. How do cgroups support reliable multi-tenant operation?

5. Why are image digests preferable to uncontrolled mutable tags?

Long Answer Questions

1. Explain the architecture and relationship among KVM, QEMU, libvirt and a guest operating system.

2. Compare virtual machines and containers with respect to isolation, performance, portability and administration.

3. Describe how namespaces, cgroups, capabilities, seccomp and mandatory access controls contribute to container security.

4. Explain Kubernetes’ declarative and reconciliation-based operating model, using Deployments, Services and health probes.

5. Discuss the Linux administration responsibilities of a Kubernetes node, including storage, networking, logging and resource pressure.

Analytical / Application Questions

1. An application requires a custom kernel module, strict tenant separation and a legacy operating system. Would you choose a VM, a container or a combination? Justify the decision.

2. A container is repeatedly killed even though the host has free memory. Analyze the likely relationship between the container’s cgroup limit and the observed failure, and propose diagnostic steps.

3. Design a secure deployment approach for a web API and database on Kubernetes. Address image construction, secrets, resource settings, probes, network access, storage and backup responsibilities.

22. Multiple Choice Questions with Answers

Question 1

Which statement best describes the relationship between KVM and QEMU in a typical Linux virtualization deployment?

A. KVM provides kernel-level virtualization support while QEMU commonly provides virtual hardware and the user-space guest process

B. QEMU is the Linux kernel scheduler and KVM is the container image format

C. KVM is a Kubernetes controller and QEMU is a network policy engine

D. Both are guest operating systems installed inside each virtual machine

Correct Answer: A. KVM provides kernel-level virtualization support while QEMU commonly provides virtual hardware and the user-space guest process

Question 2

A container process can see only its own process-numbering hierarchy while the host can still observe it. Which mechanism primarily provides this behaviour?

A. A CPU cgroup

B. A PID namespace

C. An OCI registry

D. A Kubernetes Service

Correct Answer: B. A PID namespace

Question 3

What is the main operational purpose of a memory limit assigned through a cgroup?

A. To guarantee a fixed processor frequency

B. To prevent the workload from consuming memory beyond its permitted allocation

C. To encrypt all memory pages automatically

D. To create a separate guest kernel

Correct Answer: B. To prevent the workload from consuming memory beyond its permitted allocation

Question 4

Why is deploying a container image by digest generally more reproducible than deploying it by a tag such as latest?

A. A digest identifies specific image content, whereas a tag may be moved to different content

B. A digest automatically removes all vulnerabilities from the image

C. A tag always refers to a private image and a digest always refers to a public image

D. A digest causes the container to run without a kernel

Correct Answer: A. A digest identifies specific image content, whereas a tag may be moved to different content

Question 5

Which configuration creates the greatest avoidable security risk in a conventional container deployment?

A. Running as a non-root user with a read-only root filesystem

B. Using a minimal image with pinned dependencies

C. Running a privileged container with access to host devices without a specific requirement

D. Applying a seccomp profile and dropping unused capabilities

Correct Answer: C. Running a privileged container with access to host devices without a specific requirement

Question 6

In Kubernetes, what is the principal purpose of a readiness probe?

A. To determine whether a Pod should receive network traffic

B. To select the physical CPU frequency of a node

C. To build a new container image

D. To replace the cluster control plane

Correct Answer: A. To determine whether a Pod should receive network traffic

Question 7

A Kubernetes workload has no resource requests. Which consequence is most directly associated with this omission?

A. The scheduler has less reliable information for making placement decisions

B. The workload automatically receives a separate guest kernel

C. The image registry cannot store its image

D. The Pod is guaranteed unlimited memory

Correct Answer: A. The scheduler has less reliable information for making placement decisions

Question 8

Why should a database’s persistent storage and backup strategy be designed separately from the fact that the database runs in a container?

A. Containers automatically destroy all external storage

B. Containerization does not itself provide data durability, consistency or recovery

C. Databases cannot run on Linux

D. Kubernetes Services perform database backups automatically

Correct Answer: B. Containerization does not itself provide data durability, consistency or recovery

Question 9

A process is isolated in several namespaces but retains excessive Linux capabilities. What conclusion is most accurate?

A. Namespaces alone constitute a complete security boundary

B. The process may still perform dangerous operations, so privilege reduction is also required

C. The process must be running inside a type 1 hypervisor

D. The process cannot access any kernel functionality

Correct Answer: B. The process may still perform dangerous operations, so privilege reduction is also required

Question 10

Which scenario most strongly supports choosing a virtual machine rather than only a conventional container?

A. A stateless API requiring rapid replica startup

B. A workload requiring a different kernel and a stronger isolation boundary

C. A short-lived build step using a trusted image

D. A worker process scaled according to queue depth

Correct Answer: B. A workload requiring a different kernel and a stronger isolation boundary

Linux
Chapter 13 of 15