XWLinux

Namespaces + Cgroups — magia kontenerów

Ciekawostki 2024-12-01

Kontenery = namespaces (izolacja) + cgroups (limity).

Namespaces (6 typów): - PID (pid) — procesy widzą tylko swoje PIDs - NET (net) — interfejsy, routy, firewall - MNT (mnt) — montowane filesystemy - UTS (uts) — hostname, domainname - IPC (ipc) — semafory, queue'y - USER (user) — UIDs (root w kontenerze ≠ root na hoste)

Cgroups (v1 i v2): - CPU (cpu, cpu.weight) - Memory (memory.max, memory.high) - I/O (io.max) - PID (pids.max) - Device (devices.list)

Workflow (Docker): 1. unshare --pid --net --mnt --uts --ipc --user --mount-proc /bin/bash 2. cgroup setup (systemd-run --scope) 3. pivot_root

Ciekawostka: unshare + cgroup = 'manual docker'. systemd-nspawn = 'systemd docker'. LXC = 'full-featured kontener'. Docker = 'LXC + overlayfs + cgroups'. K8s = 'Docker + orchestrator'.