Reference official
https://kubernetes.io/zh/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/
This example is the simplest HelloWorld example. It does not involve coding content, but can be used to understand how CRD works
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
# The name must match the spec field below, and the format is' < plural form of name >< Group name > '
name: crontabs.stable.example.com
spec:
# Group name for rest API: / APIs / < group > / < version >
group: stable.example.com
# List the supported versions of this customresourcedefinition
versions:
- name: v1
# Each version can be enabled or disabled independently through the served flag
served: true
# One and only one version must be marked as a stored version
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
cronSpec:
type: string
image:
type: string
replicas:
type: integer
# It can be named or cluster
scope: Namespaced
names:
# Plural of name for URL: / APIs / < group > / < version > / < plural of name >
plural: crontabs
# The singular form of the name as an alias when used on the command line and when displayed
singular: crontab
# Kind is usually a singular form of camel cased. Your resource list will use this form.
kind: CronTab
# Shortnames allows you to match resources with shorter strings on the command line
shortNames:
- ct
After the above steps, we will get a new service endpoint in
/apis/stable.example.com/v1/namespaces/*/crontabs/...
Create crontab custom object
my-crontab.yaml
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
name: my-new-cron-object
spec:
cronSpec: "*/60 * * * *"
image: my-awesome-cron-image