mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-02-14 09:39:56 +00:00
⬆️ Update CRD content to deprecate v1beta1 manifests
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
# Note: apiextensions.k8s.io/v1beta1 is deprecated, and won't be served
|
||||
# in Kubernetes 1.22 and later versions. This YAML manifest is here just
|
||||
# for reference, but it's not intended to be used in modern trainings.
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
|
||||
@@ -8,6 +8,9 @@ spec:
|
||||
- name: v1alpha1
|
||||
served: true
|
||||
storage: true
|
||||
schema:
|
||||
openAPIV3Schema:
|
||||
type: object
|
||||
scope: Namespaced
|
||||
names:
|
||||
plural: coffees
|
||||
|
||||
@@ -12,9 +12,21 @@
|
||||
|
||||
---
|
||||
|
||||
## A very simple CRD
|
||||
## Creating a CRD
|
||||
|
||||
The file @@LINK[k8s/coffee-1.yaml] describes a very simple CRD representing different kinds of coffee:
|
||||
- We will create a CRD to represent the different species of coffee
|
||||
|
||||
(arabica, liberica, and robusta)
|
||||
|
||||
- We will be able to run `kubectl get coffees` and it will list the species
|
||||
|
||||
- Then we can label, edit, etc. the species to attach some information
|
||||
|
||||
(e.g. the taste profile of the coffee, or whatever we want)
|
||||
|
||||
---
|
||||
|
||||
## First shot of coffee
|
||||
|
||||
```yaml
|
||||
@@INCLUDE[k8s/coffee-1.yaml]
|
||||
@@ -22,7 +34,43 @@ The file @@LINK[k8s/coffee-1.yaml] describes a very simple CRD representing diff
|
||||
|
||||
---
|
||||
|
||||
## Creating a CRD
|
||||
## The joys of API deprecation
|
||||
|
||||
- Unfortunately, the CRD manifest on the previous slide is deprecated!
|
||||
|
||||
- It is using `apiextensions.k8s.io/v1beta1`, which is dropped in Kubernetes 1.22
|
||||
|
||||
- We need to use `apiextensions.k8s.io/v1`, which is a little bit more complex
|
||||
|
||||
(a few optional things become mandatory, see [this guide](https://kubernetes.io/docs/reference/using-api/deprecation-guide/#customresourcedefinition-v122) for details)
|
||||
|
||||
- `apiextensions.k8s.io/v1beta1` is available since Kubernetes 1.16
|
||||
|
||||
---
|
||||
|
||||
## Second shot of coffee
|
||||
|
||||
- The next slide will show file @@LINK[k8s/coffee-2.yaml]
|
||||
|
||||
- Note the `spec.versions` list
|
||||
|
||||
- we need exactly one version with `storage: true`
|
||||
|
||||
- we can have multiple versions with `served: true`
|
||||
|
||||
- `spec.versions[].schema.openAPI3Schema` is required
|
||||
|
||||
(and must be a valid OpenAPI schema; here it's a trivial one)
|
||||
|
||||
---
|
||||
|
||||
```yaml
|
||||
@@INCLUDE[k8s/coffee-2.yaml]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Creating our Coffee CRD
|
||||
|
||||
- Let's create the Custom Resource Definition for our Coffee resource
|
||||
|
||||
@@ -30,7 +78,7 @@ The file @@LINK[k8s/coffee-1.yaml] describes a very simple CRD representing diff
|
||||
|
||||
- Load the CRD:
|
||||
```bash
|
||||
kubectl apply -f ~/container.training/k8s/coffee-1.yaml
|
||||
kubectl apply -f ~/container.training/k8s/coffee-2.yaml
|
||||
```
|
||||
|
||||
- Confirm that it shows up:
|
||||
@@ -169,13 +217,13 @@ Note: we can update a CRD without having to re-create the corresponding resource
|
||||
|
||||
## Data validation
|
||||
|
||||
- By default, CRDs are not *validated*
|
||||
- CRDs are validated with the OpenAPI v3 schema that we specify
|
||||
|
||||
(we can put anything we want in the `spec`)
|
||||
(with older versions of the API, when the schema was optional,
|
||||
<br/>
|
||||
no schema = no validation at all)
|
||||
|
||||
- When creating a CRD, we can pass an OpenAPI v3 schema
|
||||
|
||||
(which will then be used to validate resources)
|
||||
- Otherwise, we can put anything we want in the `spec`
|
||||
|
||||
- More advanced validation can also be done with admission webhooks, e.g.:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user