Deployment vs StatefulSet vs DaemonSet vs Job: what's the difference?

Deployments, StatefulSets, DaemonSets and Jobs are Kubernetes workload controllers: each one creates and replaces Pods from a template, but for a different kind of workload. A Deployment runs interchangeable replicas of a stateless application. A StatefulSet gives each replica a stable name and its own storage. A DaemonSet runs one Pod on every node, and a Job runs Pods until a task finishes, with CronJob starting Jobs on a schedule.

Which controller to use

ControllerUse it whenPod identityStorageTypical workloads
DeploymentAny replica can serve any requestRandom names, replaced freelyShared or noneWeb servers, APIs, stateless workers
StatefulSetEach replica needs a fixed name or its own dataname-0, name-1 and so on, kept across restartsOne volume per replicaDatabases, message brokers, consensus systems
DaemonSetSomething must run on every nodeOne per nodeUsually node-localLog collectors, monitoring agents, network and storage plugins
JobA task runs to completionRandom namesUsually noneBatch processing, migrations, reports
CronJobA task runs on a scheduleCreates a Job per runUsually noneNightly backups, cleanups

Deployment

A Deployment manages ReplicaSets, which in turn keep a set number of identical Pods running. When you change the Pod template, for example the image tag, the Deployment creates a new ReplicaSet and shifts Pods from the old one to the new one.

The default RollingUpdate strategy controls the pace with two settings, both 25% by default:

  • maxSurge: how many extra Pods may exist above the desired count. Rounded up.
  • maxUnavailable: how many Pods may be missing during the update. Rounded down.

With 4 replicas, the defaults allow one extra Pod and one unavailable Pod at a time. The Recreate strategy stops all old Pods before starting new ones, for applications that cannot run two versions side by side. A Deployment keeps 10 old ReplicaSets by default, so kubectl rollout undo deployment/<name> can return to an earlier version.

StatefulSet

A StatefulSet is for applications that need one or more of: stable, unique network identifiers, stable persistent storage, and ordered deployment, scaling and updates.

  • Stable names. Pods are named <statefulset>-<ordinal>, such as web-0, web-1 and web-2. A replaced Pod gets the same name.
  • Stable DNS. A headless Service, which you create yourself, gives each Pod a DNS name such as web-0.nginx.default.svc.cluster.local, so peers can find each other.
  • Storage per replica. volumeClaimTemplates create one PersistentVolumeClaim per Pod. When web-1 is recreated on another node, it mounts the same volume.
  • Ordering. With the default OrderedReady policy, Pods start one at a time in order and stop in reverse order. Parallel drops the ordering.

Deleting or scaling down a StatefulSet does not delete its volumes. That protects data, but leftover claims keep costing money. The persistentVolumeClaimRetentionPolicy field, stable since Kubernetes 1.32, can delete them automatically; its default is Retain.

A StatefulSet provides identity and storage, but it does not know how to replicate data, elect a primary, fail over or take backups. That is why most teams run production databases through an operator, which adds that logic on top of StatefulSets. See Kubernetes operators: what they are and when to use them.

DaemonSet

A DaemonSet runs a copy of a Pod on every node, or on every node that matches a node selector. When a node joins the cluster, the DaemonSet adds a Pod to it; when the node leaves, the Pod goes with it. There is no replica count.

Cluster infrastructure is the main use: log and metrics agents, the network plugin, CSI node plugins and security agents. DaemonSet Pods often need tolerations to run on tainted nodes, such as GPU nodes. Every DaemonSet adds requests to every node, so a cluster with many DaemonSets has less room per node for applications.

Job and CronJob

A Job runs Pods until a given number of them succeed. completions sets how many successful Pods are needed and parallelism how many run at once. A Job’s Pods must use restartPolicy: Never or OnFailure.

Failed Pods are retried with an exponential back-off (10 s, 20 s, 40 s and so on, capped at ten minutes) until backoffLimit is reached, which is 6 by default. activeDeadlineSeconds caps the total run time, and ttlSecondsAfterFinished deletes the finished Job automatically.

A CronJob creates a Job on a cron schedule. Finished Jobs and their Pods stay in the cluster until they are cleaned up, and thousands of them add load to the control plane’s data store, one of the real limits on how big a Kubernetes cluster can get.

Common mistakes

  • A database in a Deployment. Replicas get random names and can share or fight over a single volume. Use a StatefulSet or an operator.
  • A one-off task in a Deployment. The container exits, Kubernetes restarts it, and the Pod ends up in a restart loop. Use a Job.
  • A per-node agent with many replicas. Replicas do not map to nodes and pile up on some of them. Use a DaemonSet.
  • No resource requests. Every controller schedules Pods by their requests, and DaemonSets multiply them by the number of nodes.
On this page