Workload controllers
Deployment and ReplicaSet
A ReplicaSet keeps N identical pods running. A Deployment manages ReplicaSets to provide rolling updates, rollbacks (revisionHistoryLimit), pausing, and scaling. You almost never create ReplicaSets directly. Use for stateless apps.
StatefulSet
For workloads needing stable identity:
- Stable names with ordinals:
kafka-0,kafka-1,kafka-2— recreated pods keep their name. - Stable network identity via a headless Service (
clusterIP: None): DNSkafka-0.kafka-headless.data.svc.cluster.local. - Stable storage:
volumeClaimTemplatescreate a PVC per pod (data-kafka-0) that sticks to that ordinal across rescheduling. PVCs are not deleted when the StatefulSet scales down or is deleted (configurable withpersistentVolumeClaimRetentionPolicy). - Ordered creation (0, 1, 2 — each Ready before the next) and reverse-order deletion by default;
podManagementPolicy: Parallelrelaxes it. - Rolling updates in reverse ordinal order;
partition: Nupdates only ordinals ≥ N — a built-in canary for stateful apps.
Use for databases, Kafka, ZooKeeper, Elasticsearch — ideally managed by an operator that handles failover, backups and upgrades. On AWS, managed services (RDS, MSK, OpenSearch) often beat running them yourself.
DaemonSet
Runs one pod on every (matching) node — new nodes get one automatically. Used for node agents: log collectors (Fluent Bit), monitoring (node-exporter, Datadog), CNI (aws-node), kube-proxy, CSI node plugins, security agents. Supports RollingUpdate (maxUnavailable, maxSurge) and needs tolerations to run on tainted nodes. Use nodeSelector/affinity to target subsets.
Job and CronJob
apiVersion: batch/v1
kind: Job
spec:
completions: 10 # total successful pods needed
parallelism: 3 # run at most 3 at once
completionMode: Indexed # each pod gets JOB_COMPLETION_INDEX (0..9)
backoffLimit: 4 # retries before marking the Job failed
activeDeadlineSeconds: 3600
ttlSecondsAfterFinished: 86400 # auto-delete finished Jobs
template:
spec:
restartPolicy: OnFailure
containers: [{ name: migrate, image: orders-migrate:1.4.2 }]
apiVersion: batch/v1
kind: CronJob
spec:
schedule: "30 2 * * *"
timeZone: "Asia/Kolkata"
concurrencyPolicy: Forbid # Allow | Forbid | Replace
startingDeadlineSeconds: 300 # skip if it couldn't start within 5 min
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
jobTemplate: { spec: { ... } }
concurrencyPolicy: Forbid prevents overlapping runs of long jobs; jobs should be idempotent because they can occasionally run twice or be skipped.
Autoscaling objects
- HPA (
autoscaling/v2) scales replicas on CPU/memory utilisation (relative to requests — no requests, no HPA: it shows<unknown>), custom metrics (Prometheus Adapter) or external metrics (SQS depth via KEDA). Needs metrics-server. Has scale-up/down behaviour policies and stabilisation windows. - VPA recommends or sets requests/limits; don't run it in Auto mode together with an HPA on the same CPU/memory metric.
- KEDA — event-driven autoscaling, including scale to zero.
- Node autoscaling (Cluster Autoscaler, Karpenter) adds capacity for Pending pods.