Kubernetes Workloads: Deployments, StatefulSets, DaemonSets
Choose Kubernetes Deployments, StatefulSets, or DaemonSets with guidance on probes, graceful shutdown, rollouts, storage, and recovery.
Deployments manage interchangeable replicas, StatefulSets keep stable Pod identities and per-replica claim associations, and DaemonSets place agents on selected nodes. These controllers handle Pod creation and updates; they do not provide application-level readiness, database replication, or storage recovery. Configure probes and shutdown behavior for the application, and rehearse storage failures with disposable data in staging.
Kubernetes workloads: Deployments, StatefulSets, DaemonSets
Examples in this post target Kubernetes v1.37.1 and use stable workload APIs such as apps/v1. Probe paths, shutdown timeouts, and storage settings must match the application and its CSI driver.
Workload controllers create and replace Pods to match a declared replica or placement rule. They do not make an application ready to serve traffic, coordinate database writes, or recover data after storage failure. This guide compares Deployments, StatefulSets, and DaemonSets and shows where each controller fits.
If you are new to Kubernetes, start with the Kubernetes fundamentals post. For scheduling and other orchestration patterns, see the advanced Kubernetes guide.
Introduction
The right controller depends on the identity and placement needs of the application. A Deployment fits interchangeable replicas. A StatefulSet fits workloads that need stable ordinals or one claim per Pod. A DaemonSet fits agents that should run on selected nodes. For networking, see the Kubernetes Services and Networking guide; for persistent storage, see the Kubernetes Storage guide.
When to use each workload
Use this decision tree to pick the right workload resource:
Does each replica need a stable identity or its own persistent claim?
├── YES → Consider a StatefulSet, then confirm the application supports this topology.
└── NO → Should one Pod run on each selected node?
├── YES → DaemonSet
└── NO → Deployment
A Deployment fits when replicas can be replaced by any other replica, as with web services, stateless APIs, and queue workers. For rollout capacity and resource sizing, see the high availability guide and resource limits guide.
Consider another controller when the application needs a stable per-replica network identity or a separate persistent claim for each replica. A Deployment can still use a PVC; the controller does not assign stable identities to its replicas.
A StatefulSet fits when the application needs stable Pod ordinals, stable network names, or a PVC per replica. It supplies those Kubernetes mechanics. The database or cluster software must still implement replication, leader election, and write safety. See the storage guide for claim binding and recovery.
When replicas are interchangeable and do not need stable identities or per-replica claims, a Deployment is usually simpler.
A DaemonSet fits when an agent must run on every eligible node, such as a node exporter, log collector, or storage component. Taints, tolerations, selectors, and affinity determine which nodes are eligible. The advanced scheduling guide covers node placement rules.
Use a Deployment when replica count should follow user load rather than node count.
ReplicaSets and Deployments
A ReplicaSet makes sure a specific number of identical pod replicas are running at any given time. You rarely create ReplicaSets directly. The Deployment wraps a ReplicaSet and adds declarative update capabilities on top.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-frontend
namespace: workload-lab
spec:
replicas: 3
selector:
matchLabels:
app: web-frontend
template:
metadata:
labels:
app: web-frontend
spec:
terminationGracePeriodSeconds: 30
containers:
- name: nginx
image: nginx:1.25
ports:
- name: http
containerPort: 80
startupProbe:
httpGet:
path: /
port: http
periodSeconds: 2
failureThreshold: 30
readinessProbe:
httpGet:
path: /
port: http
periodSeconds: 5
livenessProbe:
httpGet:
path: /
port: http
periodSeconds: 10
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
These checks fit the sample Nginx page. For another application, choose an endpoint that reflects whether it can accept requests. Readiness removes an unready Pod from Service traffic; liveness restarts a process only when it is stuck; startup gives a slow process time to initialize before the other probes begin. A liveness probe should not fail just because a dependency is temporarily unavailable.
On shutdown, the application should handle SIGTERM, stop accepting new work, and finish or cancel in-flight requests within terminationGracePeriodSeconds. A preStop hook, if needed, runs inside that same grace period. A sleep hook does not replace application shutdown behavior.
The Deployment controller watches the ReplicaSet and creates a new ReplicaSet whenever you update the pod template. It also keeps a revision history so you can roll back if something goes wrong.
kubectl rollout status deployment/web-frontend -n workload-lab
kubectl rollout history deployment/web-frontend -n workload-lab
kubectl rollout undo deployment/web-frontend -n workload-lab
kubectl rollout undo deployment/web-frontend --to-revision=2 -n workload-lab
Deployments work well for stateless applications where each replica is interchangeable. You do not need persistent storage or a fixed network identity for each replica.
Scaling a Deployment
kubectl scale deployment web-frontend --replicas=5 -n workload-lab
Or update the spec directly:
kubectl patch deployment web-frontend -n workload-lab -p '{"spec":{"replicas":5}}'
The maxSurge and maxUnavailable fields control update behavior:
spec:
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
With these settings, the controller can create one extra Pod and will not intentionally reduce available replicas during the rollout. This does not guarantee zero downtime: new Pods must pass readiness, the cluster needs room for surge capacity, and old and new application versions must work with the same live data and dependencies.
Rolling updates and rollback
During a rolling update, Kubernetes replaces Pods according to the workload’s update strategy. Whether traffic stays available depends on readiness, capacity, and application compatibility.
minReadySeconds is a Deployment rollout setting. After a Pod becomes Ready, it must stay Ready for this many seconds before the Deployment counts it as available for rollout progress. It does not check application health; use readiness and startup probes for that.
spec:
minReadySeconds: 30
progressDeadlineSeconds: 600
If the Deployment makes no progress before progressDeadlineSeconds, Kubernetes reports a stalled rollout condition. Inspect events and probe results, then use rollout history and undo if the previous Pod template is still compatible with the current data.
For databases or stateful services, rolling updates do not work the same way. You need to think carefully about schema migrations and data consistency. This is where StatefulSets become relevant.
StatefulSet identity and stable storage
A StatefulSet assigns each Pod a stable ordinal and can create a separate PVC for each one. A replacement Pod with the same ordinal can reuse its claim when the volume can attach to the node where it is scheduled. The CSI driver, backend topology, and attachment limits still determine whether that can happen immediately.
The StatefulSet controller does not configure database replication, select a primary, protect concurrent writes, or make a backup. A database needs its own replication-aware configuration or a supported operator. The sample below shows the workload shape; it assumes that a headless Service and a credentials Secret are created separately, and the stock PostgreSQL image by itself is not a three-node database cluster.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres-cluster
namespace: database
spec:
serviceName: "postgres-cluster"
replicas: 1
podManagementPolicy: OrderedReady
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
terminationGracePeriodSeconds: 60
containers:
- name: postgres
image: postgres:15
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
startupProbe:
exec:
command: ["sh", "-c", "pg_isready -h 127.0.0.1 -p 5432"]
periodSeconds: 10
failureThreshold: 30
readinessProbe:
exec:
command: ["sh", "-c", "pg_isready -h 127.0.0.1 -p 5432"]
periodSeconds: 5
livenessProbe:
exec:
command: ["sh", "-c", 'pg_ctl status -D "$PGDATA"']
periodSeconds: 10
failureThreshold: 3
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "fast-ssd"
resources:
requests:
storage: 50Gi
With three replicas, the Pods would be named postgres-cluster-0, postgres-cluster-1, and postgres-cluster-2, and each would have its own claim. The claims are not shared, and a volume may be constrained to a node or zone by its driver. A Pending Pod can indicate that its claim cannot attach at the scheduled location; see the storage guide for diagnosis.
With the default OrderedReady policy, Pods are created in ordinal order and a later ordinal waits for the earlier Pod to become Ready. That ordering does not establish database quorum or replication by itself; the application must do that.
For a rolling update, StatefulSet updates proceed one Pod at a time, from the highest ordinal downward, and wait for each replacement Pod to become Ready. Check status and undo a Pod template change with:
kubectl rollout status statefulset/postgres-cluster -n database
kubectl rollout history statefulset/postgres-cluster -n database
kubectl rollout undo statefulset/postgres-cluster -n database
An image rollback does not roll back database schema or data. Use backward-compatible migrations and a database-specific recovery plan before changing a stateful workload.
The application still needs to handle SIGTERM and exit within its Pod grace period. A preStop hook shares the terminationGracePeriodSeconds budget. Deleting a StatefulSet does not guarantee ordered Pod termination; if you need ordered scale-down, first scale it to zero and wait for the Pods to stop, then delete the controller. Check the official StatefulSet termination guidance before relying on ordering.
Managing StatefulSet scaling
kubectl scale statefulset postgres-cluster --replicas=5 -n database
New ordinals request their own PVCs. With OrderedReady, scaling down removes Pods in reverse order; the claims are retained by default, though StatefulSet PVC retention settings and the PV reclaim policy can change what happens. Follow the database’s replica-removal procedure before reducing replicas, then confirm the claims and data that should remain. See the Kubernetes storage guide for reclaim-policy details.
DaemonSets for node agents
A DaemonSet keeps one Pod on each eligible node. This example uses node-exporter, which reads host metrics through read-only mounts and serves them on port 9100. The /metrics endpoint is its HTTP listener; use an application-specific health check for a different agent.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-exporter
namespace: monitoring
spec:
selector:
matchLabels:
app.kubernetes.io/name: node-exporter
template:
metadata:
labels:
app.kubernetes.io/name: node-exporter
spec:
automountServiceAccountToken: false
nodeSelector:
kubernetes.io/os: linux
terminationGracePeriodSeconds: 30
containers:
- name: node-exporter
image: quay.io/prometheus/node-exporter:v1.12.1
args:
- --path.procfs=/host/proc
- --path.sysfs=/host/sys
- --path.rootfs=/host/root
- --web.listen-address=:9100
ports:
- name: metrics
containerPort: 9100
startupProbe:
httpGet:
path: /metrics
port: metrics
periodSeconds: 2
failureThreshold: 15
readinessProbe:
httpGet:
path: /metrics
port: metrics
periodSeconds: 5
livenessProbe:
httpGet:
path: /metrics
port: metrics
periodSeconds: 10
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 65534
capabilities:
drop: ["ALL"]
volumeMounts:
- name: proc
mountPath: /host/proc
readOnly: true
- name: sys
mountPath: /host/sys
readOnly: true
- name: host-root
mountPath: /host/root
readOnly: true
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "250m"
volumes:
- name: proc
hostPath:
path: /proc
type: Directory
- name: sys
hostPath:
path: /sys
type: Directory
- name: host-root
hostPath:
path: /
type: Directory
tolerations:
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"
The sample grants no Kubernetes API access. Its host mounts are read-only and expose host data, so keep the Pod restricted to trusted monitoring workloads. The control-plane toleration makes this DaemonSet eligible for nodes with that taint; remove it if node-exporter should not run there.
You can also restrict DaemonSets to specific nodes using node selectors or node affinity:
spec:
template:
spec:
nodeSelector:
disktype: ssd
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: "topology.kubernetes.io/zone"
operator: In
values:
- us-east-1a
DaemonSets track eligible nodes: new matching nodes get a Pod, and Pods for removed nodes are garbage-collected. They use a rolling update by default. Check or undo a node-exporter rollout with:
kubectl rollout status daemonset/node-exporter -n monitoring
kubectl rollout history daemonset/node-exporter -n monitoring
kubectl rollout undo daemonset/node-exporter -n monitoring
Choosing a workload
Choose based on what the application needs:
| Workload | When to use | Identity | Storage |
|---|---|---|---|
| Deployment | Interchangeable services, web apps, APIs | Replica Pods are interchangeable | No stable per-replica claim; PVCs can still be mounted |
| StatefulSet | Stable ordinals or one claim per replica | Stable Pod name; headless Service for DNS | Per-Pod claims from volumeClaimTemplates |
| DaemonSet | Node-level agents on all or selected nodes | One Pod per eligible node | Depends on the agent; the node-exporter sample is read-only |
Choose a Deployment when replicas are interchangeable. Choose a StatefulSet when the application needs stable ordinals or per-replica claims. Choose a DaemonSet when placement follows eligible nodes rather than user load.
For the follow-up details, see the storage guide for per-Pod claims, the advanced Kubernetes guide for scheduling, and the high availability and resource limits guides for rollout capacity and sizing.
Safe staging checks
Run these checks in an isolated namespace or test cluster, using disposable data and the same storage driver as the workload. They are test procedures, not production runbooks. Do not use production PVCs to simulate a storage failure.
Deployment replacement and ephemeral data
Apply the Deployment in the workload-lab namespace, reduce it to one replica, and write a marker to that Pod’s writable layer:
kubectl scale deployment/web-frontend --replicas=1 -n workload-lab
kubectl wait --for=condition=Ready pod -l app=web-frontend -n workload-lab --timeout=5m
POD=$(kubectl get pod -l app=web-frontend -n workload-lab -o jsonpath='{.items[0].metadata.name}')
kubectl exec "$POD" -n workload-lab -- sh -c 'printf "temporary\n" > /tmp/recovery-check'
kubectl delete pod "$POD" -n workload-lab
kubectl wait --for=condition=Ready pod -l app=web-frontend -n workload-lab --timeout=5m
POD=$(kubectl get pod -l app=web-frontend -n workload-lab -o jsonpath='{.items[0].metadata.name}')
kubectl exec "$POD" -n workload-lab -- test ! -e /tmp/recovery-check
The new Pod should become Ready, and the marker should be gone. A Deployment Pod’s writable layer is not persistent storage. Keep application state in the database or an explicitly configured volume, and test that storage separately.
StatefulSet claim reattachment and data check
Copy the single-replica StatefulSet into the stateful-test namespace and update its namespace. Create the headless Service and postgres-credentials Secret in that namespace, and use a disposable StorageClass supported by the test cluster. Then write a marker to its mounted data directory, delete only the test Pod, and compare the checksum after it returns:
kubectl exec postgres-cluster-0 -n stateful-test -- sh -c 'printf "test-data\n" > "$PGDATA/recovery-check"; sha256sum "$PGDATA/recovery-check"'
kubectl get pvc -n stateful-test
kubectl delete pod postgres-cluster-0 -n stateful-test
kubectl wait --for=condition=Ready pod/postgres-cluster-0 -n stateful-test --timeout=10m
kubectl exec postgres-cluster-0 -n stateful-test -- sh -c 'sha256sum "$PGDATA/recovery-check"'
The PVC should remain bound and the checksum should match. To rehearse an attach or mount failure, use only a disposable test volume and the storage provider’s approved fault-injection procedure. Confirm that Pod/PVC events show the failure, restore the test backend, then repeat the checksum check. A healthy Pod status alone does not verify database consistency.
DaemonSet view of node-local storage
The node-exporter sample does not write or buffer application data. On one dedicated staging node, mount a disposable filesystem at a test mount point, find the node-exporter Pod for that node, and scrape it through a local port-forward:
NODE=staging-node-name
POD=$(kubectl get pods -n monitoring -l app.kubernetes.io/name=node-exporter --field-selector="spec.nodeName=$NODE" -o jsonpath='{.items[0].metadata.name}')
kubectl port-forward pod/"$POD" 19100:9100 -n monitoring
curl -s http://127.0.0.1:19100/metrics | grep 'mountpoint="/mnt/node-exporter-test"'
Unmount only that disposable filesystem on the test node and scrape again; the test mount should no longer appear. Remount it and confirm the metric returns. This checks that the agent observes the node’s mount state. If your own DaemonSet writes a local buffer, test that buffer path separately: verify the configured behavior when the test filesystem is full or unavailable, restore it, and confirm buffered data is handled according to the agent’s documentation.
Production failure scenarios
StatefulSet Pod cannot attach its claim
When a StatefulSet Pod is Pending or stuck in ContainerCreating, its claim may be unbound, the provisioner may have failed, or the volume may not attach in the Pod’s zone or on its node.
Look for FailedScheduling, FailedAttachVolume, FailedMount, or provisioner events. Check the Pod and PVC, then the StorageClass, requested capacity and access mode, node affinity, CSI controller/node logs, and backend quota or attachment limits:
kubectl describe pod postgres-cluster-0 -n database
kubectl get events --sort-by='.lastTimestamp' -n database
kubectl describe pvc data-postgres-cluster-0 -n database
kubectl get storageclass fast-ssd -o yaml
Use WaitForFirstConsumer when a topology-constrained provisioner supports delayed binding, so scheduling can account for volume topology. It is not a universal setting. Check the storage guide before changing binding mode or deleting a claim; the PV reclaim policy can affect the backing data.
DaemonSet does not run on an expected node
DaemonSet Pods run only on eligible nodes. A node selector, affinity rule, taint without a matching toleration, or resource shortage can exclude a node. The DaemonSet controller adds several node-health and unschedulable tolerations automatically, but a control-plane taint may still need an explicit toleration if the agent should run there.
Compare desired and scheduled counts, then inspect the Pod events and the node labels and taints:
kubectl get daemonset node-exporter -n monitoring
kubectl get pods -n monitoring -l app.kubernetes.io/name=node-exporter -o wide
kubectl describe node <node-name>
If the agent should run on control-plane nodes, add the matching toleration to its Pod template:
tolerations:
- key: "node-role.kubernetes.io/control-plane"
operator: "Exists"
effect: "NoSchedule"
Anti-patterns
Choosing a controller for a database
A Deployment does not corrupt a database by itself. The risks come from the application topology and storage setup. Each Pod has its own emptyDir; replicas do not share that directory. If several independent database servers sit behind one Service without a replication design, they can accept writes to separate data sets. If they mount shared storage, the access mode and filesystem do not replace database locking or replication.
A StatefulSet can give each replica a stable ordinal and a separate PVC, which helps a database operator or replication-aware configuration manage members. The vanilla PostgreSQL image in the example does not configure a cluster. Do not increase its replica count without a tested database topology. A single database can also run as a Deployment when that is a deliberate, supported design; choose based on identity, upgrade, and recovery requirements rather than a blanket rule.
During shutdown, the workload controller asks the Pod to terminate. It does not know whether an open transaction has finished. The process must handle SIGTERM, and its grace period must allow the application to stop safely. Before reducing database replicas, follow the database’s own procedure for removing a member and verify backups.
Separating readiness probes from rollout timing
Without a readiness probe, a Pod may be considered Ready as soon as its containers are running, even if the application has not finished initializing. Configure an application-specific probe so Kubernetes can keep it out of Service traffic until it can accept requests. Use a startup probe when initialization is slow.
For a Deployment or StatefulSet using rolling updates, minReadySeconds adds a stability window after the Pod first becomes Ready before the controller counts it as available for rollout progress. It is not a substitute for a probe and should be chosen from the application’s behavior, not an arbitrary startup estimate. See the Kubernetes probe guide for probe semantics.
Setting identical requests and limits for all Pods
Giving every pod the same resources is lazy. A web server and a batch job have completely different resource profiles. Profile your workloads first, then set appropriate values.
The problem starts with how Kubernetes schedules pods. The scheduler uses resources.requests to find nodes with enough capacity. If every pod requests 250m CPU and 256Mi memory, nodes get overcommitted, causing CPU throttling or OOM kills under load. A batch job processing 10,000 items might need 2000m CPU and 2Gi memory. A lightweight API gateway might only need 100m CPU and 128Mi memory. Putting both behind the same resource config means one of them is always wrong.
These are reasonable starting points:
| Workload Type | CPU Request | CPU Limit | Memory Request | Memory Limit |
|---|---|---|---|---|
| Lightweight API (Go, Node) | 50m-100m | 200m-500m | 64Mi-128Mi | 128Mi-256Mi |
| Heavy API (JVM, Python ML) | 250m-500m | 1000m-2000m | 512Mi-1Gi | 1Gi-2Gi |
| Batch processing | 500m-2000m | 2000m-4000m | 512Mi-2Gi | 1Gi-4Gi |
| In-memory cache (Redis) | 100m-250m | 500m-1000m | 1Gi-4Gi | 1.5Gi-6Gi |
Use kubectl top pods in production to see actual consumption, then tune from there. If a pod consistently uses 800m CPU but only requests 100m, raise the request so the scheduler makes better decisions. If it spikes to 2000m occasionally but mostly uses 200m, keep the request low and the limit high to avoid wasted guaranteed capacity.
Set namespace-level LimitRange objects to enforce defaults so new pods get sensible resource configs automatically.
Trade-off analysis
Workload trade-offs
| Factor | Deployment | StatefulSet | DaemonSet |
|---|---|---|---|
| Scaling | Set the desired replica count | Add or remove ordinals | One Pod per eligible node |
| Storage | Container filesystem or explicitly mounted PVC | Per-Pod claims from volumeClaimTemplates |
Depends on the agent; this sample reads host mounts |
| Identity | Replicas are interchangeable | Stable ordinal and network identity via headless Service | Pod is assigned to an eligible node |
| Ordering | No ordered replica startup | OrderedReady is the default |
Each eligible node is handled independently |
| Updates | Rolling update with surge/unavailable settings | Ordered rolling update by ordinal by default | Rolling update by default; OnDelete is optional |
| Recovery | Replacement Pod uses any feasible node | Replacement uses the same claim if the driver permits | Replacement is created for each eligible node |
If replicas are interchangeable, a Deployment keeps the model simple. If each member needs a stable identity or claim, use a StatefulSet and configure the application or operator for replication and recovery.
If placement follows node membership, use a DaemonSet. If replica count follows user traffic, use a Deployment. An agent’s exact node coverage still depends on labels, taints, tolerations, and available resources.
Scaling considerations
Scaling a Deployment changes the number of interchangeable replicas. Scaling a StatefulSet creates or removes ordinals; PVC retention and PV reclaim policies determine what happens to associated storage.
An ordinal can help a database identify members, but the database software or operator must establish its primary/replica relationships.
Interview questions
It depends on the database topology. A single database instance can run in a Deployment if its storage and lifecycle are configured for that design. StatefulSets are useful when each member needs a stable ordinal or its own PVC. Neither controller configures replication or protects concurrent writes; use a database operator or a tested application-specific setup for clustered databases.
With the default OrderedReady pod management policy, StatefulSet creates Pods in ordinal order and waits for an earlier Pod to be Ready before creating the next one. That controls Pod creation order; it does not establish quorum, replication, or a primary. The application or operator must implement those behaviors.
If a control-plane node has the node-role.kubernetes.io/control-plane:NoSchedule taint and the agent should run there, add a matching toleration to the Pod template. Also check selectors, affinity, and resource requests; a toleration alone does not make a node eligible if another scheduling rule excludes it.
The StatefulSet recreates a Pod with the same ordinal, and its claim normally remains associated with that ordinal. The volume must still be attachable under the CSI driver's topology and attachment rules. If the Pod stays Pending, inspect its events, the PVC, and the storage driver. Stable identity does not by itself prove that the application data is consistent or backed up.
maxSurge is the number of extra Pods allowed above the desired count during a Deployment update. maxUnavailable is how many may be unavailable below that count. Setting maxUnavailable: 0 and maxSurge: 1 can preserve the desired number of available replicas while a rollout proceeds, if there is enough cluster capacity and the new Pods pass readiness. It cannot guarantee zero downtime or compatibility with live data.
When a node becomes eligible, the DaemonSet controller creates a Pod there. When a node is removed, its DaemonSet Pod is garbage-collected. If that node later returns, the controller creates a Pod again. During ordinary Pod termination the configured grace period applies, but a node failure cannot guarantee that the old process shut down cleanly.
minReadySeconds makes the Deployment or StatefulSet wait after a Pod becomes Ready before counting it as available for rollout progress. It does not determine readiness. Use an application-specific readiness probe to gate Service traffic and a startup probe for slow initialization.
Inspect the Pod and PVC events, the StorageClass, requested size and access mode, node topology, CSI controller and node plugin, and backend quota. Use WaitForFirstConsumer when the provisioner supports delayed binding and volume topology must be considered during scheduling. It does not prevent every zone or attachment failure; see the storage guide.
Avoid DaemonSets when replicas should scale with user load. A DaemonSet places one Pod on each eligible node, so a 50-node cluster may run 50 copies even when an API needs only 10. Use a Deployment with an HPA when application replica count should respond to load. DaemonSets fit node-level agents such as logging and monitoring tools.
A ReplicaSet ensures a specific number of identical pod replicas are running. A Deployment manages ReplicaSets and adds declarative update capabilities on top. When you update a Deployment's pod template, it creates a new ReplicaSet, gradually scales it up while scaling the old one down, and keeps the old ReplicaSet for rollback capability. You rarely create ReplicaSets directly because Deployments provide this higher-level orchestration. Creating a ReplicaSet directly bypasses the update and rollback management that Deployments provide.
Use kubectl rollout history deployment/web-frontend -n workload-lab to see revision history, then kubectl rollout undo deployment/web-frontend -n workload-lab to roll back to the previous version, or add --to-revision=N to select a revision. Each Pod template update creates a new revision. Confirm that the older application version remains compatible with the current data before rolling back.
The controller choice alone does not make a stateful application safe or unsafe. Check that the app's replica and storage topology is supported, that each replica gets the intended volume, and that shutdown and recovery procedures are tested. A Deployment can use a PVC, but it does not give replicas stable ordinals or per-replica claims. A StatefulSet gives those mechanics, not database replication or backup.
A DaemonSet runs one pod per node, shared across all workloads on that node. A sidecar runs as part of each individual pod's workload, meaning you have N copies where N is the number of application pods, not the number of nodes. For node-level concerns like log collection and monitoring, DaemonSet is more efficient: one pod per node regardless of how many application pods run there. For workload-specific proxying or logging tied to a specific application instance, sidecars are appropriate.
Add a nodeSelector to the DaemonSet Pod template to match node labels. For example, nodeSelector: { disktype: ssd } selects nodes labeled disktype=ssd. For more complex rules, use nodeAffinity with required or preferred expressions. This can limit storage agents to nodes with fast disks or monitoring agents to particular zones.
With the default OrderedReady policy, Pods scale down in reverse ordinal order. PVCs are retained by default, but StatefulSet PVC retention settings can request deletion on scale-down or controller deletion. If a PVC is deleted, the PV reclaim policy determines what happens to the backing volume. Review both settings and the database's member-removal procedure before scaling down.
Pod readiness gates add custom conditions to the readiness decision. A controller or integration must set those conditions on the Pod; a readiness gate does not poll an external dependency by itself. Use one only when another controller provides the condition, and keep the container's readiness probe focused on whether the application can serve requests.
progressDeadlineSeconds controls how long a Deployment can go without progress before it reports a stalled rollout condition. The controller continues reconciling; inspect events, scheduling, and probe results, then decide whether to wait, fix the cause, or roll back. Its default is 600 seconds.
The Deployment controller creates a new ReplicaSet when its Pod template (.spec.template) changes, such as an image, environment variable, or volume mount. The selector remains the same across revisions, so Services can keep selecting matching Ready Pods. The old ReplicaSet remains available for rollback until it ages out of revision history.
Deleting either controller removes its Pods. Deployment deletion removes its managed ReplicaSets; StatefulSet deletion does not delete its PVCs by default. A StatefulSet's PVC retention policy can change that behavior. If a PVC is deleted, the bound PV's reclaim policy then controls whether the backing storage is retained or deleted. Check both policies before cleanup and keep a verified backup of important data.
Set requests and limits under the container's resources field. The scheduler uses requests when choosing a node; CPU limits can throttle a container, and memory over its limit can lead to an OOM kill. Requests are not a guarantee that the application will perform at that level. Measure the workload and tune the values; see the resource limits guide.
Further reading
- Kubernetes Documentation: Workload Resources
- Kubernetes Documentation: Deployments
- Kubernetes Documentation: StatefulSets
- Kubernetes Documentation: DaemonSets
- Kubernetes Documentation: Pod Disruption Budgets
Advanced workload patterns
Job-based batch processing: For batch workloads that run to completion, use Jobs or CronJobs instead of Deployments. A Job creates pods that run until completion, while a CronJob schedules recurring batch jobs. This is appropriate for data processing, report generation, and one-time migration tasks.
Init containers for workload setup: Use init containers to prepare the workload environment before the main container starts. Init containers run to completion before the main container starts, which is useful for database schema migrations, configuration loading, or dependency waiting that must complete before the application runs.
Pod topology spread constraints: Distribute workload replicas across failure domains (zones, nodes) for high availability:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: web-frontend
The scheduler tries to keep matching Pods balanced across zones. That can reduce the effect of losing one zone, but it does not guarantee service availability if a zone fails.
Conclusion
Use this checklist when choosing and configuring Kubernetes workload resources:
- Choose a controller that matches the workload’s identity and placement needs
- Configure startup and readiness probes; set
minReadySecondsas a stability window after readiness - Test rollout settings against available capacity and application-version compatibility
- Use StatefulSet
volumeClaimTemplateswhen each replica needs its own persistent claim - Add a control-plane toleration only if the DaemonSet should run on those nodes
- Set resource requests and limits for all containers
- Use readiness gates only when a controller or integration sets the custom Pod condition
- Test scaling behavior in staging before production
- Rehearse StatefulSet storage recovery with a disposable PVC and verify application data
Category
Related Posts
Container Security: Image Scanning and Vulnerability Risks
Implement comprehensive container security: from scanning images for vulnerabilities to runtime security monitoring and secrets protection.
Deployment Strategies: Rolling, Blue-Green, Canary
Compare and implement deployment strategies—rolling updates, blue-green deployments, and canary releases—to reduce risk and enable safe production releases.
Developing Helm Charts: Templates, Values, and Testing
Create production-ready Helm charts with Go templates, custom value schemas, and testing using Helm unittest and ct.