Custom Resource Definitions

C’est une façon de créer des objets customs dans 1. Kubernetes. C’est une alternative au Aggregated API. C’est objet sont en mesure d’avoir une control loop (et controller) afin de controller le status des ressources. Si RBAC est utilisé pour l’authentification, la nouvelle ressource devra être autorisé aux utilisateurs. La validation des ressources lors de leurs création se fais sur le controller directement.

Info

Chaque ressource ajouté au cluster sont sur le path apiextensions.k8s.io/v1 de l’API.

Chaque ressource peuvent avoir un scope différent, soit Namespaced ou Cluster.

Exemple

Voici un exemple d’une ressource custom:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  # name must match the spec fields below, and be in the form: <plural>.<group>
  name: crontabs.stable.example.com
spec:
  # group name to use for REST API: /apis/<group>/<version>
  group: stable.example.com
  # list of versions supported by this CustomResourceDefinition
  versions:
    - name: v1
      # Each version can be enabled/disabled by Served flag.
      served: true
      # One and only one version must be marked as the storage version.
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  # either Namespaced or Cluster
  scope: Namespaced
  names:
    # plural name to be used in the URL: /apis/<group>/<version>/<plural>
    plural: crontabs
    # singular name to be used as an alias on the CLI and for display
    singular: crontab
    # kind is normally the CamelCased singular type. Your resource manifests use this.
    kind: CronTab
    # shortNames allow shorter string to match your resource on the CLI
    shortNames:
    - ct

Name

Le nom doit match ce qui se retrouve dans le spec. La format est <plural name>.<group>.

Group

Le nom du groupe est accessible directement de l’API par /apis/<group>/<version> ou /apis/stable/<version>/<plural name>.

References