CRD schemas and versions
A CRD creates an API contract
Imagine a bookstore wants staff to request books using the same API workflow as other Kubernetes objects. A CustomResourceDefinition (CRD) registers a new resource type, BookRequest, with an API group, scope and schema. A custom resource (CR) is an individual object of that type, such as a request for three books. A controller is separate software that reads requests and reconciles them. Without a controller, saving a BookRequest does not order any books.
CRD → registers BookRequest typeCR → records a particular desired requestController → optional implementation of the requested behaviorIdentify the API and scope
A CRD is cluster-scoped even when the resources it defines are namespaced. In the example the group is books.example.com, the kind is BookRequest and the plural resource name is bookrequests. The CRD name combines plural and group: bookrequests.books.example.com. The API version on the CRD itself is apiextensions.k8s.io/v1; the custom object uses books.example.com/v1. Namespaced instances have distinct identities in different namespaces, whereas a cluster-scoped custom resource has no namespace. Installing a CRD changes the cluster API for everyone; it requires separate approval.
GVK: books.example.com / v1 / BookRequestGVR: books.example.com / v1 / bookrequestsGET /apis/books.example.com/v1/namespaces/book-lab/bookrequestsDefine a structural schema
A structural OpenAPI schema describes the permitted shape of custom resource data. Declare object types and nested property types explicitly, mark required fields at the appropriate level, and use constraints such as minimum and maximum. The toy schema requests one to ten books. Optional priority defaults to normal. The full CRD in lab-fixtures/crd-api/bookrequest-crd.yaml also describes observed status. The excerpt below shows only the spec portion, not an independently installable manifest.
type: objectrequired: [title, quantity]properties: title: type: string minLength: 1 quantity: type: integer minimum: 1 maximum: 10 priority: type: string enum: [normal, urgent] default: normalCreate a custom resource instance
The following example is a static object. Its kind and API version refer to the custom API, not the CRD API. The namespace must already exist for a real namespaced create. The manifest is acceptable to our local subset validator, not proven admissible by Kubernetes. When the API is registered and established, discovery can expose its resource type. A read of the instance would reveal saved data, not evidence that an external order occurred.
apiVersion: books.example.com/v1kind: BookRequestmetadata: name: math-books namespace: book-labspec: title: Algebra basics quantity: 3Choose the right extension mechanism
A CRD uses Kubernetes API machinery for persistence and ordinary resource operations. API aggregation instead registers an APIService and routes a group/version to an extension API server; the extension must supply its own API behavior and operational support. Use a CRD when declarative objects and built-in storage behavior fit the problem. Consider aggregation only when requirements justify a separate server. Neither is the same as an admission webhook or a controller. Avoid storing large application datasets in Kubernetes objects.
CRD: built-in API server storage and declared schemaAggregation: APIService + separate extension serverController: behavior based on observed objectsPractice and next step
Read the full CRD and sample instance in lab-fixtures/crd-api. Identify the group, kind, plural, scope, storage version and required fields. Predict whether quantity 0, quantity 3, and a missing title satisfy the contract. Explain why the API registration alone cannot fulfill a request. Run the offline validator after predicting results. Next: conversion and finalizers.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CRD schemas and versions — knowledge check
Design a namespaced custom resource with a structural schema and distinguish CRDs, custom objects and controllers.
What happens when a CRD is installed without a controller?
Which apiVersion belongs to a BookRequest instance in this lesson?
What is the scope of the CRD object itself?
Which quantity matches the fixture schema?
Which mechanism routes a registered API group/version to a separate server?