Custom Resource Definition (CRD)
What Is a Custom Resource Definition (CRD)?
A Custom Resource Definition (CRD) is a Kubernetes API object that extends the Kubernetes API with a new resource type. It defines the resource name, API group, scope, all supported versions of this resource, and the structure of the data. It is used by Kubernetes to identify and manage its custom resources in addition to its in-built resources such as pods, deployments, and services.
How Does a Custom Resource Definition Work?
A CRD manifest is submitted by the administrator to the Kubernetes API server. The new resource type is registered in the API server, and the REST endpoints are generated for API versions. The schema of OpenAPI provides accepted fields and types of data which are verified by the server when new custom resource objects are added or modified. The server stores valid custom resource objects via the Kubernetes API.
A CRD creates resource format rather than determining functionality. A custom controller will observe instances of the resource and take necessary steps. The controller compares the desired configuration with the real status of the system and acts as necessary.
Key Characteristics of Custom Resource Definition
- API extension: Introduces new resource types under a specified API group and version.
- Schema validation: Uses an OpenAPI v3 schema to define field structures, data types, validation rules, and default values.
- Resource scope: Defines whether custom resource instances belong to individual namespaces or exist at cluster level.
- Version control: Determines which versions of API are currently in use and are stored permanently.
- Integration of controllers: It is used with custom controllers that track changes in resources and bring resources to their desired state.
Benefits of Custom Resource Definition
- Increased functionality: Introduces resource types specific to applications without changing the source code of Kubernetes.
- Declarative administration: Represents application settings using manifests of resources commonly used in Kubernetes.
- Automation: Connects the custom resource definitions with controllers to automate application administration.
- Standard API access: Provides access to custom resources through Kubernetes API calls, client libraries, and kubectl application.
Custom Resource Definition in Cloud Computing
CRDs are a means of extending Kubernetes to include more than just its inherent functions in a cloud-native context. The operator of a cloud infrastructure uses CRDs to represent various resources, such as for database systems, storage systems, or other forms of managed services. The configuration for these resources is written in custom resource manifests, and the relevant controllers do the provisioning and operate on its lifecycle.