RousselTMLEARNING

Containers

Workload controllers

An overview of workload controllers in Kubernetes, their functions and use cases.

Introduction #

In Kubernetes, workload controllers orchestrate and automate the life cycle of containerized applications. They handle scaling, redundancy and resource management for applications, enabling a scalable, fault-tolerant architecture.

Deployment #

Controller for stateless applications.

Overview #

A Deployment deploys and manages stateless applications. It maintains the desired number of running Pods, handles updates and rollbacks, and offers horizontal scaling options.

Use cases #

Used for web applications, APIs or any stateless service that can easily be replicated without depending on persistent storage.

Example #

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example
        image: nginx

ReplicaSet #

Maintains the number of Pod replicas.

Overview #

A ReplicaSet maintains a constant number of identical Pods in the cluster. Deployments often rely on ReplicaSets to create and update Pods.

Use cases #

Used internally by Deployments to keep a stable number of Pods running.

StatefulSet #

For applications that need persistent storage.

Overview #

A StatefulSet is used for applications that need data persistence. Each Pod has a unique identity, preserved when the Pod is recreated, and is associated with a dedicated storage volume.

Use cases #

Databases, distributed file systems, or any application that needs a unique identifier or persistent state.

Example #

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: example-statefulset
spec:
  serviceName: "example"
  replicas: 3
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example
        image: mysql

DaemonSet #

Ensures a Pod runs on every node.

Overview #

A DaemonSet ensures that a Pod runs on every node in the cluster. It is used for monitoring, log analysis or network maintenance tasks.

Use cases #

Monitoring agents, log collection, and any service that needs to be present on every node.

Example #

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: example-daemonset
spec:
  selector:
    matchLabels:
      name: example
  template:
    metadata:
      labels:
        name: example
    spec:
      containers:
      - name: example
        image: fluentd

Job #

Running one-off tasks.

Overview #

A Job runs Pods to complete a one-off task and stops when the task is finished. It is especially suited to data processing or maintenance scripts.

Use cases #

One-off tasks such as data analysis or batch processing.

Example #

apiVersion: batch/v1
kind: Job
metadata:
  name: example-job
spec:
  template:
    spec:
      containers:
      - name: example
        image: busybox
        command: ["echo", "Hello, Kubernetes!"]
      restartPolicy: Never

CronJob #

Scheduling recurring tasks.

Overview #

A CronJob schedules recurring tasks using crontab syntax. It is useful for backups, report generation or any periodic task.

Use cases #

Recurring tasks such as backups or data cleanup.

Example #

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: example-cronjob
spec:
  schedule: "*/5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: example
            image: busybox
            command: ["echo", "Hello from CronJob"]
          restartPolicy: OnFailure

Choosing a workload controller #

  • For stateless applications: use a Deployment.
  • For stateful applications that need persistent identifiers: prefer a StatefulSet.
  • For tasks that must run on every node: choose a DaemonSet.
  • For one-off tasks: a Job is recommended.
  • For recurring tasks: a CronJob is ideal.

Related articles

Why collect metrics

Discover the key reasons to collect metrics, with concrete examples for each case.

Apdex vs Core Web Vitals

Discover the differences between Apdex and Core Web Vitals, two essential performance indicators for evaluati…

What is observability

The ability to know the internal state of a system from the data it emits. This emitted data is classified in…

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!