Custom resources
自定义资源(Custom Resources):是对现有Kubernetes API的一种扩展。当你创建一个CR后,你可以使用kubectl命令,像操作Pod一样操作自定义资源。
Custom controllers
custom resources只是定义了如何存储和查询结构化数据。如果要想CR真正的被使用起来,还需要定义Custom controllers,定义Custom controllers之后才可以真正的提供描述性接口。
描述性接口允许你只定义资源所需要达到的理想状态,控制器会为了达到理想状态进行一系列的操作,并维护这个理想状态。`Operatorr pattern可以使Custom resourcs和Custom controllers`完美结合。
如何添加custom resources
k8s提供了两种方法添加自定义资源到kubernetes集群。
- CRD:CustomResourceDefinitions:简单不需要编程
- API Aggregation:功能强大需要编程
两者使用难度对比:
| CRDs | Aggregated API |
|---|---|
| Do not require programming. Users can choose any language for a CRD controller. | Requires programming in Go and building binary and image. |
| No additional service to run; CRDs are handled by API server. | An additional service to create and that could fail. |
| No ongoing support once the CRD is created. Any bug fixes are picked up as part of normal Kubernetes Master upgrades. | May need to periodically pickup bug fixes from upstream and rebuild and update the Aggregated API server. |
| No need to handle multiple versions of your API; for example, when you control the client for this resource, you can upgrade it in sync with the API. | You need to handle multiple versions of your API; for example, when developing an extension to share with the world. |
Ref:
1.https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/