cgroups và namespaces là gì? Cách Kubernetes dùng chúng để quản lý pods?

Linux namespaces cung cấp process isolation, cgroups giới hạn resource usage — kết hợp là nền tảng của container; Kubernetes dùng cả hai để implement Pod isolation và CPU/memory limits.

Namespaces cung cấp isolation view: mỗi process thấy một view riêng của system resources. Linux có 8 namespace types: PID (process IDs), Network (interfaces, routing tables), Mount (filesystem mounts), UTS (hostname), IPC (shared memory, semaphores), User (UID/GID mapping), Cgroup, Time. Khi tạo container, Docker/containerd tạo new namespace set, clone process vào đó — process chỉ thấy resources trong namespace của nó.

cgroups (control groups) giới hạn và accounting resource usage: cpu (shares, quota, period), memory (limit, swap), blkio (I/O bandwidth), network (tc), pids (max processes).

Kubernetes Pod là nhóm containers chia sẻ Network namespace (cùng IP, cùng localhost) và IPC namespace — đó là sao containers trong cùng Pod giao tiếp qua localhost. Kubelet cấu hình cgroups per-container dựa trên resources.requests/limits: CPU limit dùng cpu.cfs_quota_us, Memory limit dùng memory.limit_in_bytes — exceed memory limit → OOMKilled; throttle CPU khi vượt quota. cgroups v2 (systemd default) unified hierarchy, better accounting, được Kubernetes adopt từ v1.25.

Xem toàn bộ Operating System cùng filter theo level & chủ đề con.

Mở danh sách Operating System