- Define a Database CRD with OpenAPI v3 schema validation.
- Apply the CRD to a cluster.
- Create example custom resources (CRs) to demonstrate validation errors and a final valid CR.
- Inspect the created resource with kubectl.
CRD skeleton
Start with a minimal CRD skeleton. We’ll fill in details next.Top-level fields explained
Use the table below as a quick reference for the main fields in the CRD manifest.
Notes:
metadata.namemust follow the convention<plural>.<group>; the API server enforces this.- Only one version in
spec.versionsshould havestorage: true. That version is persisted to etcd. - The OpenAPI v3 schema is validated by the API server when creating or updating custom resources.
OpenAPI v3 schema validation is enforced by the API server at object creation/update time. Only one version may have
storage: true — that version is the one persisted to etcd.Database CRD: concrete example
We’ll create a Database CRD in theplatform.example.com group. It will be Namespaced and expose databases as the plural. The schema requires two fields in spec: engine and size, both validated with enum to limit allowed values.
Create Custom Resources (CRs) — iterate with examples
We’ll walk through several CR examples to illustrate typical validation errors and then the successful CR.- Missing
metadata.name
Ifmetadata.nameis omitted, kubectl will fail before schema validation because resource names are required.
- Unsupported
enginevalue
Provide a name but use an engine value not allowed by the CRD schema (e.g.,mongodb). The API server rejects this with a schema validation error.
- Missing required
sizefield
Changeengineto a supported value but omit the requiredsizefield; the API server will report thatsizeis required.
- Final valid CR
Add the requiredsizeand any optional fields (likeversionandstorage) to create a valid resource.
<none> are used to avoid MDX interpreting angle brackets as JSX.)
Summary and next steps
This walkthrough showed how to:- Define a CRD with server-side OpenAPI v3 validation.
- Apply the CRD so your custom type is available via the Kubernetes API.
- Iterate on CRs and observe the API server enforcing schema constraints.
- Writing a controller/operator to reconcile Database resources into actual backing services.
- Adding status subresources and additional validation with
conversionor admission webhooks. - Documenting RBAC rules for users who will create Database CRs.