What Is a Kubernetes Operator? Automating Application Operations with Custom Resources
A Kubernetes Operator is an extension pattern that encodes an application's operating knowledge in a controller, which repeatedly brings the cluster's actual state closer to a declared state. A user describes a target configuration in a custom resource, such as `Database`; the Operator watches it and creates or adjusts resources such as StatefulSets, Services, and backup Jobs. Installing a CustomResourceDefinition (CRD) alone does not make an Operator: a CRD registers an API type and its validation schema, while a separately running controller supplies the behavior.
When an Operator helps
Kubernetes' built-in controllers are often enough for workloads managed by Deployments or StatefulSets. Some applications, however, need ordered procedures beyond keeping a number of Pods running. A database may require initialization, replica configuration, backup and restore, a safe version upgrade, and rejoining after a failure. A human operator may know these procedures and the conditions under which they are safe; a general-purpose controller does not automatically know an application's domain rules. An Operator makes repeatable parts of that knowledge executable.
Think of an Operator as two cooperating parts. A custom resource represents the user's desired state as an object in the Kubernetes API. A controller watches that object and related resources, compares desired and observed state, and takes action. Kubernetes controllers keep reconciling after changes or failures; they are not one-shot scripts. This makes an Operator a good fit for a continuing goal such as “this database must have daily backups enabled,” rather than a one-time imperative request such as “run a backup now.”
A database reconciliation example
The following hypothetical SampleDB illustrates the pattern; it does not describe a particular vendor's Operator.
An administrator declares supported goals in a `SampleDB` object, such as instance size, data-retention settings, and a backup policy.
The controller reads that object from the Kubernetes API and checks the current state of related StatefulSets, Services, and PersistentVolumeClaims.
If a resource is missing or differs from the requested configuration, the controller asks the API server to create or update it. Other Kubernetes controllers and the scheduler then handle Pod placement and execution.
When the database becomes ready, the Operator can write its observed readiness or conditions to the custom resource's `status`. Users can inspect progress with `kubectl get sampledb` or a supported detailed view.
If an administrator changes the backup policy or version, the same loop calculates the difference again. It may create backup Jobs or perform a supported upgrade sequence that includes data-format changes.
The controller repeatedly recalculates the difference between desired and current state. A design that blindly repeats a command for every event can create duplicate work on retries. Well-designed controllers consider idempotency so that repeated reconciliation is safe and report observable conditions for progress, success, or failure. These are sound design expectations, not guarantees made by every Operator; check the selected product's documentation and behavior.
CRD, custom resource, controller, and Operator
| Part | Responsibility | Does it operate the application by itself? |
|---|---|---|
| CRD | Registers a resource type and schema with the API server. | No. It stores and validates objects but contains no automation logic. |
| Custom Resource | A configuration object created using a CRD. | No. Declared values do not guarantee that anything will execute. |
| Controller | Observes state and moves it toward a declared goal. | It can, but it becomes an Operator only when it embodies application-specific operating knowledge. |
| Operator | A pattern combining an application-aware custom API and controller. | It is designed to automate repeatable lifecycle work. |
Not every CRD is an Operator, and not every controller needs a CRD. Operators commonly combine a custom resource and a custom controller. CRDs are a straightforward way to add a custom API. If an API needs specialized storage or behavior, API aggregation with a separate API server is another option, with greater operational complexity.
Deciding whether to adopt one
An Operator is useful when the same procedures recur across clusters and it is worthwhile to encode an application's expert knowledge about sequencing, validation, and recovery. Examples include creating several Kubernetes resources together or frequently performing backups, restores, and compatible upgrades. It also fits when users need small declarative configuration objects and status that they can inspect and change with Kubernetes tools.
A ConfigMap may be simpler when the job is only to deliver one configuration file to a Pod. Avoid using a CRD as an application database or work queue when the workload needs synchronous imperative operations, high-throughput user data, very large object sets, or an API whose lifecycle does not fit Kubernetes resources. Kubernetes warns that putting user or bulk data in custom resources can couple a workload too tightly to the API server.
Before adopting an Operator, find out which APIs and upgrade paths it supports; limit its RBAC permissions; understand how it retries and reports status when the controller, API server, or external storage is unavailable; and determine what deletion does to data. Check its finalizers and retention policies. Plan the lifecycle of custom objects before removing their CRD, and identify who will upgrade and monitor the controller image, CRD schema, RBAC, and backup and restore procedures.
Checking status and operating safely
An installed Operator does not prove that the application is healthy. Inspect the custom resource's status and conditions, the Operator Pod logs, generated Deployments, StatefulSets, Jobs and PVCs, and Kubernetes events. If the object exists but its readiness condition stays False, possible causes include controller errors, invalid schema values, insufficient permissions, or lack of storage capacity. Narrow down the cause from the conditions and events, then follow that Operator's documented diagnostics.
Do not assume deletion finishes immediately. A controller that must back up data or release a cloud resource can use a finalizer to delay deletion until cleanup finishes. If the controller disappears during cleanup, an object may remain in Terminating. Removing its finalizer blindly can leave external volumes or data behind, or skip a protection step. Diagnose the condition first and follow the product's recovery procedure and data-retention policy.
An Operator is not magic that “makes Kubernetes automatic.” It is a way to encode an application's operating procedures through a declarative API and a recurring reconciliation loop. Adopt one when the value of automating those procedures exceeds the added cost of running, authorizing, and upgrading the controller, and verify its recovery and data-deletion behavior in advance.
References
[Kubernetes: Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
[Kubernetes: Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
[Kubernetes: Custom Resources](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/)
[Kubernetes: CustomResourceDefinitions](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)