To create a CRD, open a YAML file and enter the fields in the following example.
Example YAML file for a Custom Resource Definition
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 , vibeta , 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 be used in the URL. The plural field is the same as a resource in an API URL. |
7 |
Specify a singular name to be used 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. |
|
By default, a custom resource definition is cluster-scoped and available to all projects.
|
After configuring the definition file, create the 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 would be created:
/apis/stable.example.com/v1/namespaces/*/crontabs/...
This endpoint URL can then be used to create and manage custom objects.
The kind of object is based on the spec.kind
field of the
Custom Resource Definition object you created.