15 Kasım 2022 Salı

Kubernetes kind : CustomResourceDefinition

Giriş
CRD tanımlarken kind : X şeklindeki isim verilir. Daha sonra X için bir instance yaratırım.
Örnek
Şöyle yaparız
apiVersion: apiextensions.k8s.io/v1       #1
kind: CustomResourceDefinition
metadata:
 name: foos.frankel.ch                    #2
spec:
 group: frankel.ch                        #3
 names:
   plural: foos                           #4
   singular: foo                          #5
   kind: Foo                              #6
 scope: Namespaced                        #7
 versions:
   - name: v1alpha1
     served: true                         #8
     storage: true                        #9
     schema:
       openAPIV3Schema:
         type: object
         properties:
           spec:
             type: object
             properties:
               bar:
                 type: string
             required: ["bar"]
         required: ["spec"]
Açıklaması şöyle
1. Required header
2. Match the following <plural>.<group>
3. Group name for REST API — /apis/<group>/<version>
4. Plural name for the REST API — /apis/<group>/<version>/<plural>
5. Singular name to be used on the CLI and for display
6. Used in manifests
7. Can be either Cluster or Namespaced. A Cluster resource is declared cluster-wide, and there can be a single one per cluster; Namespaced resources can be multiple and need to be under a namespace; by default, default
8. A version can be enabled/disabled
9. The latest version must be marked as the storage version
Kullanmak için şöyle yaparız
apiVersion: foos.frankel.ch/v1alpha1
kind: Foo
metadata:
  name: myfoo
spec:
  bar: "whatever"
kubectl apply -f foo.yml
kubectl get foo
Örnek
Şöyle yaparız
apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition # Define the metadata and definition of the CRD metadata: name: my-crds.com.amrut.prabhu spec: group: com.amrut.prabhu names: kind: my-crd plural: my-crds scope: Namespaced versions: - name: v1 served: true storage: true # Define the schema of the CRD instances that we will create later. schema: openAPIV3Schema: type: object properties: apiVersion: type: string kind: type: string metadata: type: object spec: type: object properties: my-own-property: type: string
Metadata kısmı için açıklama şöyle
Here we define the “Kind” of our resource, i.e we want to create a CRD and we provide it a name. The name has to be of the format <CRD plural Name>.<Group name> , ie. “my-crds . com.amrut.prabhu ”. Next, in the spec section, we define the name and the plural name of the kind we are creating. This is the type we will specify while creating a new instance later.

Next, we define that the CRD will be scoped to a namespace and in the version section, we specify the version of this CRD to v1. When we want to create a new version of this definition, we will just bump up this version number.

Lastly, we have served property that defines if this CRD is enabled to be used in the cluster and storage refers to if this version of the CRD will be stored. At a time you can have only one version of the CRD that can be stored.
spec için açıklama şöyle
In this, we define the schema using the Open API version 3 standards. We specify the top level as an object which has some properties.

Now, some of the absolutely required properties are:
- apiVersion: To define the version of the CRD we will be using.
- kind: The type of the CRD
metadata: The metadata which will be added such as the name, annotations, etc. This will be of the type Object.
- spec: This defines the custom specifications properties you want to provide.

Now, in the above schema, I have specified only one property i.e my-own-property in the spec section. You can also define a property of type object having its own properties.
Eğer bu CRD için bir instance yaratmak istersek şöyle yaparız
apiVersion: com.amrut.prabhu/v1
kind: my-crd
metadata:
  name: my-custom-resource-instance
spec:
  my-own-property: "My first CRD instance"
Şeklen şöyle

Hiç yorum yok:

Yorum Gönder

Cluster Propotional Autoscaler - ReplicaSet Ekler/Siler

Giriş Açıklaması şöyle CPA aims to horizontally scale the number of Pod replicas based on the cluster’s scale. A common example is DNS ser...