Lesson 1 / 10
Module 1Lesson 1⏱ 45 min study

Lesson 1: Modern Infrastructure as Code & Containerized Foundations

Examine the evolutionary shift from bare metal to containerized virtualization, the Linux kernel mechanisms underpinning containers, and declarative target-state management.

✦ Key Architectural Takeaways
  • •Traditional bare-metal and virtualization models suffer from severe library conflicts, host drift, and excessive hypervisor overhead.
  • •Containers are not virtual machines; they are standard Linux processes isolated via kernel namespaces and bounded by control groups (cgroups).
  • •Declarative Infrastructure as Code (IaC) defines the target end-state, allowing automated reconciliation loops to handle convergence.
  • •The Kubernetes Control Plane (API server, etcd, scheduler, controller manager) decouples operational intent from worker node execution.
  • •Ansible provides an agentless, idempotent automation engine that bridges host-level operating systems and cloud-native Kubernetes APIs.

1. The Evolutionary Shift: From Snowflake Servers to Cloud-Native

In traditional IT operations, application deployments were tightly bound to the underlying operating system and host libraries. Upgrading a shared runtime (such as Python, Java, or OpenSSL) to satisfy one application frequently broke neighboring services running on the same machine.

The industry progressed through three distinct architectural eras:

  1. 1Bare-Metal Deployments: Applications ran directly on physical hardware. Scaling required procuring physical servers; disaster recovery was slow; and resource utilization was notoriously poor (often under 15%).
  2. 2Hardware Virtualization (Hypervisors): Type-1 (bare-metal) and Type-2 (hosted) hypervisors introduced Virtual Machines (VMs). Each VM ran a complete guest operating system, virtual BIOS, and virtual hardware drivers. While VMs solved isolation, they introduced heavy CPU/RAM overhead and multi-minute boot cycles.
  3. 3Containerization & Cloud-Native Platforms: Containers virtualize the operating system kernel rather than hardware. Multiple isolated user-space instances share a single, shared Linux kernel, yielding near-instantaneous startup times (milliseconds) and negligible performance overhead.
ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
Traditional Virtual Machines:          Cloud-Native Containers:
+-------------------------------+      +-------------------------------+
| App A   | App B   | App C     |      | App A   | App B   | App C     |
| Bins/Lib| Bins/Lib| Bins/Lib  |      | Bins/Lib| Bins/Lib| Bins/Lib  |
+---------+---------+-----------+      +---------+---------+-----------+
| Guest OS| Guest OS| Guest OS  |      | Container Runtime (CRI-O/Docker)
+---------+---------+-----------+      +-------------------------------+
| Hypervisor (KVM / ESXi)       |      | Shared Host Linux Kernel      |
+-------------------------------+      +-------------------------------+
| Physical Server Hardware      |      | Physical Server Hardware      |
+-------------------------------+      +-------------------------------+
§

2. Under the Hood: Linux Kernel Isolation Primitives

A container is fundamentally a standard Linux process wrapped in two kernel-level enforcement mechanisms:

Linux Namespaces (Visibility Isolation)

Namespaces restrict what a running process can see:

  • PID (Process ID): Virtualizes the process tree. Inside the container, the application process believes it is PID 1, completely isolated from host processes.
  • NET (Network): Provides dedicated loopback (lo), virtual ethernet interfaces (veth), private IP routing tables, and firewall rules.
  • MNT (Mount): Isolates filesystem mount points. The container sees its own root filesystem (/) assembled from container image layers.
  • IPC (Inter-Process Communication): Isolates shared memory segments, semaphores, and POSIX message queues.
  • UTS (UNIX Timesharing System): Allows the container to have its own dedicated hostname and NIS domain name.
  • USER (User ID): Maps a non-root UID inside the container (e.g., UID 1000) to an unprivileged user on the host system, mitigating privilege escalation attacks.

Control Groups (cgroups v1 & v2: Resource Governance)

While namespaces control visibility, cgroups restrict what a running process can consume:

  • CPU: Enforces CPU bandwidth limits via the Completely Fair Scheduler (CFS) quota mechanism (e.g., assigning 50,000 µs of CPU runtime per 100,000 µs quota period limits the process to 0.5 CPU cores).
  • Memory: Enforces hard residential memory limits. If a container exceeds its allocated cgroup threshold, the Linux kernel Out-Of-Memory (OOM) Killer terminates the offending process.
  • BlkIO: Limits read/write input/output operations per second (IOPS) and disk throughput.
§

3. Declarative vs. Imperative Infrastructure Management

In modern systems engineering, how you express operational changes dictates the reliability of your infrastructure:

  • Imperative Approach (Procedural Scripts): Focuses on steps ("Execute command A, download file B, run systemctl restart C"). Imperative shell scripts are fragile: if an execution fails midway, rerunning the script often causes syntax errors, duplicate records, or corrupt states.
  • Declarative Approach (Target-State Configuration): Focuses on desired outcome ("Ensure package nginx is present, configuration file matches template X, and service is running"). The system continuously evaluates the difference between the current state and the desired state, applying only the minimal necessary delta.
ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
Imperative (Step-by-Step):         Declarative (Desired State):
[ Run: apt-get install nginx ]    [ Ensure: state = present   ]
            |                                    |
     (Fails if busy)                             v
            |                         [ Automated Reconciliation Loop ]
[ Run: systemctl start nginx ]                   |
            |                         [ Queries live system state ]
     (Fails if running)                          |
                                      +----------+----------+
                                      |                     |
                              [ Already matches? ]   [ State differs? ]
                                      |                     |
                                (Do nothing: OK)     (Apply delta: CHANGED)
§

4. Kubernetes Control Plane Architecture

Kubernetes is the industry-standard declarative container orchestrator. It consists of a distributed Control Plane and multiple Worker Nodes:

ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
+-----------------------------------------------------------------+
|                  KUBERNETES CONTROL PLANE                       |
|                                                                 |
|  +------------------+     +----------------------------------+  |
|  |  kube-apiserver  |<--->| etcd (Consensus Key-Value Store) |  |
|  +--------^---------+     +----------------------------------+  |
|           |                                                     |
|     +-----+--------------------+                                |
|     |                          |                                |
|  +--v------------------+    +--v-----------------------------+  |
|  |   kube-scheduler    |    |    kube-controller-manager     |  |
|  +---------------------+    +--------------------------------+  |
+-----------^-----------------------------------------------------+
            | TLS REST API (Declarative JSON/YAML)
            v
+------------------------------------+----------------------------+
| WORKER NODE 1                      | WORKER NODE 2              |
|                                    |                            |
|  +-------------------------------+ |  +-----------------------+ |
|  | kubelet (Node Agent)          | |  | kubelet               | |
|  +---------------+---------------+ |  +-----------+-----------+ |
|                  | gRPC (CRI)      |              |             |
|  +---------------v---------------+ |  +-----------v-----------+ |
|  | Container Runtime (CRI-O)     | |  | Container Runtime     | |
|  |  [ Pod A ]    [ Pod B ]       | |  |  [ Pod C ]  [ Pod D ] | |
|  +-------------------------------+ |  +-----------------------+ |
|  | kube-proxy (iptables / IPVS)  | |  | kube-proxy            | |
|  +-------------------------------+ |  +-----------------------+ |
+------------------------------------+----------------------------+

Control Plane Components

  1. 1kube-apiserver: The central management hub and only component that directly talks to the etcd datastore. Exposes the JSON/YAML over HTTPS REST API, handles authentication, authorization (RBAC), and admission controllers.
  2. 2etcd: A distributed, consistent B-tree key-value database built on the Raft consensus algorithm. Stores the entire cluster configuration and real-time state.
  3. 3kube-scheduler: Watches for newly created Pods with no assigned node, evaluates node resource capacities and affinities, and assigns the optimal node.
  4. 4kube-controller-manager: Runs core control loops (Node Controller, ReplicaSet Controller, EndpointSlice Controller) that continuously drive observed cluster state toward the desired specification.
§

5. Why Pair Ansible with Kubernetes?

While Kubernetes excels at orchestrating in-cluster workloads, real-world systems require infrastructure outside the cluster:

  • Bootstrapping cloud virtual networks, subnets, and firewalls (AWS VPC, GCP VPC, Azure VNet).
  • Provisioning managed databases (RDS, Cloud SQL) and cloud storage buckets (S3, GCS).
  • Managing multi-cluster deployments across development, staging, and production environments.
  • Providing a single, cohesive automation language across bare-metal servers, container runtimes, and Kubernetes clusters.

By utilizing Ansible's kubernetes.core collection, platform engineers can orchestrate both external cloud infrastructure and internal Kubernetes manifests in a single unified, reproducible workflow.