CustomResourceDefinition (CRD)¶
In Kubernetes, all objects are abstracted as resources, such as Pod, Deployment, Service, Volume, etc. are the default resources provided by Kubernetes. This provides important support for our daily operation and maintenance and management work, but in some special cases, the existing preset resources cannot meet the needs of the business. Therefore, we hope to expand the capabilities of the Kubernetes API, and CustomResourceDefinition (CRD) was born based on this requirement.
The container management module supports interface-based management of custom resources, and its main features are as follows:
- Obtain the list and detailed information of custom resources under the cluster
- Create custom resources based on YAML
- Create a custom resource example CR (Custom Resource) based on YAML
- Delete custom resources
Prerequisites¶
-
Integrated the Kubernetes cluster or created Kubernetes, and you can access the cluster UI interface.
-
Created a namespace, user, and authorized the user as
Cluster Admin
For details, refer to Namespace Authorization.
Create CRD via YAML¶
-
Click a cluster name to enter Cluster Details .
-
In the left navigation bar, click Custom Resource , and click the YAML Create button in the upper right corner.
-
On the Create with YAML page, fill in the YAML statement and click OK .
-
Return to the custom resource list page, and you can view the custom resource named
crontabs.stable.example.com
just created.
Custom resource example:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
cronSpec:
type: string
image:
type: string
replicas:
type: integer
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
Create a custom resource example via YAML¶
-
Click a cluster name to enter Cluster Details .
-
In the left navigation bar, click Custom Resource , and click the YAML Create button in the upper right corner.
-
Click the custom resource named
crontabs.stable.example.com
, enter the details, and click the YAML Create button in the upper right corner. -
On the Create with YAML page, fill in the YAML statement and click OK .
-
Return to the details page of
crontabs.stable.example.com
, and you can view the custom resource named my-new-cron-object just created.
CR Example:
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
name: my-new-cron-object
spec:
cronSpec: "* * * * */5"
image: my-awesome-cron-image