Search⌘ K
AI Features

How to Generate Scaffold CRDs

Explore how to generate scaffold CustomResourceDefinitions (CRDs) to extend Kubernetes APIs. Learn the step-by-step process to create, define, and install scaffold projects, automate manifest generation, and manage custom resources effectively within your cluster.

Scaffold CRDs

With CRDs, we can easily extend Kubernetes APIs by declaring objects in the YAML or JSON format.

Now, let’s take a look at the CRD and schema in more detail, so we can learn how to make a scaffold CRD with our own definitions.

CRD schema

The schema of CRDs is shown below:

YAML
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
# name must be in the form: <plural>.<group>
name: <name>
spec:
group: <group name>
conversion: #optional
# Specifies how custom resources are converted between versions
# can be None or Webhook
strategy: None
names: # Specify the resource and kind names for the custom resource
categories: # optional
# List of categories this custom resource belongs to (e.g. 'all')
- <mycategory>
kind: <Uppercase name>
listKind: <Uppercase list kind, defaulted to be kindList>
plural: <lowercase plural name>
shortNames: # optional
# List of strings as short names
- <alias1>
singular: <lowercase singular name, defaulted to be lowercase kind>
scope: Namespaced # Namespaced or cluster scope
versions: # List of all API versions
- name: v1alpha1
schema: # Optional
openAPIV3Schema: # OpenAPI v3 schema to use for validation and pruning
description: HelmChart is the Schema for the helm chart
properties: # Describe all the fields
...
required: # Mark required fields
- ...
type: object
served: true
storage: true
subresources: # Optional
status: {} # To enable the status subresource (optional)
scale: # Optional
specReplicasPath: <JSON path for the replica field, such as `spec.replicas`>
statusReplicasPath: <JSON path for the replica number in the status>
labelSelectorPath: <JSON path that corresponds to Scale `status.selector`>
additionalPrinterColumns: # Optional
# Specify additional columns returned in Table output. Used by kubectl
- description: The phase of this custom resource # Example
jsonPath: .status.phase
name: STATUS
type: string
- jsonPath: .metadata.creationTimestamp # Example
name: AGE
type: date

Defining a simple API can be quite easy because we’ve only got a few fields. However, creating OpenAPI schema manually can be very tedious, because we have to we declare all the fields, including ...