Latest
Kubernetes 1 min read

Choose Between a Deployment, DaemonSet, Job and CronJob

Choose Between a Deployment, DaemonSet, Job and CronJob
Kubernetes · November 28, 2026

Version note: examples use the Kubernetes v1.35 documentation snapshot, not necessarily the newest release. Check current support and component compatibility. These commands were not tested on a live cluster.

What this guide covers

Use a Deployment for a continuously running application, a DaemonSet for a Pod on each eligible node, a Job for work that finishes, and a CronJob for scheduled Jobs.

Before you start

Create workload-lab in a test cluster. The examples print simple output; they do not perform real backups or business tasks. Save each manifest separately.

Step 1: Run one Pod per eligible node

Save this as daemonset.yaml and apply it:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-heartbeat
  namespace: workload-lab
spec:
  selector:
    matchLabels:
      app: node-heartbeat
  template:
    metadata:
      labels:
        app: node-heartbeat
    spec:
      automountServiceAccountToken: false
      containers:
        - name: heartbeat
          image: busybox:1.37.0
          command: ["sh", "-c", "while true; do date -u; sleep 60; done"]
          resources:
            requests:
              cpu: 10m
              memory: 16Mi
            limits:
              memory: 32Mi

A DaemonSet respects node eligibility and taints. It does not necessarily run on every node regardless of restrictions.

Step 2: Run a task to completion

Save this as job.yaml and apply it:

apiVersion: batch/v1
kind: Job
metadata:
  name: one-off-report
  namespace: workload-lab
spec:
  completions: 1
  parallelism: 1
  backoffLimit: 2
  activeDeadlineSeconds: 120
  ttlSecondsAfterFinished: 600
  template:
    spec:
      restartPolicy: Never
      automountServiceAccountToken: false
      containers:
        - name: report
          image: busybox:1.37.0
          command: ["sh", "-c", "printf 'report completed\n'"]
          resources:
            requests:
              cpu: 10m
              memory: 16Mi
            limits:
              memory: 32Mi

A Job retries according to its policy. Real tasks should be safe to repeat because a retry may repeat some work.

Step 3: Schedule a task

Save this as cronjob.yaml and apply it:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: daily-report
  namespace: workload-lab
spec:
  schedule: "0 2 * * *"
  timeZone: Etc/UTC
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 300
  successfulJobsHistoryLimit: 2
  failedJobsHistoryLimit: 2
  jobTemplate:
    spec:
      backoffLimit: 1
      activeDeadlineSeconds: 300
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: report
              image: busybox:1.37.0
              command: ["sh", "-c", "date -u; printf 'scheduled report\n'"]
              resources:
                requests:
                  cpu: 10m
                  memory: 16Mi
                limits:
                  memory: 32Mi

Check the time zone and concurrency policy. Scheduled execution can be delayed or missed, so do not assume exact execution times or exactly-once delivery.

Step 4: Inspect results

Run:

kubectl -n workload-lab get daemonsets,pods
kubectl -n workload-lab get jobs,cronjobs
kubectl -n workload-lab logs job/one-off-report
kubectl -n workload-lab describe cronjob daily-report

Check completion and failure counts, not just whether the resource exists. Stop or delete scheduled test work after the exercise.

Check the result

The Job should complete and produce its expected log. The DaemonSet should cover eligible nodes; the CronJob should show the intended schedule and resulting Jobs.

References

PB
Written by

Parul Bedi

Notes and guides by Parul Bedi.

Up next

Install SonarQube on Ubuntu Step by Step

Sonar November 30, 2026 4 min read
Open post

Conversation

0 comments

No comments yet. Start the conversation below.

Leave a comment

Replying to a comment.
Be kind. Markdown is not supported in comments.