A custom resource definition (CRD) is a Kubernetes API object that registers a new resource type with the cluster, so that users can create, read, update and delete instances of that type, called custom resources, through the same API, kubectl commands and access controls used for built-in objects such as Pods and Deployments. In Kubernetes and the wider Cloud subject, CRDs are the standard way to extend the control plane without modifying its source code.
A CRD on its own only teaches the API server to store and validate structured data. Behavior comes from a controller that watches those objects and acts on them; the combination of CRDs and controllers is the basis of the Kubernetes operator pattern.
How a custom resource definition extends the API
When a CRD is applied, the API server creates a new REST endpoint for the defined group, version and kind, and immediately begins serving it. No restart is required, and the new objects are persisted in etcd alongside every other cluster object.
Each CRD declares a few identifying fields. The table below lists the most important ones and their effect.
| Field | Example value | Effect |
|---|---|---|
| group | databases.example.com | API group that namespaces the new type |
| names.kind | PostgresCluster | Type name used in manifests |
| names.plural | postgresclusters | Path segment in the REST endpoint |
| scope | Namespaced or Cluster | Whether objects live inside a Kubernetes namespace |
| versions | v1alpha1, v1 | Served and stored API versions with their schemas |
The CRD name must combine the plural and the group, for example postgresclusters.databases.example.com. Using a domain the organization controls for the group avoids collisions with other vendors.
Schemas, validation and versions
Modern CRDs in the apiextensions.k8s.io/v1 API must include a structural OpenAPI v3 schema for every version. The API server uses that schema to reject invalid objects at admission, apply default values and prune unknown fields, which keeps stored data predictable.
- Type and format checks enforce strings, integers, enumerations and patterns.
- Default values fill omitted fields before the object is saved.
- CEL validation rules express cross-field constraints, such as requiring replicas to be odd.
- Pruning drops fields that the schema does not declare.
A CRD can serve several versions at once, but exactly one version is the storage version. When versions differ structurally, a conversion webhook translates objects between them. The table compares the two conversion strategies.
| Strategy | How it works | When to use it |
|---|---|---|
| None | Only the apiVersion field changes | Versions share an identical schema |
| Webhook | An external service converts each object | Fields were renamed, split or restructured |
Custom resources, controllers and operators
A custom resource records desired state, and a controller makes reality match it through a reconciliation loop. The controller watches events for its kind, compares the declared specification with the actual state of the cluster, and creates, updates or deletes ordinary resources until they agree.
By convention, a custom resource has a spec section written by users and a status section written by the controller. Enabling the status subresource lets the API server handle these separately, so users cannot overwrite status and controllers cannot accidentally change the specification.
The following table shows how CRDs relate to neighboring extension concepts.
| Mechanism | What it provides | Typical use |
|---|---|---|
| Custom resource definition | New API type with schema and storage | Declaring domain objects |
| Controller | Reconciliation logic for a type | Turning objects into running resources |
| Kubernetes operator | CRDs plus controllers encoding operational expertise | Running databases, queues and certificates |
| API aggregation layer | A separate API server behind the main one | Custom storage or nonstandard behavior |
| ConfigMap | Untyped key-value configuration | Simple settings without validation |
Teams sometimes store structured configuration in ConfigMaps to avoid creating a CRD. This works for small settings, but CRDs offer schema validation, versioning and fine-grained RBAC, which matter once several teams depend on the data.
Practical design guidance
A well-designed CRD exposes a small, declarative specification that describes what users want rather than how to achieve it. Implementation details belong in the controller, not in the API surface.
| Decision | Recommended choice | Reason |
|---|---|---|
| Scope | Namespaced unless truly global | Fits multi-tenant access control |
| Initial version | v1alpha1 until the API stabilizes | Signals that breaking changes may occur |
| Printer columns | Add a few key fields and status | Makes kubectl get output useful |
| Status reporting | Use standard conditions with reasons | Tools and humans can read health uniformly |
| Deletion handling | Use finalizers for external resources | Prevents orphaned cloud resources |
Frameworks such as Kubebuilder and the Operator SDK generate CRD manifests from Go types, including schema markers for validation. Installing CRDs through Helm is common, but Helm deliberately does not upgrade or delete CRDs in its dedicated directory, so many teams manage them separately.
Limitations and common mistakes
CRDs are powerful, yet they introduce cluster-wide state that outlives the applications using them. Deleting a CRD deletes every custom resource of that type, which can remove critical configuration in one command.
- Overly large objects strain etcd, which limits individual objects to about 1.5 MB by default.
- Breaking schema changes without new versions corrupt clients and stored data.
- Missing RBAC rules leave users unable to read or edit the new type.
- Too many CRDs slow API discovery and increase control plane memory use.
- Stuck finalizers block deletion when the controller is removed first.
A frequent misconception is that installing a CRD makes something happen. Without a running controller, custom resources are inert records: they are stored and validated, but nothing reacts to them.
The simple explanation
Kubernetes understands a fixed set of things out of the box, such as containers and network services. A custom resource definition teaches it a new word, for example “database” or “certificate”.
Think of it as adding a new form to an office filing system. The definition describes which boxes the form has and which answers are allowed. A separate worker, the controller, reads the filed forms and carries out the requests.
How it is used in practice
A platform team at a software company wants developers to get PostgreSQL databases on request without opening tickets. It installs a database operator that adds a PostgresCluster CRD to the company’s Kubernetes clusters.
A developer now writes a short manifest asking for a cluster with three instances, 50 GB of storage and nightly backups, then applies it with kubectl. The API server validates the request against the schema and rejects a typo in the backup schedule immediately. Once corrected, the operator creates a StatefulSet, Services, Secrets and PersistentVolumes, and reports progress in the status conditions.
Provisioning that used to take two days now takes about ten minutes, and every database follows the same tested configuration. Access is governed by ordinary RBAC rules, so each team can manage only the databases in its own namespace.