Kubernetes Custom Resource Definitions (CRDs) provide a way to extend the Kubernetes API with new resources that represent user-defined objects. CRDs allow Kubernetes administrators and developers to create and use new resources without having to modify the Kubernetes API server or write any code.
In this article, we'll take a look at how CRDs work and how you can use them to extend the Kubernetes API. We'll also explore some of the use cases for CRDs and look at some example CRDs that have been developed by the community.
A Custom Resource Definition (CRD) is a way to define a new Kubernetes resource. CRDs are used to extend the Kubernetes API with new resources that represent user-defined objects. CRDs allow Kubernetes administrators and developers to create and use new resources without having to modify the Kubernetes API server or write any code.
CRDs are similar to the built-in Kubernetes resources, such as Pods and Services. Like built-in resources, CRDs have a name, a schema, and a set of operations (such as create, read, update, and delete). CRDs can also be used in conjunction with the built-in resources to create new, composite resources.
CRDs are stored in the Kubernetes API server and are used by the Kubernetes API server to validate and serve user requests. CRDs are defined using the OpenAPI v3 specification.
The OpenAPI v3 specification is a standard for describing RESTful APIs. It defines the structure of the API, the operations that can be performed, the input and output formats, and the authentication methods.
The OpenAPI v3 specification is used by the Kubernetes API server to validate user requests. When a user sends a request to the Kubernetes API server, the Kubernetes API server uses the OpenAPI v3 specification to validate the request. If the request is valid, the Kubernetes API server forwards the request to the appropriate CRD.
The Kubernetes API server uses the OpenAPI v3 specification to validate user requests. If the request is valid, the Kubernetes API server forwards the request to the appropriate CRD.
CRDs have a number of benefits over traditional API development approaches:
CRDs can be used to extend the Kubernetes API with new resources that represent user-defined objects. CRDs allow Kubernetes administrators and developers to create and use new resources without having to modify the Kubernetes API server or write any code.
CRDs can be used to create new resources that represent:
Creating a CRD is a two-step process:
The OpenAPI v3 specification is a standard for describing RESTful APIs. It defines the structure of the API, the operations that can be performed, the input and output formats, and the authentication methods.
The OpenAPI v3 specification is used by the Kubernetes API server to validate user requests. When a user sends a request to the Kubernetes API server, the Kubernetes API server uses the OpenAPI v3 specification to validate the request. If the request is valid, the Kubernetes API server forwards the request to the appropriate CRD.
Registering the CRD with the Kubernetes API server is a two-step process:
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: {crd-name}
spec:
group: {crd-group}
version: {crd-version}
names:
kind: {crd-kind}
plural: {crd-plural}
scope: {crd-scope}
kubectl create -f crd.yaml
Once you have created a CRD, you can use it to create new resources. Creating a resource is a two-step process:
The OpenAPI v3 specification is a standard for describing RESTful APIs. It defines the structure of the API, the operations that can be performed, the input and output formats, and the authentication methods.
The OpenAPI v3 specification is used by the Kubernetes API server to validate user requests. When a user sends a request to the Kubernetes API server, the Kubernetes API server uses the OpenAPI v3 specification to validate the request. If the request is valid, the Kubernetes API server forwards the request to the appropriate CRD.
Creating a resource is a two-step process:
kubectl create -f {resource-definition.yaml}
The following are some example CRDs that have been developed by the community:
In this article, we've taken a look at how CRDs work and how you can use them to extend the Kubernetes API. We've also explored some of the use cases for CRDs and looked at some example CRDs that have been developed by the community.