Friday, May 22, 2026

kubernetes controllers and workloads

In Kubernetes, Workloads are the applications you run on the cluster, while Controllers are the background control loops that watch the state of your cluster and make changes to move the current state closer to the desired state.

Think of it this way: a Workload defines what you want to run, and a Controller is the mechanism that ensures it stays running exactly how you specified.


1. Kubernetes Workloads

A workload is an application running on Kubernetes. Whether it is a single component or several working together, you run it inside a set of Pods. A Pod represents a single instance of a running process in your cluster.

Because managing individual Pods manually is tedious and risky (if a Pod dies, it doesn't self-heal), Kubernetes uses higher-level workload resources to manage them for you.

Core Workload Types

  • Deployments: The most common workload type. Best suited for stateless applications (e.g., web servers, microservices). It allows you to define how many identical replicas of a Pod you want, handles rolling updates, and lets you roll back to previous versions smoothly.

  • StatefulSets: Tailored for stateful applications that require unique identities and persistent storage (e.g., databases like PostgreSQL, MySQL, or Kafka). Unlike Deployments, Pods in a StatefulSet have a sticky identity (e.g., pod-0, pod-1) and pair with specific persistent volumes that persist even if a Pod is rescheduled.

  • DaemonSets: Ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are automatically started on them. This is ideal for infrastructure-level apps like log collectors (Fluentd), monitoring agents (Prometheus Node Exporter), or networking plugins.

  • Jobs & CronJobs: Designed for ephemeral, run-to-completion tasks.

    • A Job creates one or more Pods and ensures that a specified number of them successfully terminate (e.g., a database migration script).

    • A CronJob runs Jobs on a time-based schedule, exactly like a traditional Linux cron job (e.g., nightly backups).


2. Kubernetes Controllers

A Controller is a tracking process that watches the shared state of the cluster through the API server and makes changes attempting to move the current state toward the desired state. This is known as the Reconciliation Loop.

+------------------+       Watches       +--------------------+
|  Desired State   | <------------------ |                    |
| (YAML Configs)   |                     |     Kubernetes     |
+------------------+                     |  Controller Loop   |
                                         |  (Reconciliation)  |
+------------------+       Modifies      |                    |
|  Current State   | <------------------ |                    |
| (Actual Cluster) |                     |                    |
+------------------+                     +--------------------+

How They Work Together

Every workload mentioned above is actually driven by its own corresponding controller inside the Kubernetes control plane:

Workload ResourceManaging ControllerWhat It Responsibly Watches
DeploymentDeploymentControllerWatches ReplicaSets and Pods; handles rolling out updates without downtime.
StatefulSetStatefulSetControllerMaintains strict ordering and unique network/storage identifiers for its Pods.
DaemonSetDaemonSetControllerListens for new nodes joining the cluster and ensures the daemon pod is scheduled onto them.
Job / CronJobJobControllerTracks Pod exits codes to ensure tasks complete successfully; cleans up old pods.

The Built-in Controller Manager

Most of these core loops are packed into a single binary running in the control plane called the kube-controller-manager. While it acts as a single process to reduce complexity, each controller loop runs independently inside it.


Summary of Use Cases

  • Choose a Deployment if your app is a stateless API backend or frontend website.

  • Choose a StatefulSet if you are deploying a database or distributed system that cares about index order and identity.

  • Choose a DaemonSet if you need a utility tool running on every single server blade in your data center.

  • Choose a Job / CronJob if you want to run a batch processing script once or every Sunday at midnight.


kubernetes controllers and workloads

In Kubernetes, Workloads are the applications you run on the cluster, while Controllers are the background control loops that watch the st...