注解也是 key-value.

  • 注解可以容纳更多信息
  • 主要给工具使用
  • 想 Kubernetes 引入新特性会使用注解 (不稳定时)

3.6.1 查找对象的注解

查看注解:

  • annotations

image.png

注解不超过 256KB.

3.6.2 添加和修改注解

添加注解:

  1. $ kubectl annotate pod hello-pod abc="def"
  2. pod/hello-pod annotated

查看注解:

  1. $ kubectl describe pod hello-pod
  2. Name: hello-pod
  3. Namespace: default
  4. Priority: 0
  5. Node: minikube/192.168.99.100
  6. Start Time: Wed, 24 Mar 2021 10:38:47 +0800
  7. Labels: creation_method=manual
  8. Annotations: abc: def # ------------------ 这里
  9. Status: Running
  10. IP: 172.17.0.7
  11. IPs:
  12. IP: 172.17.0.7
  13. Containers:
  14. test-study-k8s:
  15. Container ID: docker://56271eb675225daa0f7ba39dc6613a06bcf4f545c7c096ee28e02aa609d1558c
  16. Image: jdxj/study_kubernetes:v0.1.0
  17. Image ID: docker-pullable://jdxj/study_kubernetes@sha256:91be05eac3742a5cd670526017c8a8a54705ed002a137e8b7fb0f553177abaec
  18. Port: 8080/TCP
  19. Host Port: 0/TCP
  20. State: Running
  21. Started: Wed, 24 Mar 2021 10:39:01 +0800
  22. Ready: True
  23. Restart Count: 0
  24. Environment: <none>
  25. Mounts:
  26. /var/run/secrets/kubernetes.io/serviceaccount from default-token-vvp8b (ro)
  27. Conditions:
  28. Type Status
  29. Initialized True
  30. Ready True
  31. ContainersReady True
  32. PodScheduled True
  33. Volumes:
  34. default-token-vvp8b:
  35. Type: Secret (a volume populated by a Secret)
  36. SecretName: default-token-vvp8b
  37. Optional: false
  38. QoS Class: BestEffort
  39. Node-Selectors: <none>
  40. Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
  41. node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
  42. Events: <none>

应该使用前缀来避免命名冲突:

  • abc/def="def"