3

k8s crd(custom resources definitions)

 3 years ago
source link: https://blog.csdn.net/oqqYuan1234567890/article/details/89264659
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

k8s crd(custom resources definitions)

original.png
皿小草 2019-04-12 23:35:03 1354
分类专栏: golang

关于CRD(custom resources definition)的concept,可以参考官方文档:https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#custom-resources
其中有提到两个比较重要的概念:声明式(declarative)API和命令式(imperative)API, kubernetes大部分资源调度都依赖于声明式API,其中涉及到调度的方式,Level trigger(水平触发)和边缘触发(edge trigger),有信号系统基础的人应该会比较熟悉,水平触发与值有关,边缘触发与跳变有关。csdn有一篇关于level trigger和edge trigger的文章https://blog.csdn.net/qq_34463875/article/details/78390111

与CRD对应的是Aggregated API(聚合API),Aggregated API需要一定的开发能力,并遵循相应设计规范,参考https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation/

使用CRD或者Aggregated API的场景

Use a custom resource (CRD or Aggregated API) if most of the following apply:

You want to use Kubernetes client libraries and CLIs to create and update the new resource.
You want top-level support from kubectl (for example: kubectl get my-object object-name).
You want to build new automation that watches for updates on the new object, and then CRUD other objects, or vice versa.
You want to write automation that handles updates to the object.
You want to use Kubernetes API conventions like .spec, .status, and .metadata.
You want the object to be an abstraction over a collection of controlled resources, or a summarization of other resources

CRD的开发难度较低,可以满足我目前的要求,官网相关的doc https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/

与之对应的是两个项目

https://github.com/kubernetes/sample-controller

sample-controller定义的数据结构位于https://github.com/kubernetes/code-generator/blob/master/_examples/apiserver/apis/example/types.go

https://github.com/kubernetes/code-generator

自定义数据结构生成k8s api代码需要用到的工具,这个工具的使用教程参考blog:https://github.com/kubernetes/code-generator, 只需要调用code-generator,就可以生成client/informer/lister, 通过编译对应的客户端(也可以直接用kubectl操作,CRD原生支持kubectl)就可以操作自定义CRD。

aggregated api熟悉以及CRD结合已有资源实现一些调度任务。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK