Summary - CRD
- Docker & Kubernetes course
- Expert
- Lesson 12/47
- 5 min
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) andopenAPIV3Schema. - Custom resource:
apiVersion: group/version,kind;additionalPrinterColumnsenrich the table. subresources.statuskeeps the spec/status split;scalegives 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 -APractice 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
# buraya yazSample solution
additionalPrinterColumns:
- name: Veritabani
type: string
jsonPath: .spec.veritabani
- name: Durum
type: string
jsonPath: .status.durumExpected 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.
saklamaGun: {type: integer, minimum: 1, ____: 7}
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 |