了解 pod 标签与注解

Understanding pod labels vs annotations

我正在尝试了解 pods 和注释之间的区别。

标准文档说注释捕获“非识别信息”。 在标签上时,可以应用选择器。标签用于组织 kubernetes 集群中的对象。

如果是这种情况,那么为什么 istio 使用 pod 注释而不是标签来进行各种不同的设置:https://istio.io/latest/docs/reference/config/annotations/

标签不是很好的方法吗?

如果 istio 开发人员选择使用注释,只是想了解注释提供了哪些优势。

作为对 Burak 答案的扩展,

Kubernetes labels and annotations are both ways of adding metadata to Kubernetes objects. The similarities end there, however. Kubernetes labels allow you to identify, select and operate on Kubernetes objects. Annotations are non-identifying metadata and do none of these things.

标签主要用于附加资源,如 POD、副本集等。它还用于路由流量和路由部署到服务等。

标签正在存储在 ETCD 数据库中,因此您可以使用它进行搜索。

注释主要用于存储元数据和config-if任何。

元数据,如:所有者详细信息、最后一次掌舵释放(如果使用头盔)、侧车注入

您可以在标签中存储所有者详细信息,K8s 使用 标签 将流量从 服务路由到部署 并且标签应该是 相同 在两种资源(部署和服务)上路由流量。

在这种情况下,您将如何匹配资源标签?在所有部署和服务中使用相同的服务所有者名称?当您 运行 多个由 diff 团队和服务所有者管理的分布式服务时。

如果您注意到 istio 的某些注释仅用于存储元数据,例如:install.operator.istio.io/chart-ownerinstall.operator.istio.io/owner-generation

阅读更多信息:https://istio.io/latest/docs/reference/config/annotations/

您还应该检查一次 label and annotation.

的语法