Kubernetes kubectl annotate 命令详解

kubectl annotate

更新一个或多个资源的Annotations信息。

  • Annotations由key/value组成。
  • Annotations的目的是存储辅助数据,特别是通过工具和系统扩展操作的数据。
  • 如果–overwrite为true,现有的annotations可以被覆盖,否则试图覆盖annotations将会报错。
  • 如果设置了–resource-version,则更新将使用此resource version,否则将使用原有的resource version。

有效资源类型包括:

  • all
  • certificatesigningrequests (aka \’csr\’)
  • clusterrolebindings
  • clusterroles
  • clusters (valid only for federation apiservers)
  • componentstatuses (aka \’cs\’)
  • configmaps (aka \’cm\’)
  • controllerrevisions
  • cronjobs
  • daemonsets (aka \’ds\’)
  • deployments (aka \’deploy\’)
  • endpoints (aka \’ep\’)
  • events (aka \’ev\’)
  • horizontalpodautoscalers (aka \’hpa\’)
  • ingresses (aka \’ing\’)
  • jobs
  • limitranges (aka \’limits\’)
  • namespaces (aka \’ns\’)
  • networkpolicies (aka \’netpol\’)
  • nodes (aka \’no\’)
  • persistentvolumeclaims (aka \’pvc\’)
  • persistentvolumes (aka \’pv\’)
  • poddisruptionbudgets (aka \’pdb\’)
  • podpreset
  • pods (aka \’po\’)
  • podsecuritypolicies (aka \’psp\’)
  • podtemplates
  • replicasets (aka \’rs\’)
  • replicationcontrollers (aka \’rc\’)
  • resourcequotas (aka \’quota\’)
  • rolebindings
  • roles
  • secrets
  • serviceaccounts (aka \’sa\’)
  • services (aka \’svc\’)
  • statefulsets
  • storageclasses
  • thirdpartyresources

语法

$ annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]

示例

更新Pod“foo”,设置annotation “description”的value “my frontend”,如果同一个annotation多次设置,则只使用最后设置的value值。

kubectl annotate pods foo description=\'my frontend\'

根据“pod.json”中的type和name更新pod的annotation

kubectl annotate -f pod.json description=\'my frontend\'

更新Pod\”foo\”,设置annotation“description”的value“my frontend running nginx”,覆盖现有的值。

kubectl annotate --overwrite pods foo description=\'my frontend running nginx\'

更新 namespace中的所有pod

kubectl annotate pods --all description=\'my frontend running nginx\'

只有当resource-version为1时,才更新pod \’ foo \’。

kubectl annotate pods foo description=\'my frontend running nginx\' --resource-version=1

通过删除名为“description”的annotations来更新pod \’ foo \’。#不需要- overwrite flag。

kubectl annotate pods foo description-

发表评论

您的电子邮箱地址不会被公开。

Shopping Cart