When would you use a StatefulSet, a DaemonSet, a Job or a CronJob instead of a Deployment?
Options
- StatefulSet: stateful. DaemonSet: per node. Job: once. CronJob: scheduled (Correct option)
- They are all identical, and any of them can replace a Deployment
- StatefulSet is for stateless apps and Job is meant for databases
- DaemonSet creates databases and CronJob scales Pods up and down
Answer
StatefulSet: stateful apps needing stable identity/storage (databases). DaemonSet: one Pod per node (log agents). Job: run a task to completion. CronJob: run a Job on a schedule
Why
Deployment fits stateless apps: any replica is interchangeable.
- StatefulSet: Pods with stable names (
db-0,db-1) and their own persistent volumes; for databases and brokers. - DaemonSet: ensures one Pod runs on each node: log collectors, monitoring agents.
- Job: runs until it finishes successfully (a migration, a batch import).
- CronJob: creates Jobs on a cron schedule (nightly report).
Remember
Stateless = Deployment. Stateful = StatefulSet. Per node = DaemonSet. Once = Job.