Docker & Kubernetes
CRD YAML
Learn the CRD YAML structure.
CRD YAML
A CRD's name must have the form <plural>.<group>. names gives the type's names, scope the namespace scope, and versions the served API versions and their validation definitions:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: yedekler.ornek.com
spec:
group: ornek.com
scope: Namespaced
names:
plural: yedekler
singular: yedek
kind: Yedek
shortNames: [yd]
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
veritabani: {type: string}
takvim: {type: string}
saklamaGun: {type: integer}
storage: true shows which version is written to etcd; it must be on exactly one version.
Scope and names
scope: Namespaced binds the type to namespaces (most application resources); Cluster uses a single cluster-wide name space (e.g. a platform setting). names determines which names kubectl recognizes:
names:
plural: yedekler # kubectl get yedekler, URL path
singular: yedek # kubectl get yedek
kind: Yedek # kind in YAML
shortNames: [yd] # kubectl get yd
categories: [all] # appears in kubectl get all
Exercise Write a CRD
Write a CRD YAML: apiextensions.k8s.io/v1; name yedekler.ornek.com; group: ornek.com, scope: Namespaced; names: plural: yedekler, singular: yedek, kind: Yedek; in versions, name: v1, served: true, storage: true. This is the first part of the file: the API server also requires a validation definition for each version; you'll add it in lesson 5 of this group.
Show example solution
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: yedekler.ornek.com
spec:
group: ornek.com
scope: Namespaced
names:
plural: yedekler
singular: yedek
kind: Yedek
versions:
- name: v1
served: true
storage: true
Test yourself
-
What must metadata.name be for a CRD with group: ornek.com and plural: yedekler?
- Yedek
- ornek.com
- yedek.v1
- yedekler.ornek.com
Show answer
yedekler.ornek.com — If the name doesn't match, the API server rejects the CRD.
-
Make the type namespace-scoped.
spec:
group: ornek.com
scope: ____
Show answer
spec:
group: ornek.com
scope: Namespaced
-
Match.
- plural
- URL and list name
- kind
- YAML type
- shortNames
- Abbreviation
- storage: true
- etcd version
Next lesson: Custom resource