InfrastructureVol. 6 · Part VI
0 / 0

Shelves / Infrastructure

IN·00

Start Here: Where Your Code Actually Runs

For readers who have written programs but never deployed one: the layers between your code and the hardware, the same small web service run four ways (as a process, a container, two Kubernetes pods, and behind NGINX) with real output, the vocabulary of the volume, and how to study it.

7 topics · ~5 min read · 10-question quiz
Updated Suggest a correction

Start here: how to use this volume

Two reading paths

This volume is about the machinery your software runs on: Linux, containers, Docker, reverse proxies, Kubernetes and deployment strategies. Every chapter has the same shape: a plain-language Start here section with small, verified experiments; a How deep to go ladder; the full-depth sections; a Lab of real measurements; and a Revision sheet.

  • New to infrastructure? Read this chapter, then the chapters in order. Everything here was run on one Linux virtual machine (Ubuntu 24.04, kernel 6.18, 2 CPUs, 8 GB) with Docker 29, NGINX 1.24, HAProxy 2.8 and k3s 1.37 (a complete, certified Kubernetes in one binary). You can reproduce it on any Linux machine, a cloud VM, or WSL2.
  • Experienced? Skip this chapter. In each chapter read the revision sheet first, take its quiz, then use How deep to go to choose the internals and lab experiments to study.

Mastery levels

Every chapter uses the same six levels:

Level Name You can… Example for containers
L1 Recognition define it and spot it "that's a container image layer"
L2 Working use it correctly write a multi-stage Dockerfile and run it with limits
L3 Internals explain why it works explain namespaces, cgroups and overlay filesystems
L4 Debugging diagnose failures find why a container is OOM-killed at half its limit
L5 Design choose between approaches decide on base images, users and resource policies for a fleet
L6 Production run it at scale operate clusters with admission policies, image signing and SLOs

The layers under your code

From a program to a service

When you run java -jar app.jar or ./tiffin on your laptop, a lot happens that you never see: the kernel loads the program into a new process, gives it memory, schedules it on a CPU, lets it open files and network sockets, and keeps it from touching other processes' memory. On a server, more layers are added on top, each answering a question your laptop never asked:

Layer Question it answers Chapter
Linux kernel and userland How do processes, files, users, networking and storage work? 79
Container How do I package the program with its dependencies and isolate it? 80
Docker (or Podman, Buildah) How do I build, ship and run container images? 81
Reverse proxy / gateway How does traffic from the internet reach the right instance, safely? 82
Kubernetes How do I run many copies on many machines and keep them running? 83
Deployment strategy How do I change the running version without breaking users? 84
hardware: CPUs, memory, disk, network card Linux kernel: processes, namespaces, cgroups, filesystems, TCP/IP process: ./tiffin, pid 26669, listening on :8080 container: own filesystem, pid 1, uid 1000, 64 MiB limit pod × 2 + Service: Kubernetes keeps 2 running reverse proxy: TLS, routing, load balancing
The same program inside more and more layers. Each layer adds packaging, isolation, scheduling or routing, but underneath it is always a Linux process.

One program, four ways

tiffin is a 5.7 MB Go web service written for this volume. It answers every request with a description of where it's running: hostname, process ID, user ID and the memory limit it can see. Here it is run four ways on the same machine:

Text
== 1) a plain process on the host
{"hostname":"vm","memory_limit":"9223372036854771712","pid":26669,"service":"tiffin","uid":0,"uptime_s":0,"version":"v1"}
stopped cleanly
== 2) a container (Docker, 64 MiB memory limit)
{"hostname":"af1f73fff56f","memory_limit":"67108864","pid":1,"service":"tiffin","uid":1000,"uptime_s":1,"version":"v1"}
stopped cleanly
== 3) two pods in Kubernetes behind a Service
{"hostname":"tiffin-64d67c4459-ggnbk","memory_limit":"67108864","pid":1,…}
{"hostname":"tiffin-64d67c4459-bbghw","memory_limit":"67108864","pid":1,…}
== 4) two processes behind NGINX as a reverse proxy
answered by pid 29577
answered by pid 29578
answered by pid 29577
answered by pid 29578

Read the differences, because they're the whole volume in miniature:

  • As a plain process it saw the real hostname, a real PID, ran as root (uid 0), and had no memory limit (that huge number means "unlimited").
  • In a container it believed it was PID 1 on a machine called af1f73fff56f, ran as user 1000, and could see its 64 MiB limit. Nothing was emulated: it was still a normal Linux process, but the kernel gave it its own view (namespaces) and its own limits (cgroups). Chapter 80 builds one by hand.
  • In Kubernetes two copies (pods) ran, and one stable Service address spread requests across both. If one dies, Kubernetes starts another.
  • Behind NGINX, a reverse proxy alternated requests between two processes: the basis of load balancing, TLS termination and routing in chapter 82.

Both the container and the process printed stopped cleanly: when asked to stop, they received SIGTERM, finished in-flight requests and exited. That small detail is what makes zero-downtime deployments possible (chapter 84).

How to study infrastructure

A routine that works

  1. Type the commands. Infrastructure is learned with your hands; copying output into your head doesn't stick.
  2. Break things on purpose. Kill processes, fill disks, exceed memory limits, misconfigure a proxy, then read the error messages and logs until you understand them.
  3. Look underneath. For every abstraction, find the Linux mechanism: a container is a process in ps, a Service is iptables rules, a volume is a mount.
  4. Write it down as code. Dockerfiles, Compose files, Kubernetes manifests and proxy configs belong in version control.

Warm-up exercises

  1. Run ps -ef, ss -tlnp, df -h and free -m on a Linux machine and explain one line of each.
  2. Start any web server, find its PID, list its open files in /proc/<pid>/fd, and send it SIGTERM.
  3. Run a container with --memory 64m and look at /sys/fs/cgroup from inside it.
  4. Draw the four runs above as boxes and arrows, marking where the request enters and which process answers.

Glossary

  • Kernel: the core of the operating system, managing hardware, processes and memory.
  • Process: a running program with its own memory, PID and resources.
  • Container: a process (or group) with isolated views and resource limits, started from an image.
  • Image: a packaged filesystem plus metadata from which containers start.
  • Pod: Kubernetes' smallest unit: one or more containers sharing network and storage.
  • Service: a stable address that load-balances across matching pods.
  • Reverse proxy: a server that accepts client connections and forwards them to backends.
  • Signal: a notification sent to a process, such as SIGTERM (please stop) or SIGKILL (stop now).