Simple definition#
A workload is an application running on Kubernetes. The smallest unit is a Pod — one or more containers that share a network identity and storage. You rarely create Pods directly; you use controllers (Deployment, StatefulSet, DaemonSet, Job) that create and manage Pods for you.
Workload types#
flowchart TD
Q{"What kind of workload?"} -->|"stateless service, web API"| D["Deployment<br/>replicas, rolling updates"]
Q -->|"needs stable identity + own disk<br/>databases, Kafka"| S["StatefulSet<br/>ordered, stable names, PVC per Pod"]
Q -->|"one per node<br/>log/metrics agents, CNI"| DS["DaemonSet"]
Q -->|"run to completion"| J["Job<br/>batch, migrations"]
Q -->|"on a schedule"| CJ["CronJob"]
| Object | Key behaviour |
|---|---|
| Pod | Containers sharing IP, ports, volumes; ephemeral — replaced, never repaired |
| Deployment | Manages ReplicaSets; rolling update and rollback; for stateless apps |
| StatefulSet | Stable names (db-0, db-1), ordered start/stop, a PersistentVolumeClaim per Pod |
| DaemonSet | One Pod per (matching) node |
| Job / CronJob | Run until success; retries; schedules |
| Init containers | Run before app containers (setup, migrations) |
| Sidecar containers | Long-running helpers (proxies, log shippers) with proper start/stop ordering — stable since 1.33 |
Pod lifecycle and probes#
stateDiagram-v2
[*] --> Pending: scheduled? image pulled?
Pending --> Running: containers started
Running --> Running: liveness fails → container restarted
Running --> Succeeded: all containers exit 0
Running --> Failed: container exits non-zero, no restart
Succeeded --> [*]
Failed --> [*]
| Probe | Question | On failure |
|---|---|---|
| Startup | Has the app finished starting? | Keep waiting (other probes disabled) until threshold, then restart |
| Readiness | Can it receive traffic now? | Removed from Service endpoints (no restart) |
| Liveness | Is it stuck? | Container restarted |
Resources: requests, limits and QoS#
- Request — what the scheduler reserves for the container; the basis of bin-packing and cost.
- Limit — the maximum. Exceeding a memory limit gets the container OOM-killed; exceeding CPU limit gets it throttled.
| QoS class | Rule | Eviction priority |
|---|---|---|
| Guaranteed | requests = limits for CPU and memory in every container | Last |
| Burstable | Some requests set, not equal to limits | Middle |
| BestEffort | No requests or limits | First |
Practical defaults: always set memory requests and limits (equal for critical apps); set CPU requests; consider omitting CPU limits for latency-sensitive services to avoid throttling, while enforcing namespace quotas. In-place Pod resize (stable in 1.35) lets you change CPU and memory of running Pods without restarting them.
Scheduling controls#
| Mechanism | Use |
|---|---|
| nodeSelector / node affinity | Run on nodes with certain labels (GPU, zone, instance type) |
| Pod affinity / anti-affinity | Co-locate with, or keep apart from, other Pods |
| Taints and tolerations | Reserve nodes (for example GPU or system nodes); only tolerating Pods land there |
| Topology spread constraints | Spread replicas evenly across zones and nodes |
| PriorityClass and preemption | Important Pods can evict less important ones |
| PodDisruptionBudget | Limit voluntary disruptions (drains, upgrades) |
| Dynamic Resource Allocation (DRA) | Request GPUs and other devices with rich parameters; supports sharing and partitioning |
Autoscaling#
flowchart TB
L["Load rises"] --> HPA["HPA / KEDA<br/>more Pods"]
HPA --> P{"Pods pending?<br/>no room"}
P -->|"yes"| NA["Node autoscaler<br/>Cluster Autoscaler or Karpenter<br/>adds nodes"]
P -->|"no"| OK["Pods scheduled"]
NA --> OK
VPA["VPA / in-place resize<br/>right-size requests"] -.-> HPA
| Autoscaler | Scales | On |
|---|---|---|
| HPA | Replica count | CPU, memory, custom/external metrics |
| KEDA | Replica count, including to zero | Event sources: queue length, Kafka lag, cron, Prometheus queries |
| VPA | Requests/limits | Observed usage (recommend, or apply — increasingly in place) |
| Cluster Autoscaler | Node groups | Pending Pods; scale-down of idle nodes |
| Karpenter | Individual nodes, chosen to fit | Pending Pods; consolidation to cheaper/fewer nodes; spot support |
Storage#
flowchart LR
POD["Pod"] --> PVC["PersistentVolumeClaim<br/>10Gi, ReadWriteOnce"]
PVC --> SC["StorageClass<br/>gp3, premium-ssd, ceph"]
SC --> CSI["CSI driver"]
CSI --> DISK[("Cloud disk / SAN / Ceph")]
CSI --> PV["PersistentVolume<br/>created and bound"]
PV --> PVC
- PersistentVolumeClaim (PVC) — what the app asks for. StorageClass — how to provision it. CSI driver — vendor plug-in that creates disks, snapshots and resizes.
- Access modes: ReadWriteOnce (one node), ReadOnlyMany, ReadWriteMany (shared file systems), ReadWriteOncePod.
- Snapshots and volume group snapshots (stable in 1.36) for consistent backups; tools such as Velero back up objects and volumes.
- Stateful workloads: prefer managed databases; when running databases on Kubernetes, use mature operators (CloudNativePG, Strimzi for Kafka) and test failover and restore.
Configuration#
- ConfigMaps for non-secret config; Secrets for credentials (base64, not encryption — enable etcd encryption and prefer external secret stores, see security).
- Namespaces separate teams and environments; ResourceQuotas and LimitRanges set budgets and defaults.
Common mistakes#
Quick check#
Deployment or StatefulSet for PostgreSQL? StatefulSet (or better, a database operator or managed service): it provides stable identities and a dedicated volume per replica with ordered rollout.
What is the difference between readiness and liveness probes? Readiness controls whether a Pod receives traffic; liveness decides whether a container is restarted.
What happens when a container exceeds its memory limit? Its CPU limit? Memory: OOM-killed. CPU: throttled.
What are the three QoS classes? Guaranteed, Burstable and BestEffort — evicted in reverse order under node pressure.
HPA, VPA, KEDA, Karpenter — what does each scale? HPA: replicas on metrics. VPA: requests/limits. KEDA: replicas from event sources, including to zero. Karpenter: nodes, chosen to fit pending Pods and consolidated for cost.
How do you make a service survive a zone failure? Multiple replicas spread with topology spread constraints across zones, a PodDisruptionBudget, zone-redundant storage or data replication, and a zone-aware load balancer.
Summary#
- Pods are ephemeral; controllers (Deployment, StatefulSet, DaemonSet, Job) manage them.
- Probes decide traffic (readiness) and restarts (liveness).
- Requests drive scheduling and cost; limits cap usage; QoS decides eviction.
- Autoscale Pods (HPA/KEDA/VPA) and nodes (Cluster Autoscaler/Karpenter).
- Storage via PVC → StorageClass → CSI; prefer operators or managed services for databases.
References#
- Kubernetes documentation, Workloads, Scheduling, Storage.
- KEDA, Karpenter.
- Kubernetes blog, In-place Pod resize graduates to stable.