Custom resource definition

Also known as: custom resource

On this page 7

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.

FieldExample valueEffect
groupdatabases.example.comAPI group that namespaces the new type
names.kindPostgresClusterType name used in manifests
names.pluralpostgresclustersPath segment in the REST endpoint
scopeNamespaced or ClusterWhether objects live inside a Kubernetes namespace
versionsv1alpha1, v1Served and stored API versions with their schemas
Key fields of a custom resource definition

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.

StrategyHow it worksWhen to use it
NoneOnly the apiVersion field changesVersions share an identical schema
WebhookAn external service converts each objectFields were renamed, split or restructured
Conversion strategies for multi-version CRDs

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.

MechanismWhat it providesTypical use
Custom resource definitionNew API type with schema and storageDeclaring domain objects
ControllerReconciliation logic for a typeTurning objects into running resources
Kubernetes operatorCRDs plus controllers encoding operational expertiseRunning databases, queues and certificates
API aggregation layerA separate API server behind the main oneCustom storage or nonstandard behavior
ConfigMapUntyped key-value configurationSimple settings without validation
CRDs and related Kubernetes extension mechanisms

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.

DecisionRecommended choiceReason
ScopeNamespaced unless truly globalFits multi-tenant access control
Initial versionv1alpha1 until the API stabilizesSignals that breaking changes may occur
Printer columnsAdd a few key fields and statusMakes kubectl get output useful
Status reportingUse standard conditions with reasonsTools and humans can read health uniformly
Deletion handlingUse finalizers for external resourcesPrevents orphaned cloud resources
Design decisions for a new CRD

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.