Kubernetes Container Internals: Namespaces, cgroups and runc Explained
Kubernetes container internals are Linux mechanisms, not magic. This guide traces namespaces, cgroups v2, OCI bundles, runc, containerd, CRI and the pause sandbox so SREs can inspect Pods on the node with ordinary tools.
Introduction
Kubernetes container internals start with a plain fact: a container is an ordinary Linux process with restricted visibility, resource ceilings and privileges. Namespaces control what it sees, cgroups control what it uses, and runtimes write those kernel settings. This guide follows that chain from Pod spec to kernel files you can inspect during an incident.
Consider an illustrative composite scenario, not a named outage. A service runs slowly on one node, its CPU graph looks flat, and the team debates application code for an hour. On the node, the container cgroup shows throttling: the process wants more CPU than its limit allows, so the kernel pauses it in slices. Nothing is broken in the application. The ceiling is doing exactly what it was told to do. That is why kubernetes container internals matter to busy engineers: many production symptoms that look like application faults are kernel accounting, namespace boundaries or runtime behaviour showing through the Kubernetes API.
5-minute takeaway. A Pod is a group of Linux processes sharing selected namespaces. The kubelet asks a high-level runtime through CRI, containerd or CRI-O prepares images and sandboxes, and a low-level OCI runtime such as runc creates namespaces, mounts and cgroups before exec-ing your process. Requests mostly influence scheduling and relative CPU weight; limits become hard ceilings such as cpu.max and memory.max on cgroup v2 nodes. When memory exceeds its ceiling the kernel can OOM-kill inside that cgroup, which Kubernetes reports as OOMKilled. When CPU exceeds its quota the process is throttled, not killed. Keep those two asymmetries in mind and half of node-level debugging becomes predictable.
This is post two in the Kubernetes Roadmap Series. The previous post, Why Use Kubernetes and When Not To, covered the platform decision. The next post in the series compares EKS, GKE and AKS for production teams. For background, read Kubernetes Concepts Explained and Kubernetes Architecture and Workload Orchestration alongside this mechanism guide. Readers who want the Docker-side view can pair it with the Docker Container Architecture Guide.
1. Kubernetes container internals: a container is a process
Kubernetes container internals rest on one sentence: there is no container object in the Linux kernel. A container is a process, or a small process tree, started with namespace flags, placed in a cgroup, given a root filesystem from image layers, and restricted by capabilities and seccomp. The host kernel schedules it like any other process.
That sentence corrects the most common mental error. A virtual machine boots its own kernel on virtual hardware, so isolation comes from the hypervisor boundary. A container boots nothing. The runtime calls clone or unshare with flags such as CLONENEWPID and CLONENEWNET, mounts a prepared root filesystem, writes cgroup limits, drops privileges, then execs the workload binary. From the host, ps shows the same process with a normal host PID. Inside, the process sees itself as PID 1 in its own PID namespace and cannot see host processes.
This shared-kernel design explains both the speed and the risk. Containers start fast because no guest kernel boots and no hardware is emulated. They pack densely because the overhead is metadata, mounts and accounting rather than a second operating system. The trade-off is that the kernel is a shared surface: a kernel privilege-escalation flaw can become a container-escape path, which is why containers alone are not a VM-grade security boundary. Sandboxed runtimes such as gVisor and Kata Containers exist for workloads that need a stronger boundary, and platform teams choose them deliberately rather than by default.
For SRE work, the process model gives you tools. You can inspect a container with ps, readlink, cat and nsenter on the node, subject to your node access policy. You can compare the process view from inside and outside the namespace and see exactly which lie the kernel is telling. Linux Commands for DevOps Engineers covers the shell habits; this guide adds the container-specific files to read.
2. Kubernetes container internals: namespaces control visibility
Kubernetes container internals use namespaces to control what a process can see. Each namespace type wraps one global resource: process IDs, mounts, network devices, IPC objects, hostname, user IDs, time or the cgroup view. A process belongs to one namespace of each type, and children inherit them unless the runtime creates new ones.
Linux provides eight namespace types in current kernels: PID, mount, network, IPC, UTS, user, cgroup and time. The PID namespace gives the container its own process numbering, with its init process as PID 1. That init matters: PID 1 has special signal and zombie-reaping duties, so an application that ignores SIGTERM or fails to reap children can create shutdown hangs that look mysterious from kubectl. The mount namespace gives the container its own mount table and root filesystem assembled from image layers, which is why a file can exist on the node and be invisible inside the container.
The network namespace gives the Pod its own interfaces, routes, ports and firewall view. Kubernetes assigns one network namespace per Pod, not per container, which is why containers in a Pod reach each other over localhost and cannot bind the same port. The IPC namespace isolates System V IPC and POSIX message queues. The UTS namespace isolates hostname and domain name. The user namespace maps user and group IDs so root inside can be unprivileged outside, where the runtime and cluster configuration support it. The cgroup namespace changes the view of the cgroup hierarchy so the container sees its own cgroup as the root. The time namespace can offset clocks for specific processes, though it is rarely the first thing an SRE checks.
You can prove namespace membership from the node. Each process exposes symlinks under /proc/Treat those commands as read-only inspection. They require node access, which many managed clusters restrict, and that restriction is itself a design decision: node debugging power should be deliberate, audited and rare.
3. Kubernetes container internals: cgroups control consumption
Kubernetes container internals use cgroups to control how much a process may consume. Namespaces limit visibility, but a visible process could still exhaust memory or CPU. Control groups organise processes into a hierarchy and attach accounting and limits for CPU, memory, process count and I/O. Kubernetes writes Pod requests and limits into that hierarchy.
On cgroup v2 nodes there is one unified hierarchy mounted at /sys/fs/cgroup, and each cgroup is a directory whose files you can read. CPU weight expresses relative share under contention, while cpu.max expresses a quota over a period: exceed it and the process is throttled until the next period. Memory controls include memory.max as the hard ceiling, memory.high as a throttling threshold that pushes reclaim, and memory.min or memory.low as protection hints. pids.max caps process creation, which stops fork bombs inside the group. The exact files present depend on controllers enabled on the node, so read what exists rather than assuming.
The asymmetry between CPU and memory is the operational heart of this topic. CPU is compressible: the kernel can delay a process and it still makes progress later, so limits show up as latency and throttling counters. Memory is incompressible: when a cgroup hits its hard ceiling and reclaim cannot free enough, the kernel OOM-kills a process in that cgroup. Kubernetes then reports OOMKilled and restarts the container according to policy. The companion guide Kubernetes OOMKilled Troubleshooting works that failure path in detail.
Paths vary by cgroup driver and init system. With the systemd driver on v2, Kubernetes cgroups appear under kubepods.slice with nested slices for QoS classes and Pods. Find the Pod cgroup from the process entry in /proc/4. Kubernetes container internals: requests, limits and QoS
Kubernetes container internals translate Pod resources into scheduler decisions and kernel settings. Requests influence placement and relative CPU weight under contention. Limits become ceilings the kernel enforces. The combination also sets the Pod QoS class, Guaranteed, Burstable or BestEffort, which affects eviction order when the node runs short of memory.
A CPU request is not a reservation of idle cycles. It tells the scheduler how much capacity to account for, and on cgroup v2 it maps toward cpu.weight so that, under contention, groups receive CPU roughly in proportion to their weights. A CPU limit maps to cpu.max quota and period. Set the limit too low for a bursty service and you buy predictable latency spikes: the process finishes its quota early in each period and waits. Many latency investigations end here, with throttled time rising in cpu.stat while node CPU looks underused.
Memory requests influence scheduling and reclaim behaviour, while memory limits map to the hard ceiling. A process whose working set grows past the limit is OOM-killed inside its cgroup even if the node has free memory, because the ceiling is per-group, not per-node. That surprises teams who watch node graphs only. Watch container working set against its own limit, and read memory.events for oom_kill counters before blaming the node.
QoS classes summarise the contract. Guaranteed Pods set requests equal to limits for CPU and memory on every container, and they are last in line for eviction. Burstable Pods set requests below limits, or set only some resources, and they can use spare capacity while accepting earlier eviction risk. BestEffort Pods set nothing and are evicted first under pressure. The series covers eviction ranking in depth in a later Module 6 post; here, remember that QoS is not a label you pick directly. It is derived from the resources you declare, so sloppy requests quietly change production behaviour. Kubernetes Best Practices gives the policy side of setting them well.
5. Kubernetes container internals: images, layers and OverlayFS
Kubernetes container internals need a filesystem before a process can run. An image supplies it as ordered layers, a config and a manifest. The runtime unpacks layers into a snapshot, and a union filesystem such as OverlayFS presents one merged root. Each container adds a writable upper layer over shared read-only lowers.
A layer is a tar changeset of filesystem changes, with whiteout entries marking deletions. The image config carries entrypoint, command, environment, working directory and user. The manifest ties layers and config together by digest, so the runtime can verify content rather than trusting a tag. When containerd pulls an image it stores blobs in a content store, unpacks them through a snapshotter, and reuses layers already present on the node. That reuse is why the second Pod using a large base image starts faster than the first.
OverlayFS mounts lower directories read-only and an upper directory writable. Reads fall through to the layer that holds the file. Writes copy the file up into the upper layer first, which means heavy write workloads pay copy-up cost and fill the container writable layer unless they use a volume. Deleting a file from a lower layer writes a whiteout in the upper layer; the bytes remain in the lower layer until the image itself changes. This explains two common surprises: removing a large file in a later Dockerfile layer does not shrink the image, and a container can fill node disk through its writable layer while its volumes look healthy.
Operationally, treat the container filesystem as disposable. Logs, uploads and state belong on volumes or external services. Image size still matters for pull latency and node disk pressure, so keep layers deliberate: combine package installs with cache cleanup in the same layer, copy dependency manifests before source where the build allows cache reuse, and pin base images by digest in production pipelines. The Docker architecture guide linked earlier covers build-side habits; the kernel-side point is that every layer becomes mounts and files the runtime must assemble before runc can start the process.
6. Kubernetes container internals: the OCI bundle and config.json
Kubernetes container internals pass through the OCI runtime specification before any process starts. A low-level runtime receives a bundle: a root filesystem directory plus config.json describing namespaces, mounts, cgroup settings, capabilities, seccomp and the process to exec. That file is the contract between high-level machinery and kernel operations.
The bundle model separates concerns cleanly. containerd or CRI-O decides what should run, prepares the snapshot and mounts, and generates an OCI spec. runc reads config.json, creates the namespaces named in it, sets up mounts inside the mount namespace, applies resource limits, sets capabilities and seccomp filters, switches to the requested user, and execs the entrypoint. Because the spec is a file, different low-level runtimes can honour the same contract: runc and crun implement it with kernel namespaces, while sandboxed runtimes add a stronger boundary around the same lifecycle.
Reading config.json on a node, where your access policy allows it, is the fastest way to settle arguments about what a container was actually given. The spec shows the exact mount list, the namespace paths it joined, the cgroup path, environment variables, and security settings such as nonewprivs and capability sets. When a Pod spec and observed behaviour disagree, the generated spec is ground truth for what the runtime was asked to do, and the kubelet and runtime logs explain why it asked.
Do not hand-edit generated specs in production. Change the Pod spec, the runtime configuration or the node configuration through your normal platform path, then let the machinery regenerate the bundle. Hand edits vanish on the next restart and teach the team the wrong lesson.
7. Kubernetes container internals: what runc actually does
Kubernetes container internals reach the kernel through runc or a sibling low-level runtime. runc creates the container process with the requested namespaces, mounts and cgroups, applies security restrictions, execs the workload, and then steps aside. A shim process stays behind to hold the container lifecycle so the high-level runtime can restart safely.
The runc lifecycle is short and deliberate. On create, runc sets up the container and its init process waits. On start, it releases the init to exec the workload. On kill and delete, it signals and cleans up. During setup it performs the privileged work: cloning with namespace flags, mounting filesystems, writing cgroup files, setting hostname, configuring devices, dropping capabilities, installing seccomp filters and switching users. After exec, the workload runs unprivileged under those restrictions, and runc itself exits.
That exit is why the shim exists. containerd spawns a containerd-shim per container or sandbox, and the shim holds the container process, reports exit status and keeps stdio plumbing alive. containerd can then restart or upgrade without killing running containers, because the shim, not the daemon, is the parent that matters. When you see shim processes on a node, you are looking at the bookkeeping layer that makes runtime maintenance survivable.
Failure modes map to the layer that owns them. A runc error about a mount or namespace points at node configuration, kernel support or the generated spec. A container that starts and exits immediately usually points at the workload: wrong entrypoint, missing library, bad configuration or a PID 1 that does not handle signals. Kubernetes CrashLoopBackOff Troubleshooting separates those cases from the Kubernetes side; the runtime side asks a narrower question: did the process exec, and what did it print before it died? Runtime logs and container stdio answer that before any redeploy.
8. Kubernetes container internals: kubelet, CRI and containerd
Kubernetes container internals are orchestrated by the kubelet through the Container Runtime Interface. The kubelet never creates namespaces itself. It sends CRI requests over a socket to containerd or CRI-O, which pulls images, creates sandboxes and containers, and reports status back. That boundary keeps Kubernetes runtime-agnostic.
The flow for a new Pod runs in a fixed order. The scheduler assigns the Pod to a node. The kubelet on that node syncs the Pod spec and calls CRI RunPodSandbox, which creates the sandbox and its network namespace, then calls the CNI plugin to wire networking. It pulls images through the ImageService, creates each container with CreateContainer, and starts it with StartContainer. Status flows back through ContainerStatus, and the kubelet writes Pod status to the API server. Exec and log streaming use separate streaming endpoints so long-lived connections do not block the main gRPC channel.
containerd divides its own work into a content store for image blobs, a snapshotter for unpacked filesystems, metadata storage, and the runtime layer that spawns shims and runc. CRI-O takes a narrower path, built specifically for Kubernetes CRI with OCI runtimes underneath. Either way, the kubelet sees the same CRI verbs, and platform teams can choose the runtime that fits their operating model. What matters during incidents is knowing which layer logged the failure: kubelet events describe Pod-level decisions, runtime logs describe image, sandbox and container operations, and kernel messages describe OOM kills and throttling consequences.
Start with those two commands before node access. Events often name the failing layer precisely enough to skip the node entirely, and node access should be the escalation, not the first move.
9. Kubernetes container internals: the pause sandbox and Pod sharing
Kubernetes container internals give every Pod a sandbox held open by a pause process. The pause container creates and holds the shared network namespace, and usually the IPC namespace, so application containers can join them. If an application container restarts, the Pod IP and namespace survive because pause never died.
The pause process does almost nothing, and that is the point. It sleeps, reaps zombies where required, and holds the namespaces open. The runtime creates the sandbox first, CNI configures networking inside its network namespace, and each application container then joins that namespace instead of creating its own. Containers still get separate mount and PID namespaces by default, so each sees its own filesystem and process tree while sharing one IP address and localhost.
Sharing rules explain everyday Pod behaviour. Two containers cannot bind the same port because they share one network namespace. A sidecar can proxy localhost traffic for the main container for the same reason. shareProcessNamespace changes the PID arrangement so containers share one PID namespace, with pause as PID 1, which helps debugging and signal handling in specific designs and weakens isolation in exchange. hostNetwork, hostPID and hostIPC go further and join host namespaces directly; each removes a layer of the container boundary and should be treated as a security decision, not a convenience flag.
When networking breaks inside a Pod, ask which namespace you are actually testing. A debug container joins the Pod network namespace and sees the Pod view; a node shell sees the host view. Confusing the two produces confident wrong answers. The namespace symlinks under /proc settle the question in seconds.
10. Kubernetes container internals: security envelopes beyond namespaces
Kubernetes container internals include a privilege envelope that namespaces alone do not provide. Capabilities split root authority into granular rights, seccomp filters system calls, nonewprivs blocks privilege gain through exec, and LSM profiles such as AppArmor or SELinux constrain file and network access. Together they decide what a compromised process can attempt.
Root inside a container is still root over the resources its namespaces expose, tempered by the capability set it holds. Dropping all capabilities and adding back only what the workload needs is the baseline that Kubernetes Best Practices recommends, and Pod Security Standards encode the same expectation at admission time. A process that needs to bind a low port may need one capability; a process that needs none should hold none. Every extra capability is attack surface the kernel will honour.
Seccomp adds a syscall filter. The runtime default profile blocks rarely needed, dangerous calls while allowing the common set most workloads use. Custom profiles can tighten further, at the cost of testing: a blocked syscall can crash a workload in ways that look like application bugs until you read the audit log. nonewprivs prevents a process from gaining privileges through setuid binaries or file capabilities on exec, which closes a class of escalation paths inside the container. User namespaces, where enabled and supported, map container root to an unprivileged host user, so even a successful escape lands with reduced rights.
The honest summary for platform teams: namespaces isolate visibility, cgroups limit consumption, and the privilege envelope limits action. A container with all three, running as non-root with a read-only root filesystem and no extra capabilities, is a reasonable boundary for ordinary workloads. It is still not a VM boundary. Multi-tenant clusters running untrusted code should evaluate sandboxed runtimes or VM-backed nodes, and say so plainly in their threat model rather than hoping the default stack is enough.
11. Kubernetes container internals: a node inspection runbook
Kubernetes container internals become practical when you can inspect a live Pod on the node in a fixed order. Confirm the host PID, read its namespace links, find its cgroup, check CPU throttling and memory events, then compare the generated runtime state with the Pod spec. That order separates kernel facts from API opinions.
Start from Kubernetes, not the node. Describe the Pod, read events, and note restart counts, last state and termination reasons. OOMKilled in the last state already tells you the memory ceiling fired; CrashLoopBackOff tells you the process exits repeatedly. Those two facts decide which node files matter. Only then, with approved node access, find the container host PID through the runtime tooling your platform provides, and inspect from there.
From the cgroup path, read cpu.stat for throttled time, memory.current and memory.max for headroom, and memory.events for oomkill counts. Rising throttling with flat node CPU means the limit, not the node, is the constraint. An oomkill counter that increments at each restart confirms the ceiling. If the process view surprises you, compare namespace inodes between the container and the pause process to confirm sharing, and check whether host namespaces were requested in the Pod spec.
Close the loop in the API. Node facts explain mechanism; the fix still lands in Pod resources, image configuration, runtime configuration or node configuration through normal change paths. Record the cgroup values you observed in the incident notes, because they are the evidence that separates a measured fix from a guess. Teams that keep this runbook short and rehearsed resolve the composite scenario from the introduction in minutes.
12. Kubernetes container internals: comparison and troubleshooting matrix
Kubernetes container internals are easier to reason about with two tables. The comparison table separates virtual machines, standard containers and sandboxed containers by isolation boundary and cost. The troubleshooting matrix maps common symptoms to the kernel or runtime mechanism behind them and the first check that confirms it.
| Option | Isolation boundary | Kernel | Typical cost | Use it when |
|---|---|---|---|---|
| Virtual machine | Hypervisor and virtual hardware | Own guest kernel | Highest overhead, slowest start | Strong tenant separation or non-Linux workloads |
| Standard container | Namespaces, cgroups, capabilities, seccomp | Shared host kernel | Lowest overhead, fastest start | Trusted workloads on a shared platform |
| Sandboxed container | User-space kernel or lightweight VM per Pod | Intercepted or guest kernel | Moderate overhead | Untrusted code needing container ergonomics |
The table is a decision aid, not a ranking. Most internal platforms run standard containers for their own services and reserve sandboxed or VM-backed capacity for untrusted or regulated workloads. The mistake is treating the default as a security proof rather than a trade-off the platform has accepted.
| Symptom | Likely mechanism | First check |
|---|---|---|
| Latency rises, node CPU looks idle | CPU quota throttling in cpu.max | cpu.stat throttled time for the Pod cgroup |
| Container restarts with OOMKilled | Memory ceiling reached in its cgroup | memory.events oom_kill and working set vs limit |
| File exists on node, missing in container | Separate mount namespace and image rootfs | Mount list and image contents, not node paths |
| Two containers cannot bind one port | Shared Pod network namespace | Pod spec and namespace inodes vs pause |
| Shutdown hangs until forced kill | PID 1 signal handling in the container | Entrypoint behaviour on SIGTERM |
| Process count grows without bound | pids.max absent or too high | pids.current and fork behaviour in the workload |
Work the matrix from the symptom, confirm with the named check, and only then change configuration. Each row ends at a different layer, which is why generic restarts waste time: they reset the evidence without touching the mechanism.
13. Kubernetes container internals: final checklist
Kubernetes container internals end in a short checklist platform teams can apply before the next incident. Know your runtime stack, set requests and limits from measured working sets, watch throttling and OOM counters per container, run non-root with dropped capabilities, and rehearse node inspection before you need it under pressure.
Use this checklist when reviewing a workload or a node pool:
- Runtime stack named: kubelet CRI endpoint, containerd or CRI-O version policy, low-level runtime, and cgroup driver recorded for every node pool.
- Requests set from measured usage, limits set from measured peaks plus headroom, and QoS class understood as a consequence of those numbers.
- Dashboards show container working set against limit, CPU throttled time, and OOM kill events per workload, not only node averages.
- Containers run as non-root, drop all capabilities by default, use the runtime default seccomp profile or tighter, and mount root filesystems read-only where the workload allows.
- Images are pinned by digest, kept small enough for pull and disk budgets, and treated as disposable; state lives on volumes or external services.
- hostNetwork, hostPID, hostIPC and privileged mode require explicit review, with the namespace or privilege being surrendered named in the request.
- Node inspection is rehearsed: namespace links, cgroup path, cpu.stat, memory.events and runtime logs can be read by the on-call engineer through an approved, audited path.
- Series navigation: previous post Why Use Kubernetes and When Not To; next in the series, EKS vs GKE vs AKS for Production Teams. Continue learning with Module 1 of the Kubernetes roadmap at k8s.naveedkumbhar.com.
A container is a process the kernel has fenced with namespaces, metered with cgroups and restrained by a privilege envelope, started by runc from an OCI bundle that containerd prepared at the kubelet request. Hold that sentence and the rest of Kubernetes internals stops being folklore. It becomes files you can read, counters you can watch and settings you can change with evidence.
Frequently Asked Questions
What are Kubernetes container internals in simple terms?
Kubernetes container internals are the Linux mechanisms under every Pod: namespaces control what a process sees, cgroups control what it uses, image layers supply its filesystem, and runc creates the process from an OCI bundle. containerd prepares the work and the kubelet requests it through CRI.
How do namespaces and cgroups differ in Kubernetes container internals?
In Kubernetes container internals, namespaces isolate visibility such as processes, mounts and network interfaces, while cgroups limit consumption such as CPU time, memory and process count. A process needs both: namespaces alone would still let it exhaust the node, and cgroups alone would not hide host resources.
What does runc do in Kubernetes container internals?
In Kubernetes container internals, runc is the low-level OCI runtime that creates namespaces, mounts and cgroups, applies capabilities and seccomp, then execs the workload process. After setup runc exits and a shim holds the container lifecycle for containerd.
Why does a container get OOMKilled in Kubernetes container internals?
In Kubernetes container internals, OOMKilled means the process exceeded the memory ceiling in its own cgroup and the kernel killed it there. The node may still have free memory. Check memory.events and the working set against the container limit before changing anything.
What is the pause container in Kubernetes container internals?
In Kubernetes container internals, the pause container holds the Pod sandbox open. It creates the shared network namespace that application containers join, so the Pod IP survives application container restarts. It does almost no work beyond holding namespaces and reaping zombies.
How can I inspect Kubernetes container internals on a node?
Inspect Kubernetes container internals by finding the container host PID, reading /proc/
Preparing for Senior Platform & SRE Interviews
Practice real-world cluster triage, RBAC debugging, and pod scheduling scenarios in our Kubernetes scenario interview questions hub.
Explore Interview Scenarios →