Workloads, Probes and Autoscaling
Run applications with Deployments, StatefulSets, DaemonSets and Jobs, keep them healthy with probes, and scale them automatically.
Intermediate · about 10 hours · difficulty 3/5
Learn first: Kubernetes Architecture and kubectl
Pods are the unit of scheduling, but you almost never create them directly. Higher-level workload controllers manage pods for you.
Controllers
- Deployment (via ReplicaSets): stateless apps with rolling updates and
kubectl rollout undo. TunemaxSurgeandmaxUnavailable. - StatefulSet: stable names and per-pod storage for databases and queues.
- DaemonSet: one pod per node (log shippers, node agents).
- Job and CronJob: run-to-completion and scheduled work.
Keeping pods healthy
- Resource requests (used for scheduling) and limits (enforced). Without requests the scheduler is guessing; memory over the limit means an OOM kill.
- Probes:
readinessProbecontrols whether a pod receives traffic,livenessProberestarts a stuck container,startupProbeprotects slow starters. - Graceful shutdown: handle SIGTERM, set
terminationGracePeriodSeconds, and a smallpreStopsleep to let endpoints update. - PodDisruptionBudgets keep capacity during node drains.
Scaling
The Horizontal Pod Autoscaler scales replicas on CPU, memory or custom metrics; the Cluster Autoscaler or Karpenter adds nodes; KEDA scales on events such as queue length.
Pitfalls
Liveness probes that check dependencies (a database blip restarts every pod), no requests set, and CrashLoopBackOff debugging without kubectl logs --previous.
Good enough to move on: you can deploy an app with requests, limits, three probes, a PDB and an HPA, and do a rolling update and rollback with zero failed requests.
Key concepts
- Pods and ReplicaSets
- Deployments and rolling updates
- StatefulSets and DaemonSets
- Jobs and CronJobs
- Requests and limits
- Readiness, liveness, startup probes
- PodDisruptionBudgets
- HPA and cluster autoscaling
- KEDA event-driven scaling
Mini project
Deploy an app with 3 replicas, probes, requests/limits and an HPA; run a load test to trigger scaling, then roll out a new version while a script hammers it and confirm zero errors.
Check yourself
What is the difference in behaviour between a failing readiness probe and a failing liveness probe?
Free resources
- Kubernetes workloads (kubernetes.io)
- Configure liveness, readiness and startup probes (kubernetes.io)