Kubernetes Operators Explained: CRDs, Controllers, Day-2 Tasks

Kubernetes Operators Explained: CRDs, Controllers, Day-2 Tasks

Kubernetes operators explained in plain terms: an operator is software that runs inside your cluster and manages a specific application the way a skilled human operator would. It watches a custom resource that describes what you want, then does the work needed to make reality match that description, including the day-to-day tasks that a basic deployment cannot handle. The short answer is that an operator turns operational knowledge into code, so a database, a message queue or a monitoring system can install, upgrade, back up and repair itself with far less manual effort.

The pattern was introduced by CoreOS in November 2016, alongside two early examples: an operator for etcd, the distributed key-value store that Kubernetes itself uses, and one for Prometheus, the monitoring system. The idea caught on because Kubernetes was already good at running stateless applications but offered little help with stateful ones, which need careful steps for clustering, failover and upgrades.

The official Kubernetes documentation defines operators as software extensions that use custom resources to manage applications and their components. If you are new to the platform, our guide to Kubernetes explained covers the foundations this article builds on.

Key takeaways

  • A Kubernetes operator is a custom controller plus a custom resource definition, or CRD, that together automate the running of one specific application.
  • The operator watches a custom resource and runs a reconcile loop, repeatedly moving the real state of the cluster towards the desired state written in that resource.
  • Operators are most valuable for stateful applications and day-2 operations such as backups, upgrades, scaling and failover.
  • Common examples include the Prometheus Operator, cert-manager, Strimzi for Kafka and Postgres operators such as CloudNativePG.
  • Do not write your own operator when a Helm chart, a StatefulSet or an existing operator already solves the problem.

What an operator actually is

Every operator is a controller, but not every controller is an operator. A controller is a loop that watches Kubernetes objects and moves the current state of the cluster towards the desired state declared in those objects, and Kubernetes itself is built from dozens of them. An operator is a controller with application-specific knowledge: it understands one application deeply enough to perform the operations a human specialist would, such as adding a database replica, taking a backup before an upgrade, or rebuilding a failed cluster member.

The power is that routine expertise becomes repeatable and available around the clock, so a team can run a complex database without keeping its runbook in one person’s head. The cost is that someone must write, test and maintain that expertise in code, and a buggy operator can do damage faster than a human, because it acts automatically. Best for: teams running stateful applications that need repeated, careful operational steps a plain deployment cannot express.

The two parts: a CRD and a controller

An operator has two components that work together. The first is a Custom Resource Definition, or CRD, which teaches the API server a new resource type.

Once you apply a CRD, you can create objects of that type with kubectl, just like Deployments or Services, with schema validation, role-based access control and the usual kubectl commands. A CRD alone does nothing, however, because the API server only stores the object; nothing acts on it until a controller is watching.

The second component is the controller, a long-running process that usually runs as a Deployment inside the cluster. It watches objects of the custom type and creates or updates the underlying resources, such as StatefulSets, Services, ConfigMaps and Secrets, to bring the application into line with the desired state.

Controllers are commonly built with Kubebuilder or the Operator SDK, using the controller-runtime library, and distributed through OperatorHub or a Helm chart. The control plane components that host these controllers are described in our guide to Kubernetes architecture.

apiVersion: example.com/v1
kind: PostgresCluster
metadata:
  name: orders-db
spec:
  instances: 3
  version: "16"
  backup:
    schedule: "0 2 * * *"

The example above shows the idea in miniature. Instead of writing a StatefulSet, a Service, several ConfigMaps and a CronJob for backups, you declare a single PostgresCluster object with three instances, a version and a backup schedule. The operator reads that declaration and builds everything underneath it, and when you change the instance count or the version, it works out the safe sequence of steps to reach the new state.

Best for: application teams that want a simple, declarative interface to a complicated system they run repeatedly.

How the reconcile loop works

The heart of every operator is the reconcile loop, a function that receives the name of one object, reads its desired state from the spec, looks at the actual state of the world, and takes one step to close the gap. It then returns, and it is called again whenever the object changes, whenever a child resource it owns changes, or after a delay it requests. Because the loop is level-triggered rather than edge-triggered, it keeps comparing the current state with the desired state, so a missed event or a failed step is corrected on the next pass instead of being lost.

Three properties make this loop reliable. First, it must be idempotent, so running it twice gives the same result as running it once, because it will run many times. Second, it should take small steps and requeue itself rather than completing a long operation, such as an upgrade, in one pass, so a crash mid-way leaves a state the next pass can continue from.

Third, it records progress in the status section of the custom resource. Our Kubernetes troubleshooting guide shows how to inspect an operator’s logs and status when reconciliation stalls.

What operators are good at: day-2 operations

Day-1 operations are installation and first setup, and most tools handle them well. Day-2 operations are everything after that: scaling, upgrading, backing up, restoring, failing over and recovering from failure.

This is where operators earn their keep, because day-2 work for a stateful application is a sequence of ordered, conditional steps that depends on the application’s internal state. A database upgrade, for example, may require a backup first, then a rolling restart in a specific order, then a check that replication has caught up before the next member is touched.

An operator encodes that sequence once and runs it the same way every time, which removes the variation that causes most operational incidents. It can also react to events a human would miss at three in the morning, such as a failed replica that needs rebuilding from a backup, or a certificate that is about to expire. Popular examples show the range: the Prometheus Operator manages monitoring stacks, cert-manager automates TLS certificates, Strimzi runs Kafka clusters, and Postgres operators such as CloudNativePG manage highly available database clusters with automated backups and failover.

Best for: production stateful workloads where the cost of a manual mistake during an upgrade or a failover is high.

An engineer at a laptop in a modern office, with a terminal window and a diagram of connected boxes on the screen
An operator watches a custom resource and reconciles the cluster towards the state it declares, automating the steps a human specialist would otherwise perform by hand.

Operator, Helm chart or plain StatefulSet?

Choosing between an operator, a Helm chart and a plain StatefulSet is a common source of confusion, and the right answer depends on how much operational behaviour the application needs. A StatefulSet gives you stable identities and ordered startup for pods, which is enough for a simple stateful service.

A Helm chart adds templating and packaging, so the same application can be installed with different settings in different environments. An operator adds a live controller that keeps managing the application after installation.

The practical rule is to climb the ladder only when the lower rung fails you. If the application is stateless, a Deployment is enough. If it is stateful but its operations are simple, a StatefulSet plus a Helm chart is usually the right choice.

Reach for an operator when the application needs ongoing, application-aware decisions, such as coordinated failover, backup scheduling, or version-specific upgrade steps. For background on the deployment patterns operators often complement, see our guide to GitOps explained.

Approach What it provides Day-2 automation When to choose it
Plain Deployment or StatefulSet Built-in workload management None beyond restarts and scaling Simple stateless or stateful services
Helm chart Templating, packaging, install-time values None; it renders manifests and stops Repeatable installs with different settings
Kubernetes operator Custom resource plus a live controller Backups, upgrades, failover, repair Complex stateful apps with ongoing operations
Managed cloud service Provider runs the application for you Handled by the provider When you prefer to buy the operations outright

The five capability levels

The Operator Framework publishes a capability model with five levels that describe how much of an application’s lifecycle an operator automates. Level one covers basic installation, meaning the operator can deploy the application from its custom resource.

Level two adds seamless upgrades, so the operator can move the application between versions safely. Level three adds full lifecycle management, including backups and restores.

Level four adds deep insights, such as metrics and health reporting that reflect the application’s own state rather than just its pods. Level five adds auto-pilot capabilities, where the operator tunes the application itself, for example by adjusting configuration in response to load. OperatorHub listings show the level each operator claims, and it is a useful filter: a level-five claim for a production database deserves a close look at exactly what it automates before you trust it.

Best for: comparing operators on a marketplace, where the claimed capability level tells you how much operational work you are actually buying.

Decision framework: should you write your own operator?

  • Use an existing operator first when one covers your application, because building one duplicates work the community has already tested.
  • Use a Helm chart or a StatefulSet when the application needs installation and simple scaling, but no ongoing application-aware decisions.
  • Write an operator only when the application has complex day-2 operations that you perform repeatedly and that follow clear, automatable rules.
  • Check whether a managed service exists before building, because buying the operations is often cheaper than staffing them.
  • Count the maintenance cost honestly: an operator is software you now own, with bugs, upgrades and Kubernetes version compatibility to track.
  • Start small if you do build one, automating installation first and adding upgrades, backups and failover one capability at a time.

Frequently asked questions

What is a Kubernetes operator in simple terms?

A Kubernetes operator is software that manages one specific application inside your cluster, using a custom resource to describe what you want and a controller that does the work to achieve it. It encodes the operational knowledge of a human specialist, so tasks such as backups, upgrades and failover happen automatically.

What is the difference between an operator and a controller?

Every operator is a controller, but not every controller is an operator. A controller is a loop that watches objects and moves the cluster towards the desired state, while an operator is a controller that carries application-specific operational knowledge for one particular application, managed through its own custom resources.

Do I need an operator for a stateless application?

Almost certainly not. Stateless applications are well served by Deployments, which handle rolling updates, scaling and restarts. Operators exist for the extra complexity of stateful applications, where operations depend on the application’s internal state and need ordered, conditional steps.

What are CRDs in Kubernetes?

A Custom Resource Definition, or CRD, extends the Kubernetes API with a new resource type, such as PostgresCluster or Kafka. Once installed, you can create, read, update and delete objects of that type with kubectl, and they gain schema validation and access control like built-in resources.

Are operators the same as Helm charts?

No. A Helm chart is a packaging and templating tool that renders manifests at install time and then stops, while an operator is a live controller that keeps watching and managing the application afterwards. The two are often used together, with a chart installing the operator itself.

Latest articles

Scroll to Top