Q: In Kubernetes, what is the difference between Deployment, StatefulSet, and DaemonSet?
Clear decision matrix distinguishing Kubernetes Deployment, StatefulSet, and DaemonSet controllers, covering pod identity, network identity, persistent volume lifecycle, and per-node scheduling.
Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: In production, selecting the wrong workload controller leads to data corruption, deployment deadlocks, or wasted compute. I categorize them by statefulness, pod identity, and placement topology.
Deployment: Stateless, Interchangeable Workloads
Designed for stateless microservices, web apps, and API gateways where pods are ephemeral and interchangeable:
- Pod Identity: Pods receive random hash suffixes (e.g.
api-7d58f97b6b-4kx9l). Any pod can serve any request. - Storage: Typically stateless. If mounting PersistentVolumes (PV), all replicas share the same ReadWriteMany (NFS/EFS) volume or ephemeral emptyDir.
- Rollouts: Controlled by ReplicaSets with declarative RollingUpdate or Recreate strategies.
StatefulSet: Ordered, Stateful & Identity-Preserving Workloads
Designed for databases, distributed storage, and clustered systems (Kafka, Elasticsearch, PostgreSQL, Redis Cluster, ZooKeeper):
- Predictable Identity: Pods get deterministic, zero-indexed ordinal names (e.g.
kafka-0,kafka-1,kafka-2). - Headless Service & DNS: Uses
clusterIP: Noneso each pod receives a distinct DNS entry (e.g.kafka-0.kafka-headless.prod.svc.cluster.local) essential for leader election and cluster peering. - volumeClaimTemplates: Each replica dynamically provisions its own dedicated, persistent disk that survives pod recreation or rescheduling.
- Ordered Deployment & Termination: Deploys sequentially (0 ➔ 1 ➔ 2) and shuts down in reverse order to preserve quorum.
DaemonSet: Exactly One Pod Per Node Workloads
Ensures that a copy of the pod runs on every matching node in the cluster:
- Node-Bound Placement: Pods are automatically scheduled when a new node joins the cluster and garbage collected when the node is decommissioned.
- Primary Use Cases: Cluster observability agents (Datadog, Fluentbit, Prometheus Node Exporter), networking CNI plugins (Calico, AWS VPC CNI, Cilium), and security runtimes (Falco, Sysdig).
- Tolerations: DaemonSets typically tolerate
node.kubernetes.io/unschedulableand master/control-plane taints to monitor every physical host.
- Deployment: Stateless apps (APIs, web apps); random pod hashes; shared or no persistent disk; rolling updates.
- StatefulSet: Clustered databases (Kafka, Postgres, Redis); deterministic ordinal names (app-0, app-1); dedicated volumeClaimTemplates; headless service DNS.
- DaemonSet: Infrastructure agents (Fluentbit, Node Exporter, Cilium, Falco); runs exactly one pod per node automatically as nodes scale.
- Pro-Tip: Never run databases on Deployments with ReadWriteOnce EBS volumes—pods will fail to remount across nodes due to multi-attach errors.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Over-granting cluster-admin permissions to pod ServiceAccounts instead of scoping namespace Roles when configuring Deployment StatefulSet DaemonSet Over-granting cluster-wide permissions violates least-privilege principles and allows compromised pods to escalate privileges across namespaces.
-
Referencing mutable latest container tags across production Kubernetes Deployment specs when configuring Deployment StatefulSet DaemonSet
Deployments referencing
:latestrisk inconsistent versions across replica pods and break deterministic rollback capabilities. - Omitting pod readiness probes, causing traffic to hit uninitialized application containers when configuring Deployment StatefulSet DaemonSet Readiness probes gate traffic delivery; missing probes cause Kubernetes to route user requests to pods before dependencies or caches are loaded.
- Executing diagnostic triage without analyzing chronological cluster events and describe outputs when configuring Deployment StatefulSet DaemonSet Cluster events provide sequential timestamps of scheduler decisions, probe failures, and image pull timeouts essential for rapid root-cause isolation.