A Kubernetes operator is a custom controller paired with a custom resource that encodes the operational knowledge of a human administrator, so that a complex application can be deployed, configured, upgraded, backed up and repaired automatically inside Kubernetes. The approach, also called the operator pattern, extends the platform’s declarative model beyond stateless workloads to software such as databases, message brokers and monitoring stacks.
In the Cloud subject, operators matter because they turn runbook procedures into code. Instead of a person following a checklist to fail over a database replica, the operator watches the cluster and performs the same steps whenever the observed state drifts from the desired state.
How a Kubernetes operator works
An operator works by running a reconciliation loop that continuously compares the desired state declared in a custom resource with the actual state of the cluster and then acts to close the gap. The user writes a short manifest, for example a PostgresCluster object requesting three replicas and nightly backups, and the operator translates that intent into Pods, StatefulSets, Services, Secrets and scheduled jobs.
The mechanism rests on three building blocks. A Custom resource definition (CRD) registers a new API type with the Kubernetes API server, so the new object is stored in etcd like any built-in resource. A controller process, usually running as a Deployment inside the cluster, subscribes to change events through watches and informers. Finally, the domain logic inside the controller decides which concrete actions bring reality in line with the specification.
The following table maps each component to its role in the loop.
| Component | Role | Where it lives |
|---|---|---|
| Custom resource definition | Defines the schema of the new API type | Kubernetes API server and etcd |
| Custom resource | Declares the desired state for one instance | Namespace of the application |
| Controller | Watches events and reconciles state | Pod managed by a Deployment |
| RBAC rules | Grant the controller permission to act | ServiceAccount, Role, ClusterRole |
| Status subresource | Reports observed state and conditions | Field on the custom resource |
Reconciliation must be idempotent and level-based. The controller should reach the same result whether it runs once or a hundred times, and it should react to the current state rather than to the exact sequence of events, because events can be dropped, merged or delivered late.
Operator capability levels
Operators differ widely in how much operational work they automate, and the community commonly describes this with a five-level capability model used by the Operator Framework. A basic operator only installs software, while a mature one tunes performance and heals failures without human help.
| Level | Name | What the operator automates |
|---|---|---|
| Level 1 | Basic install | Provisioning and configuration from a custom resource |
| Level 2 | Seamless upgrades | Patch and minor version upgrades of the application |
| Level 3 | Full lifecycle | Backup, restore, failure recovery and storage management |
| Level 4 | Deep insights | Metrics, alerts, log processing and workload analysis |
| Level 5 | Autopilot | Horizontal and vertical scaling, auto-tuning, anomaly detection |
Most production-grade database operators reach level 3 or level 4. Level 5 claims deserve scrutiny, because automatic tuning of a stateful system is hard to verify and can mask underlying capacity problems.
Operators compared with related Kubernetes tools
An operator differs from Helm and from built-in controllers because it manages the entire lifecycle continuously, not only the initial installation. Helm renders templates and applies them once per release, whereas an operator stays running and responds to change at any time.
| Approach | Main strength | Main limitation |
|---|---|---|
| Kubernetes operator | Day-2 automation with domain logic | Code to write, test and maintain |
| Helm chart | Simple packaging and versioned releases | No runtime reaction after install |
| StatefulSet alone | Stable identities and ordered rollout | No knowledge of replication or backups |
| GitOps controller | Syncs manifests from a Git repository | Applies state but has no application logic |
| External scripts | Quick to write for one task | Run outside the cluster, often fragile |
These tools are complementary rather than competing. A common setup installs the operator itself with a Helm chart, stores custom resources in Git, and lets Argo CD or a similar GitOps tool apply them, while the operator handles everything that happens afterward.
Building and choosing an operator
Teams typically build operators with an SDK that generates scaffolding, CRD manifests and test harnesses, so engineers can concentrate on reconciliation logic. The choice of toolkit depends on language skills and on how much control the application requires.
| Toolkit | Language | Best suited for |
|---|---|---|
| Kubebuilder | Go | Full-featured operators built on controller-runtime |
| Operator SDK | Go, Ansible, Helm | Teams reusing existing playbooks or charts |
| Kopf | Python | Python teams and lighter automation |
| Java Operator SDK | Java | Organizations standardized on the JVM |
Before writing a new operator, check whether a maintained community operator already exists for the software. Evaluate it on upgrade history, test coverage, backup and restore support, the permissions it requests and how quickly security issues receive fixes. An unmaintained operator becomes a liability, because it holds broad cluster rights and sits in the critical path of a stateful service.
Limitations and common mistakes
The main risk of an operator is that it concentrates powerful automation in a single process, so a logic error can damage every instance it manages at once. Operational experience points to recurring failure patterns.
- Overly broad permissions: a ClusterRole with wildcard verbs turns a controller bug into a cluster-wide incident; grant only the resources the operator actually manages.
- Edge-triggered logic: code that assumes every event arrives exactly once breaks under restarts; always recompute from the current state.
- Missing status conditions: without clear conditions in the status field, operators of the platform cannot tell whether reconciliation succeeded or stalled.
- Unsafe CRD changes: removing or renaming schema fields without API versioning and conversion webhooks can break existing resources.
- Hidden coupling to cluster versions: an operator tested on one Kubernetes release may fail after an upgrade that deprecates an API it uses.
Operators also add cognitive and maintenance cost. For a simple stateless service, a Deployment, a Horizontal Pod Autoscaler and a Helm chart are usually sufficient, and writing an operator only makes sense when the application has genuine day-2 complexity.
The short version
Kubernetes can keep simple apps running on its own, but complicated software such as a database needs an expert who knows how to back it up, fix it and upgrade it safely. A Kubernetes operator is that expert written as a program. It sits inside the cluster and watches.
You tell it what you want in a few lines, such as three copies of a database with a backup every night. The operator then does the work and keeps checking. If a copy fails at three in the morning, it repairs the setup without waiting for a person. In short, it turns a team’s know-how into automatic, repeatable actions.
Where it makes a difference
A mid-sized online retailer runs its order database on a Kubernetes cluster with a PostgreSQL operator at capability level 3. The platform team declares one custom resource that requests three replicas spread across availability zones, continuous write-ahead log archiving to object storage and a full backup every night at 02:00.
During a regional network fault, the node hosting the primary replica becomes unreachable. Within about thirty seconds the operator detects the failed health checks, promotes the most up-to-date standby, updates the Service so that applications connect to the new primary and schedules a replacement replica on a healthy node.
The checkout service sees a brief spike of connection retries but no lost orders. Before adopting the operator, the same failover required a paged engineer and roughly forty minutes of manual work; afterward, the team reviews the event the next morning from the status conditions and logs.