Kubernetes interview question · Most asked
Deployment, StatefulSet, DaemonSet, Job and CronJob: when do you use each?
Summary
Deployment for stateless, interchangeable replicas (web apps, APIs); StatefulSet for pods needing stable identity and their own storage (databases, Kafka, ZooKeeper); DaemonSet for one pod per node (log collectors, node exporters, CNI agents); Job for run-to-completion tasks; CronJob for Jobs on a schedule.
Longer Answer
- Deployment manages ReplicaSets and supports rolling updates and rollbacks; pods are fungible.
- StatefulSet gives pods stable names (
db-0,db-1), stable DNS through a headless Service, ordered startup and shutdown, and a PersistentVolumeClaim per pod fromvolumeClaimTemplates. - DaemonSet schedules onto every node (or selected nodes), including new nodes as they join.
- Job retries failed pods up to
backoffLimit, can run in parallel, and supports indexed completions. - CronJob creates Jobs on a cron schedule; set
concurrencyPolicyandstartingDeadlineSeconds, and make the work idempotent because runs can be missed or duplicated.
Key Points
- Deployment: stateless replicas.
- StatefulSet: identity + per-pod storage.
- DaemonSet: one per node.
- Job/CronJob: run to completion; idempotent work.
More most-asked Kubernetes questions
- Describe the Kubernetes architecture: what runs on the control plane and what runs on the nodes?
- What is the difference between resource requests and limits, and what are the QoS classes?
- How do rolling updates work in a Deployment, and how do you roll back?
- Explain the Service types: ClusterIP, NodePort, LoadBalancer, ExternalName and headless.
- What happens, step by step, when you run kubectl apply for a Deployment?
- How does the scheduler place pods? Explain resource requests, node affinity, taints and tolerations.
- ConfigMaps and Secrets: how do they differ, and how should secrets really be handled?
- Liveness, readiness and startup probes: how do you configure them correctly?