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 from volumeClaimTemplates.
  • 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 concurrencyPolicy and startingDeadlineSeconds, 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

← All Kubernetes questions