工作中即将开始写operator,先提前学习一下相关的知识
目前我们的kubernetes集群版本为1.15.0,故参考文档为官方文档《Extend the Kubernetes API with CustomResourceDefinitions》
创建一个CustomResourceDefinition
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
versions:
- name: v1
served: true
storage: true
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
preserveUnknownFields: false
validation:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
cronSpec:
type: string
image:
type: string
replicas:
type: integer
customresourcedefinition.apiextensions.k8s.io/crontabs.stable.example.com created
crontabs.stable.example.com 2020-01-08T07:49:53Z
创建自定义对象
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
name: my-new-cron-object
spec:
cronSpec: "* * * * */5"
image: my-awesome-cron-image
NAME AGE
my-new-cron-object 28s
删除自定义对象
删除CustomResourceDefinition时,服务器将卸载RESTful API端点并删除其中存储的所有自定义对象
Error from server (NotFound): Unable to list "stable.example.com/v1, Resource=crontabs": the server could not find the requested resource (get crontabs.stable.example.com)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)