OverviewsContainers and Kubernetes

Containers and Kubernetes, the concepts that matter

Contents
  1. A container is a process with fences
  2. Images are content-addressed layers
  3. The supply chain is part of the image
  4. Everything goes through the API server
  5. Controllers reconcile desired state
  6. Workloads are chains of owners
  7. Scheduling is filter, then score
  8. Requests reserve, limits enforce
  9. Probes and shutdown decide uptime
  10. Services give Pods a stable address
  11. Storage outlives Pods
  12. RBAC and Pod security decide the blast radius
  13. Operators turn runbooks into controllers
  14. What is changing now
  15. Sources

Containers package a process with its files and run it behind kernel fences. Kubernetes stores the state you want for thousands of those processes and runs controllers that keep the cluster matching it. When a Pod is Pending, restarting, slow or unreachable, the cause almost always sits in one of a small set of mechanisms.

This page covers the thirteen things I watch when I dig into a cluster, plus the pieces that changed in recent releases. Each section says what the concept is, what to track, and why tracking it matters. The prompting guide for this topic turns the same ideas into exact field names and prompt lines.

A container is a process with fences

Start here, because everything else rests on it. A container isn’t a small VM. It’s an ordinary Linux process that the runtime has placed into its own namespaces and into a cgroup. Namespaces control what the process can see. The cgroup controls how much CPU, memory and I/O it can use. The namespaces(7) man page lists eight kinds: cgroup, IPC, network, mount, PID, time, user and UTS.

Namespaces decide what the process sees, the cgroup decides what it can use, and every container on the node shares one kernel.

Track three consequences. First, the kernel is shared, so a kernel bug is a container escape. That is why Pod security settings drop capabilities, apply a seccomp filter and block privilege escalation, and why untrusted code runs under gVisor or Kata Containers. Second, your app is PID 1 in its PID namespace. PID 1 gets no default signal handlers, so an app that ignores SIGTERM is killed with SIGKILL when the grace period runs out. Third, root in the container is root on the host unless user namespaces remap it. Kubernetes made user namespaces stable in 1.36 through hostUsers: false.

The node runs a short stack of programs to set this up. The kubelet calls a CRI runtime such as containerd or CRI-O. That runtime prepares an OCI bundle and calls an OCI runtime such as runc, which makes the namespace and cgroup system calls. Kubernetes removed its built-in Docker Engine support, dockershim, in 1.24. A RuntimeClass lets one Pod pick a different OCI runtime, such as gVisor’s runsc.

Images are content-addressed layers

An OCI image is a manifest that lists a config file and an ordered set of layer tarballs, each named by the SHA-256 digest of its content. The runtime stacks the layers with OverlayFS and adds one writable layer per container. A layer only adds. A file deleted in a later step is recorded as a whiteout entry, and the bytes stay in the earlier layer.

Layers are read-only and shared; the writable layer dies with the container; a tag is a pointer that moves, and a digest never changes.

The thing to track is the difference between a tag and a digest. A tag like v1.4 is a name the registry can repoint at any time. A digest is the content itself. If you deploy by tag, two nodes can run different bytes under the same name, and a rollback to “the old tag” may not give you the old image. Deploy by digest and keep the tag for humans.

Layer order also decides build speed and image size. Put the steps that change least first, so a code change reuses the cached dependency layer. Use a multi-stage build so compilers never reach the final image. For multi-architecture work, an image index maps one tag to a manifest per platform, so arm64 and amd64 nodes each pull their own build.

The supply chain is part of the image

Once images are content-addressed, you can attach evidence to a digest. The OCI Distribution Spec 1.1 added a referrers API. With it, an SBOM, a signature or a build attestation is stored as an artifact whose subject field points at the image digest.

Evidence travels with the digest, and the cluster checks it before a node ever pulls the image.

Three artifacts matter. An SBOM lists every package and version in the image, in SPDX or CycloneDX format, so you can answer “are we affected by this CVE” without rebuilding. A signature proves who published the digest. Sigstore’s keyless signing ties it to an OIDC identity, such as a CI workflow, and logs it in the Rekor transparency log. Provenance records how and from what source the image was built. The SLSA spec grades that provenance in Build levels. At L1 it exists, at L2 a hosted build platform signs it, and at L3 the build platform is hardened against tampering during the build.

The step people skip is enforcement. Evidence is only useful if an admission policy, such as Kyverno’s verifyImages or the Sigstore policy-controller, rejects Pods whose image lacks a valid signature from your CI identity.

Everything goes through the API server

Kubernetes is an API over a database, with controllers attached. The kube-apiserver is the only component that reads and writes etcd. The scheduler, the controllers and every kubelet watch the API server for changes and write their results back to it. Nothing talks to anything else directly.

Clients, controllers and kubelets all meet at the API server, which is the only component that touches etcd.

This design tells you where to look. If kubectl get is slow, look at the API server and etcd, not the nodes. etcd uses Raft, so it runs with an odd number of members and needs a majority to accept writes. The Kubernetes docs recommend five members for production. Back it up with etcdctl snapshot save and test the restore, because etcd holds every object in the cluster.

Every request passes authentication, authorization, mutating admission, schema validation and validating admission before it is stored. Admission is where policy lives: Pod Security Admission, ValidatingAdmissionPolicy rules written in CEL, and webhooks like Kyverno.

Controllers reconcile desired state

Every object has a spec you write and a status the system writes. A controller watches one kind of object, compares spec with what exists, and acts to close the gap. Then it does it again. The Kubernetes docs compare it to a thermostat.

A controller loops forever: observe, compare spec with status, act through the API, and requeue.

Expect two properties from any controller you write or install. Reconciliation is level-triggered. It acts on the current difference, not on the event that caused it, so the next pass fixes a missed event. It is also idempotent, so running it twice with nothing changed makes no writes.

When something is stuck, find the controller that owns the gap. Check its object’s status.conditions and compare status.observedGeneration with metadata.generation. If the observed generation is behind, the controller hasn’t processed your latest change yet. Finalizers explain the other common stuck state. An object with a finalizer stays in Terminating until its controller removes the key.

Workloads are chains of owners

You rarely create Pods directly. A Deployment owns ReplicaSets, and each ReplicaSet owns Pods. Every link is an ownerReferences entry, and the garbage collector deletes dependents when their owner goes.

A rolling update is two ReplicaSets trading Pods, paced by maxSurge and maxUnavailable.

A rollout is the Deployment controller creating a new ReplicaSet for the new Pod template and scaling the two in opposite directions. The Kubernetes Deployment docs give the defaults as maxSurge 25% and maxUnavailable 25%. For a service that can’t lose capacity, set maxUnavailable to 0 and maxSurge to 1. progressDeadlineSeconds, default 600, marks a stalled rollout as failed, and minReadySeconds keeps a Pod that crashes after a few seconds from counting as available.

Pick the controller by the guarantees you need. A StatefulSet gives each Pod a stable name like pg-0, starts Pods in order and gives each its own PersistentVolumeClaim. A DaemonSet runs one Pod per node. A Job runs to completion. Since 1.33, a native sidecar is an init container with restartPolicy: Always, so it starts before the app and stops after it.

Scheduling is filter, then score

The scheduler takes each Pod with no node and runs two phases. Filtering removes nodes that can’t run it. Scoring ranks the rest. Then it writes a binding to the API server, and the chosen node’s kubelet starts the Pod.

Filtering removes nodes that can't fit the Pod, scoring picks the best of the rest, and a Pod no node passes stays Pending.

Filters check resource requests against allocatable capacity, taints against tolerations, node affinity, and required Pod anti-affinity. When a Pod is Pending, the FailedScheduling event lists how many nodes each filter rejected. That message is the first thing to read.

The placement controls to track are topology spread constraints, which keep replicas balanced across zones with a maxSkew, and PodDisruptionBudgets, which limit how many Pods a drain or autoscaler can evict at once. Without a PDB, a node drain can take every replica of a service down together. PriorityClass decides who wins when the cluster is full, because a higher-priority Pod can preempt lower-priority ones.

Requests reserve, limits enforce

This is the topic that causes the most production incidents. A request is what the scheduler reserves on a node. A limit is a ceiling the kernel enforces through the cgroup. CPU and memory react differently when a container hits its limit.

Going over the memory limit kills the container; going over the CPU limit only slows it down.

CPU is compressible. The CFS quota in cpu.max throttles a container at its CPU limit. With a 500m limit, it gets 50 ms of CPU per 100 ms period and then waits. Latency rises, and nothing appears in the Pod’s status. Track the container_cpu_cfs_throttled_periods_total metric. Memory isn’t compressible. A container that crosses its memory limit is killed by the kernel’s OOM killer, and the Pod shows OOMKilled with exit code 137.

Requests and limits also set the Pod’s QoS class: Guaranteed when requests equal limits for every container, BestEffort when nothing is set, Burstable otherwise. When a node runs low on memory, the kubelet evicts BestEffort Pods first, then Burstable Pods that use more than they requested. The Kubernetes eviction docs list default hard thresholds that include memory.available below 100Mi and nodefs.available below 10%. A common starting policy is to set memory request equal to memory limit and to leave the CPU limit unset, then tune from measured usage. Since 1.35, you can resize a running Pod’s CPU and memory in place.

Probes and shutdown decide uptime

Kubernetes has three probes, and mixing them up causes outages. A readiness probe that fails removes the Pod from Service endpoints but leaves it running. A liveness probe that fails restarts the container. A startup probe holds the other two off until the app has started. The Kubernetes probe docs set the defaults at a 10 s period, a 1 s timeout and 3 failures.

Keep one rule. Liveness checks only the process itself. If liveness calls the database, a database outage restarts every replica at once and turns a dependency problem into a full outage.

Endpoint removal and SIGTERM start together, so a short preStop sleep stops traffic from reaching a Pod that has already stopped listening.

Shutdown is the other half. When a Pod is deleted, the kubelet runs the preStop hook, sends SIGTERM, and sends SIGKILL when the grace period ends, 30 s by default. Endpoint removal happens in parallel through a different path, so for a few seconds the load balancer may still send traffic. A preStop sleep of about 5 s covers that gap. The app then stops accepting connections, finishes in-flight requests and exits. A container that keeps failing enters CrashLoopBackOff, where restarts back off from 10 s up to 300 s.

Services give Pods a stable address

Pods come and go, and each new Pod gets a new IP. The Kubernetes network model gives every Pod a cluster-wide IP and requires Pods to reach each other without NAT. A CNI plugin, such as Cilium or Calico, wires up each Pod’s network namespace to meet that rule.

A Service is a stable name and IP, and it only forwards to Pods whose readiness probe passes.

A Service gives a set of Pods one virtual IP and one DNS name, api.payments.svc.cluster.local. The EndpointSlice controller keeps a list of the ready Pod addresses behind it, and kube-proxy or an eBPF replacement programs every node to send Service traffic to those addresses. The Kubernetes Service proxy docs mark kube-proxy’s IPVS mode deprecated in 1.35, and nftables mode is the newer option.

For traffic from outside, track the move from Ingress to Gateway API. The Kubernetes Ingress page says the Ingress API is frozen and recommends Gateway API. Gateway API splits the job by role. A cluster operator owns the Gateway, and application developers attach HTTPRoutes from their own namespaces, with weights for canaries. Inside the cluster, NetworkPolicy is the firewall. Pods accept all traffic until a policy selects them, and policies only work when the CNI enforces them. Start each namespace with default-deny and allow DNS on port 53 explicitly, or every lookup will fail.

Storage outlives Pods

A Pod asks for storage with a PersistentVolumeClaim: a size, an access mode and a StorageClass. The StorageClass names a CSI driver, which creates the actual disk, the PersistentVolume, and attaches and mounts it on the node where the Pod runs.

The claim asks, the StorageClass decides how, the CSI driver creates the disk, and the reclaim policy decides whether the disk survives the claim.

Three settings cause most storage surprises. The reclaim policy decides whether deleting the PVC deletes the disk. Delete is the default for dynamically provisioned volumes, and Retain keeps the data. The binding mode decides when the disk is created. With WaitForFirstConsumer, it is created after scheduling, in the zone where the Pod landed. With immediate binding, a disk can be created in a zone where the Pod can’t run. The access mode decides who can mount it. ReadWriteOnce means one node, and ReadWriteOncePod means one Pod.

When a Pod hangs in ContainerCreating with a volume event, map the event to the CSI call that failed. CreateVolume is provisioning. ControllerPublishVolume is attaching the disk to the node. NodeStageVolume and NodePublishVolume are mounting it.

RBAC and Pod security decide the blast radius

Two separate systems limit damage. RBAC decides what an identity can do through the API. Pod security decides what a Pod can do on its node.

A RoleBinding grants a Role's verbs to a ServiceAccount inside one namespace, and the namespace label sets the Pod Security level.

RBAC has four objects. Role and ClusterRole hold verbs on resources, and RoleBinding and ClusterRoleBinding grant them to users, groups or ServiceAccounts. Track wildcards and the verbs that lead to more power: escalate, bind, impersonate, and create on pods/exec. The Kubernetes RBAC good practices page warns that anyone who can create Pods in a namespace can mount its Secrets and run as any of its ServiceAccounts. Check real permissions with kubectl auth can-i --list --as=.... Secrets are base64-encoded, not encrypted, and the API server stores them unencrypted in etcd unless you enable encryption at rest.

Pod security has three standard levels: Privileged, Baseline and Restricted. Pod Security Admission applies them per namespace through labels, in enforce, audit or warn mode. Restricted requires running as non-root, dropping all capabilities except NET_BIND_SERVICE, blocking privilege escalation and setting a seccomp profile. Turn on warn and audit first, read the warnings, then enforce.

Operators turn runbooks into controllers

A CustomResourceDefinition adds a new type to the API, such as Postgres. An operator is a controller that reconciles that type, so the steps an engineer would run by hand become code.

An operator reads a custom resource, manages the ordinary Kubernetes objects behind it, and reports progress in the resource's status.

Judge an operator the way you’d judge any controller. Does it set status conditions with an observedGeneration? Does it use ownerReferences so its objects are cleaned up? Does it use a finalizer for external resources and remove it reliably? Does it run more than one replica with leader election through a Lease? An operator that fails these checks hides state that you will need during an incident.

What is changing now

Several pieces moved in recent releases, according to the Kubernetes feature gate list, and models trained on older docs will suggest the old way. Native sidecars went stable in 1.33. In-place Pod resize went stable in 1.35. User namespaces went stable in 1.36. kube-proxy’s IPVS mode was deprecated in 1.35. The Ingress API is frozen, and the project recommends Gateway API for new work. PodSecurityPolicy is gone; Pod Security Admission replaced it. cgroup v2 support has been stable since 1.25, and some features, such as MemoryQoS, only work on cgroup v2. When you read an example, check which Kubernetes version it was written for.

Sources