CodeBlanks Logo Icon CodeBlanks

Summary - CRD

Combine YAML and validation to write a CRD.

Summary: CRD

In this group:

  • A CRD adds a new type to the API; objects are stored in etcd and managed with kubectl and RBAC.
  • The name is plural.group; names, scope, versions (served/storage) and openAPIV3Schema.
  • Custom resource: apiVersion: group/version, kind; additionalPrinterColumns enrich the table.
  • subresources.status keeps the spec/status split; scale gives kubectl scale and HPA support.
  • Validation definitions (required, min/max, enum, pattern, default) and CEL rules reject broken data up front.
kubectl apply -f crd.yaml
kubectl apply -f yedek.yaml
kubectl get yd -A

Practice Printer columns

Write a CRD version's additionalPrinterColumns section (starting with additionalPrinterColumns:): Veritabani (type: string, jsonPath: .spec.veritabani) and Durum (type: string, jsonPath: .status.durum).

Starter code

terminal
# buraya yaz

Sample solution

terminal
additionalPrinterColumns:
  - name: Veritabani
    type: string
    jsonPath: .spec.veritabani
  - name: Durum
    type: string
    jsonPath: .status.durum

Expected output

customresourcedefinition.apiextensions.k8s.io/yedekler.ornek.com configured
$ kubectl get yd -n magaza
NAME          VERITABANI   DURUM      AGE
magaza-gece   db           Basarili   1d

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is needed for a custom resource to gain behaviour?

  • A more detailed validation definition
  • A ClusterRole
  • An additional printer column
  • A controller (operator) watching and reconciling it Correct answer

Explanation: In the next group you'll write an operator.

2 Give the field a default value.

Question
saklamaGun: {type: integer, minimum: 1, ____: 7}
Answer
saklamaGun: {type: integer, minimum: 1, default: 7}

Explanation: default is applied if the field isn't written.

3 Match.

Term Meaning
CRD Type
CR Object
openAPIV3 definition Validation
status Controller report

All lessons in Expert