To create Custom Resource (CR) objects, cluster administrators must first create a Custom Resource Definition (CRD).
-
Access to an {product-title} cluster with
cluster-admin
user privileges.
To create a CRD:
-
Create a YAML file that contains the following field types:
Example YAML file for a CRDapiVersion: 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)
-
Use the
apiextensions.k8s.io/v1beta1
API. -
Specify a name for the definition. This must be in the <plural-name>.<group> format using the values from the
group
andplural
fields. -
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
orScheduledJob
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. -
Specify a version name to be used in the URL. Each API Group can exist in multiple versions. For example:
v1alpha
,v1beta
,v1
. -
Specify whether the custom objects are available to a project (
Namespaced
) or all projects in the cluster (Cluster
). -
Specify the plural name to use in the URL. The
plural
field is the same as a resource in an API URL. -
Specify a singular name to use as an alias on the CLI and for display.
-
Specify the kind of objects that can be created. The type can be in CamelCase.
-
Specify a shorter string to match your resource on the CLI.
NoteBy default, a CRD is cluster-scoped and available to all projects.
-
-
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 thespec.kind
field of the CRD object you created.