|
| 1 | +--- |
| 2 | +layout: two-cols |
| 3 | +transition: fade |
| 4 | +title: Custom Resource Definitions |
| 5 | +--- |
| 6 | + |
| 7 | +# [Custom Resource Definitions](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions) |
| 8 | + |
| 9 | +They allow the extension of Kubernetes API by introducing new resource types, according to the <Link to="operator-pattern">operator pattern</Link> |
| 10 | + |
| 11 | +<v-clicks> |
| 12 | + |
| 13 | +Several operators that can be installed as `helm charts` provide their own `CRDs` |
| 14 | + |
| 15 | +</v-clicks> |
| 16 | + |
| 17 | +--- |
| 18 | +layout: two-cols |
| 19 | +transition: fade |
| 20 | +hideInToc: true |
| 21 | +--- |
| 22 | + |
| 23 | +# [Custom Resource Definitions](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions) |
| 24 | + |
| 25 | +`CRDs` define the schema for the custom resources |
| 26 | + |
| 27 | +<v-click at="3"> |
| 28 | + |
| 29 | +The custom resource can be `Namespace` specific or defined `Cluster` wide |
| 30 | + |
| 31 | +</v-click> |
| 32 | + |
| 33 | +<v-click at="7"> |
| 34 | + |
| 35 | +Version name must follow a [specific schema](https://kubernetes.io/docs/reference/using-api/#api-versioning) |
| 36 | + |
| 37 | +</v-click> |
| 38 | + |
| 39 | +<v-click at="10"> |
| 40 | + |
| 41 | +The resource structure is defined via [OpenAPI v3.0 schemas](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#specifying-a-structural-schema) |
| 42 | + |
| 43 | +</v-click> |
| 44 | + |
| 45 | +<div class="mt-25"/> |
| 46 | + |
| 47 | +<small v-click="5"> |
| 48 | + |
| 49 | +N.B. the `name` cannot be chosen arbitrarily; it must be set as `"{.spec.names.plural}.{.spec.group}"` and be a valid [DNS subdomain name](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) |
| 50 | + |
| 51 | +</small> |
| 52 | + |
| 53 | +::right:: |
| 54 | + |
| 55 | +<Transform :scale="0.9" origin="top center"> |
| 56 | +<<<@/snippets/manifests/custom-resource-definitions/crd-distro.yaml yaml[crd-distro.yaml]{all|1-2|6|7|8-10|4|11-28|12|13|14|15-28}{lines:true} |
| 57 | +</Transform> |
| 58 | + |
| 59 | +<!-- |
| 60 | +- [click]: `apiVersion` and `kind` |
| 61 | +- [click]: `group` |
| 62 | +- [click]: `scope` |
| 63 | +- [click]: `names` |
| 64 | +- [click]: `name` |
| 65 | +- [click]: `versions` |
| 66 | +- [click]: `name` |
| 67 | + |
| 68 | +- [click]: `served` |
| 69 | +- [click]: `storage` |
| 70 | + Only one version must have this field set to `true`. |
| 71 | + It indicates which version is used to serialize the resource to be stored it in etcd |
| 72 | +- [click]: `schema` |
| 73 | +
|
| 74 | +```shell |
| 75 | +kubectl apply -f ./snippets/manifests/custom-resource-definitions/crd-distro.yaml |
| 76 | +kubectl get crds |
| 77 | +``` |
| 78 | +--> |
| 79 | + |
| 80 | +--- |
| 81 | +layout: two-cols |
| 82 | +hideInToc: true |
| 83 | +--- |
| 84 | + |
| 85 | +# [Custom Resource Definitions](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions) |
| 86 | +Once the `CRDs` are defined, the relative resources are managed as the native ones |
| 87 | + |
| 88 | +::right:: |
| 89 | + |
| 90 | +<<<@/snippets/manifests/custom-resource-definitions/distro-fedora.yaml yaml[distro-fedora.yaml]{all|1-2|5-8|all}{lines:true} |
| 91 | +<div class="mt-5"/> |
| 92 | +<<<@/snippets/manifests/custom-resource-definitions/distro-ubuntu.yaml yaml[distro-ubuntu.yaml]{all|1-2|5-8|all}{lines:true,at:1} |
| 93 | + |
| 94 | +<!-- |
| 95 | +- [click]: `apiVersion` and `kind` |
| 96 | +- [click]: `spec` |
| 97 | +
|
| 98 | +```shell |
| 99 | +kubectl apply -f ./snippets/manifests/custom-resource-definitions/distro-fedora.yaml |
| 100 | +kubectl apply -f ./snippets/manifests/custom-resource-definitions/distro-ubuntu.yaml |
| 101 | +kubectl get distro |
| 102 | +kubectl describe distro |
| 103 | +``` |
| 104 | +--> |
0 commit comments