liveBook · Manning

Custom resource definition

As explained in Kubernetes in Action, Second Edition

A CustomResourceDefinition is a Kubernetes API object that extends the Kubernetes API with a new custom resource type.

A CustomResourceDefinition (CRD) extends the Kubernetes API with a new custom resource type. After installing a CRD, the cluster accepts objects with that kind, just as it accepts built-in Kubernetes objects. section 16.4.1

CRDs support several practical workflows:

  • Install Gateway API CRDs before creating Gateway API resources; choose the standard channel for stable resources or the experimental channel for resources and fields that may change. section 13.1.2 section 13.1.3
  • Define an application-specific type such as MongoDBCommunity, which can represent a desired MongoDB deployment through familiar apiVersion, kind, metadata, and spec fields. section 16.4.1 section 16.4.2
  • Remove the type by deleting its CRD after deleting the related custom resource and operator resources. section 16.4.3

Creating a MongoDB custom type

Apply the operator's CRD manifest with kubectl apply -f config/crd/bases/mongodbcommunity.mongodb.com_mongodbcommunity.yaml. The cluster then recognizes kind MongoDBCommunity. Applying a MongoDBCommunity object lets the operator reconcile the desired configuration into a StatefulSet, Services, and Secrets; the operator restores its desired state if those generated objects are changed directly. section 16.4.2

$ kubectl apply -k github.com/kubernetes-sigs/gateway-api/config/crd/experimental
customresourcedefinition/gatewayclasses.gateway.networking.k8s.io created
customresourcedefinition/gateways.gateway.networking.k8s.io created
...

Shows the kubectl command that installs Gateway API CRDs from the experimental channel and the resulting resource creation. section 13.1.3

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains installation, release channels, custom objects, reconciliation, and cleanup, but does not detail CRD schema implementation.
Examples
Uses Gateway API CRDs and a MongoDBCommunity CRD, with kubectl installation, inspection, reconciliation, and deletion commands.
What it assumes
Assumes access to a Kubernetes cluster and kubectl, while introducing custom resources, controllers, and operators through examples.
What you can do after
Operate custom API types by installing CRDs, creating custom resources, inspecting them, and removing them during cleanup.
How it connects
Connects CustomResourceDefinitions with custom resources, Kubernetes controllers, operators, Gateway API, and StatefulSets.

Also explained in

Compare how 7 books explain custom resource definition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.