LS·202
Phase 6 — Infrastructure
The sixth phase: Linux, Docker, networking, reverse proxies and Kubernetes, ending with your application containerised and deployed locally; the order and why, an entry check, step-by-step exit checks mapped to Volumes 1 and 6, the project with milestones and definitions of done, traps, a time budget, and a lab that builds a container's isolation from Linux primitives.
Start here: Phase 6 in one page
Your application has to run somewhere. Phase 6 teaches where and how: on Linux, inside containers, behind a reverse proxy, orchestrated by Kubernetes. The project takes the application from Phases 2–5 and runs it locally the way it will run in production: containerised, with a database and cache, behind a proxy, on a local Kubernetes cluster.
The sequence
Linux → Docker → networking → reverse proxy → Kubernetes
Containers are Linux features, so Linux comes first. Docker packages and runs containers. Container networking (bridges, ports, DNS) connects them. A reverse proxy puts one front door in front of many services. Kubernetes runs all of it across machines and keeps it running.
A container is a process with walls
The lab built a container's isolation by hand with two Linux commands:
- In a new PID namespace, a shell saw itself as PID 1 and only 4 processes, while the host had 76.
- In a new network namespace,
curl 127.0.0.1:9501got connection refused, even though a server was listening on that port on the host: the namespace had its own, empty loopback. - In a memory cgroup limited to 100 MB, a program using 50 MB ran normally and one using 150 MB was killed by the kernel's OOM killer.
Docker and Kubernetes add images, networking, scheduling and management on top, but every container is still a Linux process isolated with namespaces and limited with cgroups. That's why OOMKilled, CrashLoopBackOff and "works on my machine but not in the container" are Linux problems first.
How deep to go in Phase 6
Volume 17 defines six mastery levels; Phase 6's exit targets are:
| Topic | Exit level | What that means here |
|---|---|---|
| Linux | L3 | processes, permissions, systemd, logs, networking tools, performance tools |
| containers and Docker | L3 | namespaces, cgroups, images, layers, multi-stage builds |
| networking | L3 | bridges, NAT, ports, DNS in containers |
| reverse proxies | L2–L3 | routing, TLS termination, load balancing, health checks |
| Kubernetes | L2–L3 | pods, deployments, services, ingress, config, probes, resources |
The sequence, step by step
| Step | Learn | Read | Exit check |
|---|---|---|---|
| 1 | Linux: processes, files, permissions, systemd, networking and performance tools | Vol. 6, Start Here, ch. 79; Vol. 1, ch. 8–9 review | diagnose a stuck process and a full disk on a VM |
| 2 | containers from first principles | Vol. 6, ch. 80 | reproduce the lab: namespaces and a cgroup limit |
| 3 | Docker: images, layers, multi-stage builds, compose | Vol. 6, ch. 81 | a small, non-root, multi-stage image of your app |
| 4 | container networking and DNS | Vol. 6, ch. 81 | app, database and cache talking by name in compose |
| 5 | reverse proxies and gateways | Vol. 6, ch. 82 | nginx or Traefik with TLS and two backends |
| 6 | Kubernetes core objects | Vol. 6, ch. 83 | deploy the app to a local cluster (kind, k3d, minikube) |
| 7 | deployment strategy, probes, resources | Vol. 6, ch. 84 | a rolling update with zero failed requests |
Entry check
A working application from Phases 2–5 (backend, database, optionally frontend) and comfort with the command line.
The phase project: containerise and deploy the application locally
Goal. Your application running on a local Kubernetes cluster as it would in production.
Milestones. Dockerfiles (multi-stage, non-root, small) for each service → compose file for local development → reverse proxy with TLS → Kubernetes manifests (or Helm/Kustomize): deployments, services, ingress, config maps, secrets → database with a persistent volume (or a managed-like local instance) → probes and resource requests/limits → a rolling update under load with zero errors → a runbook for "pod keeps restarting".
Done when. One command brings up the whole system locally; images are under an agreed size and run as non-root; a rolling update under load produces no failed requests; killing a pod is recovered automatically; the runbook works for someone else.
Stretch. Add NetworkPolicies that allow only the needed connections, and prove a blocked one fails.
Common traps
- Learning Kubernetes before Linux and containers: every error message becomes mysterious.
- Huge images with build tools and secrets baked in.
- Running as root in containers.
- No probes or resource requests, so Kubernetes can't manage the app well.
latesttags that make deployments non-reproducible.
Exit criteria
- [ ] The project meets its "done when" list.
- [ ] I can explain namespaces and cgroups and diagnose an OOM kill.
- [ ] I can debug a pod that won't start (image, config, probe, resources) with
kubectl describeand logs. - [ ] I can explain how a request reaches a pod through ingress and a service.
- [ ] I scored at least 80% on 40 questions from Volume 6's quizzes, twice.
Time budget
Volume 6 is about 41,000 words (3 hours of reading) plus Linux review; with practice, about 12 hours, plus 2–3 weeks for the project: about 5–6 weeks at 8 hours a week.
Lab: a container's walls, built by hand
Setup. The lab machine's Linux kernel; unshare from util-linux for namespaces; the cgroup v1 memory controller for a limit; Python for the workloads. Run as root (as container runtimes do).
Experiment 1: a PID namespace
processes visible on the host: 76
inside: shell is PID 1; processes visible: 4
unshare --pid --fork --mount-proc gave the shell its own process-ID space and a fresh /proc; it saw itself as PID 1 and only its own descendants. This is why a container's main process is PID 1, and why it must handle signals (SIGTERM) and reap zombie children, jobs an init system normally does (hence tini or --init).
Experiment 2: a network namespace
host -> 127.0.0.1:9501: HTTP 200
new net namespace -> 127.0.0.1:9501: connection refused (its own loopback, no server there)
The server was listening on the host's loopback. Inside a new network namespace, 127.0.0.1 belongs to a different, empty network stack. Container runtimes connect namespaces with virtual Ethernet pairs and a bridge, then publish ports with NAT. Classic consequence: an app inside a container that listens on 127.0.0.1 can't be reached from outside it; it must listen on 0.0.0.0.
Experiment 3: a memory cgroup
A cgroup with memory.limit_in_bytes = 100 MB:
| Program | Result |
|---|---|
| allocates and touches 50 MB | ran normally |
| allocates and touches 150 MB | killed by the OOM killer; oom_kill counter 0 → 1 |
Afterwards the cgroup reported failcnt 97 (allocations that hit the limit) and a maximum usage of exactly 100 MB. In Kubernetes this is the OOMKilled status with exit code 137; the fix is either more memory or a smaller footprint (for the JVM, heap and off-heap settings that respect the container limit).
What Docker and Kubernetes add
Images (a layered root filesystem), a mount namespace with that filesystem, user namespaces, capability dropping, seccomp filters, networking and port publishing, and lifecycle management; Kubernetes adds scheduling, restarts, rollouts and services. Underneath, it's still these primitives.
Try it yourself
- Add
--netand--mountto Experiment 1 and list what you can and can't see. - Create a veth pair between the host and a network namespace and reach the server through it.
- In a cgroup with a 200 MB limit, run a JVM with and without
-XX:MaxRAMPercentage=75and observe heap sizing. - Run your app's container and trigger an OOM kill on purpose; find the evidence in
docker inspectorkubectl describe pod.
Revision sheet: Phase 6, infrastructure
Key ideas
- Sequence: Linux → Docker → networking → reverse proxy → Kubernetes.
- Containers = processes + namespaces (visibility) + cgroups (limits) + an image filesystem.
- Images: multi-stage, small, non-root, pinned by digest.
- Kubernetes: declarative desired state; pods, deployments, services, ingress, probes, resources.
Numbers to remember
- Lab: PID namespace showed 4 processes vs 76 on the host; net namespace refused the host's 127.0.0.1 server; 150 MB in a 100 MB cgroup was OOM-killed.
- OOMKilled exit code: 137 (128 + SIGKILL 9).
- Budget: ~12 study hours + 2–3 project weeks ≈ 5–6 weeks at 8 h/week.
Pitfalls
- Kubernetes before Linux.
- Apps listening on 127.0.0.1 inside containers.
- Root containers, fat images,
latesttags. - Missing probes and resource requests.
Glossary
- Namespace: a kernel feature isolating a view of a resource.
- cgroup: a kernel feature limiting and accounting resources.
- Multi-stage build: building in one image stage and copying artefacts into a minimal runtime stage.
- Ingress: Kubernetes routing of external HTTP traffic to services.
- Probe: a check Kubernetes runs to decide readiness, liveness or startup.