Skip to content
Rahul Shishodiaon GitHub LinkedIn profile

CustomResourceDefinitions (CRDs)

  • CRD: extend K8s API with custom resource types
  • Custom resource: instance of a CRD (like Pod is instance of core API)
  • Operators (controllers): out of exam scope; know CRD + CR only

CRD schema

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: widgets.example.com    # <plural>.<group>
spec:
  group: example.com
  scope: Namespaced            # or Cluster
  names:
    plural: widgets
    singular: widget
    kind: Widget
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              size:
                type: string

Custom resource instance

apiVersion: example.com/v1
kind: Widget
metadata:
  name: my-widget
spec:
  size: large

kubectl

kubectl get crds
kubectl describe crd widgets.example.com
kubectl api-resources --api-group=example.com
kubectl get widgets
kubectl create -f widget.yaml

Exam tips

  • CRD metadata.name must be <plural>.<group>
  • apiVersion on custom resource = <group>/<version>
  • Building operators/controllers: not tested