美文网首页
Annotation

Annotation

作者: YoungJadeStone | 来源:发表于2021-01-02 06:48 被阅读0次

在其他文章里我们提到,k8s里面有一些group & manage resources的方式,比如Label,Namespace。但有时候我们还会听到类似的一个概念,叫Annotation。

它和Label有点类似,但是不能group & manage resources,我们来简单聊聊Annotation。

1. Annotation Intro

官方doc说:

You can use Kubernetes annotations to attach arbitrary non-identifying metadata to objects. Clients such as tools and libraries can retrieve this metadata.

和Label类似的是:它也是key-value pair,也可以在resource object创建的时候指定,也可以给已经存在的object添加或修改Annotation。

Annotations的形式如下(和Label几乎一样):

"metadata": {
  "annotations": {
    "key1" : "value1",
    "key2" : "value2"
  }
}

但和Label不同的是:

  • Annotation可以相对比较长(relatively large blobs of data),只需要256KB之内。
  • Annotation没有对应的selector,也就是说我们不能根据Annotation来filter object。

有什么使用Annotation的例子吗?我们可以用它来描述contributor,creation time之类的。

2. Commands

想查看Annotation,可以通过显示Pod(或其他resource object)的yaml:

kubectl get po <pod-name> -o yaml

或者通过:

kubectl describe pod <pod-name>

给Pod添加Annotation:

kubectl annotate po <pod-name> <annotation_key>=<annotation_value>

Reference:

  • Kubernetes in Action

相关文章

网友评论

      本文标题:Annotation

      本文链接:https://www.haomeiwen.com/subject/vtosoktx.html