CRD 只管理 Pod 吗?

huangapple go评论74阅读模式
英文:

Do CRDs only ever manage pods?

问题

CRDs一起工作了一段时间。最近,我的一个同事声称自定义资源最终只管理Pod。这是真的吗?您可以为服务或配置映射创建CRD吗?

英文:

Worked with CRDs a bit so far. Recently a colleague of mine claimed that custom resources only ever manage pods in the end. Is this true? Can you do CRDs for services or config maps as well?

答案1

得分: 3

自定义资源定义不管理任何内容。它仅仅是为特定的API组、版本和种类(如你在Kubernetes清单的顶部看到的)提供一个定义,这不是标准Kubernetes API的一部分。如果你已安装了一个CRD,那么你可以使用 kubectl get customtypename 和类似的命令,但创建这些对象不会导致任何实际操作。

典型operator模式的另一部分是Kubernetes控制器。这是一个通常在集群内运行的程序,它使用Kubernetes API来执行某些操作。

控制器可以读取和写入_任何_ Kubernetes资源;它不限于Pods。例如,你可以响应自定义资源的更改而创建一个ConfigMap,或者在你的自定义资源中引用一个ConfigMap,并结合这两个数据来调用某个外部API。

英文:

A custom resource definition doesn't manage anything. It is just a definition for some specific API group, version, and kind (as you see at the top of a Kubernetes manifest) that is not part of the standard Kubernetes API. If you've installed a CRD then you can kubectl get customtypename and run similar commands, but nothing actually happens as a result of creating one of these objects.

The other part of the typical operator pattern is a Kubernetes controller. This is a program, that usually runs inside the cluster, that uses the Kubernetes API to take some action.

A controller can read and write any Kubernetes resource; it is not limited to Pods. You could, for example, create a ConfigMap in response to a custom resource changing, or reference a ConfigMap in your custom resource and combine those two data to invoke some external API.

答案2

得分: 1

CRD 用于创建、存储和公开 Kubernetes API 对象,当它们也可以用于其他目的。CRD 可用于创建用于服务和配置的自定义资源。例如,为服务创建一个 CRD,

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: service-crd
spec:
  group: mycompany.com
  version: v1
  scope: Namespaced
  names:
    kind: Service
    plural: services

上述 YAML 将指定一个名为 service-crd 的 CRD,可用于与 mycompany.com 一起创建和管理。有了这个自定义资源定义,您可以使用 API 来创建、更新和删除服务。

可以使用 CRD 将配置映射到自定义对象中。而 ConfigMap 更适合在 Kubernetes 中存储非机密信息。如果需要存储更复杂的数据结构,请使用 CRD。

获取更多信息,请参阅 Dawid Ziolkowski 的博客2

英文:

CRDs are used to create, store and expose Kubernetes API objects, when they can be used for other purposes also. CRDs can be used to create custom resources for services and configs also.For example a CRD for a service,

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: service-crd
spec:
  group: mycompany.com
  version: v1
  scope: Namespaced
  names:
    kind: Service
    plural: services

Above yaml will specify a CRD called service-crd that can be used to create and manage with the mycompany.com. With this custom resource definition in place, you can use the API to create, update and delete services.

It is possible to mount a config map into a custom object using CRDs. Whereas configmaps are better suited for storing non- confidential information in kubernetes. Use a CRD if you need to store more complex data structures.

For more information follow a blog by Dawid Ziolkowski.

huangapple
  • 本文由 发表于 2023年2月27日 17:58:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578981.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定