How to Generate Scaffold CRDs
Learn how to generate a scaffold CRD.
We'll cover the following...
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:
Press + to interact
apiVersion: apiextensions.k8s.io/v1kind: CustomResourceDefinitionmetadata:# 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 Webhookstrategy: Nonenames: # Specify the resource and kind names for the custom resourcecategories: # 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 scopeversions: # List of all API versions- name: v1alpha1schema: # OptionalopenAPIV3Schema: # OpenAPI v3 schema to use for validation and pruningdescription: HelmChart is the Schema for the helm chartproperties: # Describe all the fields...required: # Mark required fields- ...type: objectserved: truestorage: truesubresources: # Optionalstatus: {} # To enable the status subresource (optional)scale: # OptionalspecReplicasPath: <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 # ExamplejsonPath: .status.phasename: STATUStype: string- jsonPath: .metadata.creationTimestamp # Examplename: AGEtype: date
Defining a simple API can be quite easy because we’ve only got a few fields. However, creating OpenAPI schema ...
Access this course and 1400+ top-rated courses and projects.