Isolation: namespaces, cgroups and the runtime
A container is an ordinary Linux process that namespaces fence in and cgroups meter. Learn which boundaries a pod shares, how limits are enforced, and how Docker's networks and volumes map onto pods.
Shows the lesson one block at a time. Arrow keys step, number keys jump to a scene, and Escape returns to the page where you were.
A container is not a small virtual machine. It is an ordinary process on the node’s kernel that the runtime starts inside a set of Linux namespacesKernel features that give a process its own view of one resource, such as process IDs, network interfaces, mount points or hostname. and a cgroupA control group: a kernel node that meters and caps the CPU, memory and I/O used by the processes inside it.. Namespaces decide what the process can see; cgroups decide how much it can use. Everything a pod spec says about isolation and resources becomes one of the two.
Reconcile, in 6 scenes
Namespaces draw the boundaries
Linux has eight namespace types: mount, PID, network, IPC, UTS (hostname), user, cgroup and time. When the runtime creates a pod it first starts a tiny sandbox (the pause container) that holds the pod’s network, IPC and UTS namespaces, then starts each container inside them. So the containers of one pod share an IP address, localhost, the port space and a hostname. Each keeps its own mount namespace, so it sees only its own image’s filesystem plus the volumes it mounts, and its own PID namespace unless the pod sets shareProcessNamespace: true.
kubectl get pod pair -o jsonpath='{.status.podIP}'
10.244.3.2
kubectl exec pair -c web -- hostname
pair
kubectl exec pair -c sidecar -- hostname
pair
kubectl exec pair -c sidecar -- ps
PID USER TIME COMMAND
1 root 0:00 sh -c sleep 3600
41 root 0:00 pskubectl exec pair -c sidecar -- ls /usr/share/nginx/html
ls: /usr/share/nginx/html: No such file or directory command terminated with exit code 1
kubectl exec pair -c web -- id
uid=0(root) gid=0(root) groups=0(root)
The sidecar sees only its own processes and none of nginx’s files, yet it reports the same hostname and lives at the same pod IP. Two containers in one pod that both listen on port 80 collide, exactly as two processes on one host would. The id output matters later: nginx runs as root, and without a user namespace that is UID 0 on the node.
cgroups meter the resources
The kubelet and the runtime give every pod a cgroup and every container a child cgroup beneath it, and translate the container’s resources into cgroup v2 files:
| Pod spec | cgroup v2 file | What the kernel does |
|---|---|---|
requests.cpu | cpu.weight | Shares CPU in proportion when the node is busy; not a cap. |
limits.cpu | cpu.max | A quota per period. Once the quota is spent, the container is not scheduled until the next period: throttling. |
limits.memory | memory.max | Memory in use cannot be throttled. At the limit the kernel reclaims what it can, such as page cache, and if that is not enough it OOM-kills a process in the cgroup. |
Memory requests are not written to a cgroup by default; the scheduler uses them for placement and the kubelet for eviction order. MemoryQoS, beta and enabled by default in Kubernetes 1.37, writes them to memory.min or memory.low only when the kubelet’s memoryReservationPolicy is set to TieredReservation. The simulator’s leaky image grows its memory until the limit stops it:
kubectl get pod leaky
NAME READY STATUS RESTARTS AGE leaky 1/1 Running 1 (4s ago) 20s
kubectl get pod leaky -o jsonpath='{.status.containerStatuses[0].lastState.terminated.reason} {.status.containerStatuses[0].lastState.terminated.exitCode}'
OOMKilled 137
Exit code 137 is 128 plus signal 9, SIGKILL. The container restarted; the pod and its IP stayed.
Both halves are on the node for one pod. Press X-ray on pair and pick a layer: the sandbox holds the namespaces its two containers share, each container owns the rest, and the cgroup layer is where the kubelet wrote the files in the table above.
ExplainerThe Linux under a pod
Six layers sit under this pod. Press X-ray to lift them apart.
Sandboxon kx-worker3
docker exec kx-worker3 crictl pods --name pairPOD ID CREATED STATE NAME NAMESPACE ATTEMPT RUNTIME 301df3779cdcc 19 seconds ago Ready pair default 0 (default)
The only layer kubectl shows. Everything under it exists because the kubelet on kx-worker3 turned this object into calls to containerd: a sandbox, then a container for each entry in spec.containers.containerd starts the pause process first. It holds the network, UTS and IPC namespaces every container in the pod joins, so they share one IP, localhost and a hostname.The container is these processes: PID 1 inside it is pid 648 on the node, with 4 more. It has its own mount, PID and cgroup namespaces and joins the sandbox's others.With no limits.cpu, cpu.max is max 100000, no ceiling, and with no requests.cpu the kubelet gives it 2 shares, cpu.weight 1. With no limits.memory, memory.max is max: the fill is memory.current against the node's memory.kindnet's ptp plugin made a veth pair: eth0 inside the pod and veth5bca4d3b on the node, with a /32 route to 10.244.3.2 through it. kube-proxy's DNAT sends Service traffic down the same route.The root is an overlay of read-only image layers under one writable layer that goes when the container does. Volumes are bind mounts from the node's disk, or tmpfs for Secrets and the service account token.
cgroup v2 is the single unified hierarchy at /sys/fs/cgroup; stat -fc %T /sys/fs/cgroup/ prints cgroup2fs on a v2 node and tmpfs on v1. cgroup v1 entered maintenance mode in Kubernetes 1.31 and has been deprecated since 1.35. From 1.35 the kubelet’s failCgroupV1 setting defaults to true, so a kubelet refuses to start on a cgroup v1 node unless an administrator sets it to false, a temporary override.
The runtime stack
On every node the chain is the same: the kubelet speaks CRI to containerd or CRI-O, which pulls and unpacks images and asks an OCI runtime (runc or crun) to create each process with its namespaces and cgroup. Kubernetes 1.36 and later need containerd 2.0 or later:
kubectl get node kx-worker -o jsonpath='{.status.nodeInfo.containerRuntimeVersion}'
containerd://2.3.4
Docker Engine is not in that chain. The kubelet’s dockershim was removed in 1.24, and Docker Engine can serve as a node runtime only through the external cri-dockerd adapter.
A RuntimeClassA cluster-scoped object that maps a name to a handler configured in the node’s CRI runtime, so a pod can choose a different OCI runtime. swaps the bottom of the stack. A RuntimeClass named gvisor with handler: runsc sends any pod that sets runtimeClassName: gvisor to gVisor, which intercepts system calls in a user-space kernel; Kata Containers runs each pod in a lightweight VM instead. Both narrow what a kernel exploit can reach, at a cost in start time and overhead.
Docker networking versus the pod network
Docker’s default bridge (docker0, usually 172.17.0.0/16) hides containers behind the host with NAT. docker run -p 8080:80 adds iptables DNAT rules in chains Docker manages, and Docker’s documentation says not to modify those rules. User-defined bridge networks add name resolution through an embedded DNS server at 127.0.0.11, and multi-host overlay networks need Swarm mode; a standalone container can join an overlay network only if the network was created with --attachable.
Kubernetes replaces all of that with one rule: every pod gets its own IP that every other pod can reach without NAT. There is no port publishing between pods. A Service gives a set of pods a stable virtual IP and DNS name, and a NodePort, LoadBalancer or Gateway takes traffic into the cluster.
Two Compose habits mislead. expose is documentation: containers on the same user-defined network reach every listening port of their peers anyway. And ports: ["80"] does not keep a port internal; it publishes container port 80 on a host port the runtime picks. Compose V1 (docker-compose) stopped receiving updates in July 2023; the V2 plugin is docker compose.
Docker volumes versus pod volumes
A container’s writable layer disappears with the container in both worlds, whether it is an overlayfs snapshot on a containerd node or lives in a Docker host’s storage driver (overlay2, or the containerd image store on fresh Docker Engine 29 installs). What survives is a volume:
| Docker or Compose | Kubernetes |
|---|---|
Named volume (docker run -v pgdata:/var/lib/postgresql postgres:18) | PersistentVolumeClaim, bound to a PersistentVolume |
Bind mount (-v /home/me/src:/app) | hostPath, which Pod Security baseline forbids; avoid it for workloads |
--tmpfs /cache | emptyDir with medium: Memory, counted against the container’s memory limit |
Compose secrets:, mounted at /run/secrets/<name> | A Secret mounted as a volume |
depends_on | No equivalent: init containers, readiness probes and retries |
docker volume inspect shows the driver and mount point but not which containers use a volume; docker ps -a --filter volume=<name> answers that. In Compose files, the preferred name is compose.yaml, and the top-level version key is obsolete: Compose warns about it, ignores it and validates every file against the Compose Specification. Compose secrets work without Swarm. On Docker Desktop for Mac, bind mounts cross into Docker Desktop’s Linux VM, through VirtioFS by default, so they are slower than bind mounts on a Linux host.
What a container is not
Containers share the node’s kernel. A kernel exploit from inside a container reaches the host unless something narrows it, and the default leaves a lot open. Without a user namespace, root in a container is UID 0 on the node, held back only by the capability set, seccomp and Linux security modules such as AppArmor or SELinux. User namespaces are off by default everywhere: Docker needs daemon-wide userns-remap, and a pod needs hostUsers: false, GA in Kubernetes 1.36. They also need Linux 6.3 or later and containerd 2.0 or CRI-O 1.25 or later.
Seccomp is not on by default either: unless the kubelet sets seccompDefault: true, a pod without a seccompProfile runs Unconfined. A hardened pod asks for every layer explicitly:
apiVersion: v1
kind: Pod
metadata:
name: hardened
spec:
hostUsers: false
securityContext:
runAsNonRoot: true
runAsUser: 10001
seccompProfile:
type: RuntimeDefault
containers:
- name: app
image: ghcr.io/kx-labs/web:1.1
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 500m
memory: 128Mi
A non-root process here can still bind port 80: unprivileged ports start at 1024 on a host, but Docker, and containerd 2.0 and later through enable_unprivileged_ports, set net.ipv4.ip_unprivileged_port_start=0 in every container network namespace that is not the host’s. Where a shared kernel is not enough, a sandbox runtime through RuntimeClass, such as gVisor, Kata Containers or Firecracker microVMs, puts a second boundary between workload and host; platforms built on microVMs accept container images only as a packaging format. And the image you run should be the one you signed: Docker announced the retirement of Docker Content Trust (Notary v1) in July 2025, so sign with Sigstore cosign or Notation.
kubectl --context kind-kx run boundaries --image=nginx:1.30kubectl --context kind-kx wait --for=condition=Ready pod/boundaries --timeout=60skubectl --context kind-kx exec boundaries -- cat /sys/fs/cgroup/cpu.maxkubectl --context kind-kx exec boundaries -- cat /sys/fs/cgroup/memory.maxkubectl --context kind-kx exec boundaries -- idkubectl --context kind-kx get node kx-worker -o jsonpath='{.status.nodeInfo.containerRuntimeVersion}'kubectl --context kind-kx delete pod boundaries
For your own kind cluster kx: copy a command and paste it into your terminal. Run in the simulator runs the same command in this page's simulated cluster instead; nothing on this page touches your machine. With no limits set, cpu.max reads max 100000 and memory.max reads max. id shows root: nginx runs as UID 0, and with no user namespace that is UID 0 on the node too.
Actual state
Check your understanding
Your first answer to each check is the one that counts. After a miss you can answer again; passing every check reconciles the lesson.
Lesson not yet reconciled
Desired: 4 objectives, 0 metReconciled: 4 of 4 objectives met
- Say which Linux namespaces the containers in one pod share and which they keep apart. (not yet met)
- Explain how cgroup v2 enforces CPU and memory limits, and why the kubelet refuses cgroup v1 nodes by default from Kubernetes 1.35. (not yet met)
- Relate Docker bridge networking and Docker volumes to the pod network and pod volumes. (not yet met)
- Name the kernel features behind container security settings, namely capabilities, seccomp and user namespaces. (not yet met)
Pass every check above to reconcile this lesson.
Every check has passed, so the desired state is met. First-try accuracy: 0 of 5. This lesson's review cards are in your queue.
Changed since the notes
This lesson draws on an earlier set of study notes. Where the documentation contradicts a claim in them, qualifies it or has moved past it, the claim is listed here with the corrected statement and the source it was checked against.
Show 20 corrections
The notes saidDropping Docker support just removed the shim so Kubernetes talks directly to containerd (two entries)
Correcteddockershim was deprecated in v1.20 and removed in v1.24. The kubelet talks CRI to any CRI runtime, such as containerd or CRI-O. Docker Engine works only through the external cri-dockerd adapter maintained by Mirantis.
The notes saidIn modern Linux systems, cgroups v2 provides a unified hierarchy
CorrectedTrue. Kubernetes context: from v1.35 the kubelet refuses to start on cgroup v1 unless
failCgroupV1: falseis set. On EKS, AL2023 uses cgroup v2; Bottlerocket 1.35 uses v2 but sets failCgroupV1: false; Fargate still uses v1. Removal of the v1 fallback (KEP-5573) is placed at v1.38 only by secondary sources and is unconfirmed.Sourcekubernetes.io/blog/2026/10/06/kubernetes-cgroups-v2-shift
The notes saidUser namespace: a process can be root inside its namespace but unprivileged on the host
CorrectedTrue for the kernel feature. Kubernetes pod user namespaces (
hostUsers: false) are GA in v1.36 and remain opt-in per Pod.Sourcekubernetes.io/blog/2026/04/23/kubernetes-v1-36-userns-ga
The notes saidImplies user namespaces are part of normal container isolation
CorrectedThey are off by default. Docker userns-remap is a daemon-level opt-in, and Kubernetes needs
hostUsers: falseon each Pod (GA in v1.36). Without them, root in a container is host UID 0, limited by capabilities, seccomp and LSMs.The notes saidLambda runs function code in containers internally
CorrectedLambda isolates execution environments in Firecracker microVMs. Container images are only a packaging format.
Sourceaws.amazon.com/about-aws/whats-new/2026/06/aws-lambda-microvms
The notes saidoverlay2 is the default; aufs, btrfs and devicemapper are available
Correctedaufs was removed in Docker Engine v24.0 and devicemapper in v25.0. Fresh installs of Docker Engine 29.0+ default to the containerd image store (snapshotters). Upgraded hosts keep overlay2 until switched.
The notes saidWhen you run docker-compose up
CorrectedCompose V1 (
docker-compose) stopped receiving updates in July 2023. Usedocker compose up.The notes saidOverlay networks are primarily used with Docker Swarm
CorrectedMulti-host overlay networks still need Swarm mode, and standalone containers can join only if the network was created with
--attachable. Most multi-host container networking now runs on Kubernetes CNIs.The notes saidThe docker-iptables-reload command can restore Docker's expected rules
CorrectedDocker documents no such command, and its packet-filtering docs only say not to modify Docker's rules. Restarting dockerd recreates its chains, though that page doesn't say so.
Sourcedocs.docker.com/engine/network/packet-filtering-firewalls
The notes saidCompose expose controls which ports peers can reach
CorrectedContainers on the same user-defined network can reach every listening port of their peers.
exposeis documentation only.The notes saidA compose file is named docker-compose.yml by default
CorrectedThe default is compose.yaml (preferred) or compose.yml. docker-compose.yaml and docker-compose.yml are still read for backward compatibility.
Sourcedocs.docker.com/compose/intro/compose-application-model
The notes saiddocker-compose up / down / logs / exec / build
CorrectedUse the Compose V2 plugin:
docker compose up/down/logs/exec/build.The notes saidSynchronization strategies (cached, delegated, or the newer VirtioFS)
CorrectedVirtioFS is the default file sharing implementation in Docker Desktop for Mac, with gRPC FUSE as the alternative. Official docs don't confirm whether the cached/delegated flags do anything under VirtioFS.
Sourcedocs.docker.com/desktop/settings-and-maintenance/settings
The notes saidimage: postgres:15
Correctedpostgres:15 is several major versions behind. PostgreSQL 19 was at Beta 4 on 2026-09-24, and whether it reached GA by 2026-11-19 is unconfirmed. Pin to the newest GA major.
Sourcepostgresql.org/about/news/postgresql-19-beta-4-released-3386
The notes saidThe basic structure of a compose file includes a version declaration
CorrectedThe top-level
versionkey is obsolete. It is informative only and triggers a warning, and Compose always validates against the newest schema.Sourcedocs.docker.com/reference/compose-file/version-and-name
The notes saidYou can specify just a container port to expose it to other containers without publishing it to the host
Corrected
ports: ["80"]publishes the port on a host port the runtime picks automatically. For internal-only access, useexposeor omit ports.The notes saiddocker volume inspect shows which containers use the volume
CorrectedIts output is CreatedAt, Driver, Labels, Mountpoint, Name, Options and Scope. To find containers that use a volume, run
docker ps -a --filter volume=<name>.The notes saidDocker Content Trust provides image signing
CorrectedDocker announced the retirement of DCT (Notary v1) on 2025-07-29. Docker Official Images signing certificates began expiring on 2025-08-08, and pulls with DOCKER_CONTENT_TRUST=1 fail for those images. Use Sigstore cosign or Notation instead. Final shutdown dates are not confirmed from a primary source.
The notes saidConfigure the application to use non-privileged ports (above 1024) (two entries)
CorrectedUnprivileged ports are those >= 1024, so 1024 itself is unprivileged. Docker sets net.ipv4.ip_unprivileged_port_start=0 in container network namespaces, and the containerd 2.0 CRI plugin does the same by default (enable_unprivileged_ports = true). Non-root processes can therefore bind low ports in containers that don't use the host network.
The notes saidDocker secrets only work with Swarm, not standalone Docker (two entries)
CorrectedDocker Compose supports secrets without Swarm. They are mounted read-only at /run/secrets/<name> in Linux containers.
Every correction across the guide, by note and topic.
Sources
Checked against kubernetes.io, Linux kernel and Docker documentation for Kubernetes 1.37 on .
- man7.org/linux/man-pages/man7/namespaces.7.html
- docs.kernel.org/admin-guide/cgroup-v2.html
- kubernetes.io/docs/concepts/architecture/cgroups
- kubernetes.io/blog/2026/10/06/kubernetes-cgroups-v2-shift
- kubernetes.io/docs/concepts/configuration/manage-resources-containers
- kubernetes.io/docs/tasks/configure-pod-container/share-process-namespace
- kubernetes.io/docs/concepts/workloads/pods/user-namespaces
- kubernetes.io/docs/concepts/containers/runtime-class
- kubernetes.io/docs/tutorials/security/seccomp
- kubernetes.io/docs/concepts/security/linux-kernel-security-constraints
- kubernetes.io/docs/concepts/security/pod-security-standards
- kubernetes.io/docs/concepts/services-networking
- kubernetes.io/docs/concepts/storage/volumes
- github.com/containerd/containerd/blob/main/docs/cri/config.md
- docs.docker.com/engine/network/drivers/bridge
- docs.docker.com/engine/network/packet-filtering-firewalls
- docs.docker.com/engine/security/userns-remap
- docs.docker.com/reference/compose-file/services
- docs.docker.com/reference/compose-file/version-and-name
- docs.docker.com/compose/how-tos/use-secrets
Isolation: namespaces, cgroups and the runtime
↓ ↑ step, 1 to 6 scene, Esc leave