Skip to content

Latest commit

 

History

History
74 lines (66 loc) · 2.47 KB

crd-creating-crds.adoc

File metadata and controls

74 lines (66 loc) · 2.47 KB

Creating a Custom Resource Definition

To create Custom Resource (CR) objects, cluster administrators must first create a Custom Resource Definition (CRD).

Prerequisites
  • Access to an {product-title} cluster with cluster-admin user privileges.

Procedure

To create a CRD:

  1. Create a YAML file that contains the following field types:

    Example YAML file for a CRD
    apiVersion: apiextensions.k8s.io/v1beta1 (1)
    kind: CustomResourceDefinition
    metadata:
      name: crontabs.stable.example.com (2)
    spec:
      group: stable.example.com (3)
      version: v1 (4)
      scope: Namespaced (5)
      names:
        plural: crontabs (6)
        singular: crontab (7)
        kind: CronTab (8)
        shortNames:
        - ct (9)
    1. Use the apiextensions.k8s.io/v1beta1 API.

    2. Specify a name for the definition. This must be in the <plural-name>.<group> format using the values from the group and plural fields.

    3. Specify a group name for the API. An API group is a collection of objects that are logically related. For example, all batch objects like Job or ScheduledJob could be in the batch API Group (such as batch.api.example.com). A good practice is to use a fully-qualified-domain name of your organization.

    4. Specify a version name to be used in the URL. Each API Group can exist in multiple versions. For example: v1alpha, v1beta, v1.

    5. Specify whether the custom objects are available to a project (Namespaced) or all projects in the cluster (Cluster).

    6. Specify the plural name to use in the URL. The plural field is the same as a resource in an API URL.

    7. Specify a singular name to use as an alias on the CLI and for display.

    8. Specify the kind of objects that can be created. The type can be in CamelCase.

    9. Specify a shorter string to match your resource on the CLI.

      Note

      By default, a CRD is cluster-scoped and available to all projects.

  2. Create the CRD object:

    $ oc create -f <file_name>.yaml

    A new RESTful API endpoint is created at:

    /apis/<spec:group>/<spec:version>/<scope>/*/<names-plural>/...

    For example, using the example file, the following endpoint is created:

    /apis/stable.example.com/v1/namespaces/*/crontabs/...

    You can now use this endpoint URL to create and manage CRs. The object Kind is based on the spec.kind field of the CRD object you created.