CodeBlanks Logo Icon CodeBlanks

Custom resource

Learn to create custom resources from a CRD.

Custom resource

After the CRD is applied, objects of that type (custom resources, CRs) are created. apiVersion is group/version, and kind is the kind from the CRD:

apiVersion: ornek.com/v1
kind: Yedek
metadata:
  name: magaza-gece
  namespace: magaza
spec:
  veritabani: db
  takvim: "0 3 * * *"
  saklamaGun: 14
$ kubectl apply -f yedek.yaml
yedek.ornek.com/magaza-gece created
$ kubectl get yd -n magaza
NAME          AGE
magaza-gece   5s

Additional printer columns

The default kubectl get output has only NAME and AGE. By adding additionalPrinterColumns to the CRD, important fields are shown in the table:

    - name: v1
      additionalPrinterColumns:
        - name: Veritabani
          type: string
          jsonPath: .spec.veritabani
        - name: Takvim
          type: string
          jsonPath: .spec.takvim

$ kubectl get yd -n magaza
NAME          VERITABANI   TAKVIM      AGE
magaza-gece   db           0 3 * * *   2m

Practice Create a Yedek

Write the YAML of a Yedek object: apiVersion: ornek.com/v1, kind: Yedek; name magaza-gece, namespace magaza; spec: veritabani: db, takvim: "0 3 * * *", saklamaGun: 14.

Starter code

terminal
# buraya yaz

Sample solution

terminal
apiVersion: ornek.com/v1
kind: Yedek
metadata:
  name: magaza-gece
  namespace: magaza
spec:
  veritabani: db
  takvim: "0 3 * * *"
  saklamaGun: 14

Expected output

yedek.ornek.com/magaza-gece created

Questions and answers

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

1 What happens to all objects of a type if its CRD is deleted?

  • They move to the default namespace
  • They turn into ConfigMaps
  • They are all deleted Correct answer
  • They remain

Explanation: Deleting a CRD is irreversible data loss; it's done with care in production.

2 Write the custom resource's API version.

Question
apiVersion: ornek.com/____
kind: Yedek
Answer
apiVersion: ornek.com/v1
kind: Yedek

Explanation: apiVersion has the form group/version.

3 Match.

Term Meaning
apiVersion: ornek.com/v1 Group and version
kind: Yedek Kind from the CRD
additionalPrinterColumns Table columns
jsonPath Field to show

All lessons in Expert