Topic 182 / Advanced
Kubernetes workloads, networking and storage
Chapter 11.3 · Kubernetes
What and why
The control plane (→ 181) reconciles desired state, but "desired state" needs a vocabulary — what kind of thing is being run, how it's reached over the network, and where its data lives. Kubernetes defines a small set of workload, networking, and storage objects that cover almost every deployment shape. Builds on: → 181 (Kubernetes architecture).
Diagram
| Object | Purpose | On failure |
|---|---|---|
| Pod | smallest deployable unit, one or more tightly coupled containers | disposable, nothing preserved |
| Deployment | a set of identical, stateless Pods; rolling updates | replaces failed Pods, any identity |
| StatefulSet | like Deployment, but stable identity and storage per Pod | replaces a Pod, preserves its identity/storage |
| DaemonSet | exactly one Pod per node | node-scoped, not count-scoped |
| Job / CronJob | run-to-completion / scheduled run-to-completion | retries until done or a limit |
| Service | a stable network identity for a changing set of Pods | routes around dead Pods |
| PersistentVolume(Claim) | durable storage requested by a Pod | survives Pod rescheduling |
How it works
- A Pod is the smallest unit Kubernetes schedules — one or more containers that always run together on the same node, sharing network and storage; Pods are treated as disposable, never patched in place.
- A Deployment declares "N identical Pods of this image, kept running" for stateless workloads — it drives rolling updates (→ 187) and self-heals by replacing any Pod that disappears, with no guarantee it's the same Pod, just an equivalent one.
- A StatefulSet is for workloads where identity matters — each Pod gets a stable name and its own PersistentVolumeClaim that follows it across rescheduling, which is what a clustered database or anything with per-instance state needs.
- DaemonSet runs one Pod per node, for node-level agents; Job and CronJob run a Pod to completion once, or on a schedule, rather than keeping it running indefinitely.
- A Service gives a stable DNS name and virtual IP to a set of Pods selected by label, so other workloads never track individual Pod IPs that change on every reschedule — Kubernetes' own layer of service discovery (→ 42). Ingress routes external HTTP(S) traffic to Services by host/path rules, acting as the cluster's L7 entry point (→ 93).
- A PersistentVolume is provisioned storage in the cluster; a PersistentVolumeClaim is a Pod's request to use one — decoupling "what storage exists" from "what's currently using it," so a StatefulSet's Pod can be rescheduled to a different node and reattach to the same volume.
- ConfigMaps hold non-secret configuration and Secrets hold sensitive values (→ 165) — both injected into Pods as environment variables or mounted files, keeping configuration out of the container image (→ 188).
Practical example
(numbers illustrative). A stateless API runs as a Deployment with 6 replicas and a Service in front; a clustered cache runs as a StatefulSet with 3 replicas, each with its own PersistentVolumeClaim. When a node fails, the Deployment's Pods are replaced with no concern for which exact Pod identity comes back — any of the 6 is interchangeable. The StatefulSet's Pod on that node is also rescheduled, but reattaches to its own volume and keeps its own name — losing that distinction for a stateful workload would mean a cache node coming back with someone else's data, or none at all.
When to use it
- Use Deployment for anything stateless — the default, simplest workload type.
- Use StatefulSet only when identity or per-instance storage genuinely matters — it's more operationally complex than a Deployment for no benefit otherwise.
- Use a managed database or cache (→ 178) instead of running a stateful workload on Kubernetes yourself, unless there's a specific reason the managed option doesn't fit — running stateful systems well is a specialty of its own.
- Avoid Ingress/Service sprawl with no naming or ownership convention — in a cluster with many teams, an unowned Service is as risky as an unowned production table.
- Failure scenarios: a stateless workload mistakenly built as a StatefulSet (or the reverse), paying StatefulSet's operational cost or losing a Deployment's simple interchangeability for nothing; a Pod writing data to its local, non-Persistent filesystem and losing it the moment the Pod is rescheduled; a Secret mounted into a Pod and then logged in plaintext by the application, defeating the point of using a Secret object at all.
- Simpler alternative: for a handful of services with no scaling or self-healing complexity, a managed container service (no Kubernetes objects to learn) covers the same Deployment-and-Service pattern with far less to operate — this object vocabulary earns its complexity at cluster-wide scale, not a handful of services.
Practice
(trace kind, 20–30 min, conceptual — no cluster required). Given a system of a stateless API, a stateful cache cluster, and a nightly cleanup job, assign the correct Kubernetes workload object to each and justify it; then trace what happens to each when its node is drained for maintenance — which one keeps its identity and storage, which doesn't need to, and which simply reruns on schedule regardless. Done when every assignment's justification names the specific property (identity, storage, run-once) that drove it.
Key takeaway
A small set of workload, networking and storage objects — Pod, Deployment, StatefulSet, Service, PersistentVolume(Claim) — covers nearly every deployment shape; choosing the wrong one costs either unnecessary complexity or a missing guarantee. Done when you can: pick the correct object for a stateless service, a stateful cluster, and a scheduled job, and state what each guarantees on failure. Used next in → 183 (how the cluster decides these Pods are healthy and how much resource to give them), → 187 (Deployments are what rolling/canary updates act on).
References
Kubernetes: Concepts — see references.md.