实战生产环境:最新K8s Annotations详解

本篇文章,所使用的任何镜像我都会发一个网盘链接,供大家下载学习!

yaml 请到我的github上下载学习!

github:https://github.com/heyangguang

有任何问题可以直接联系我的Email:[email protected]

Annotations官网

https://kubernetes.io/docs/co...

Annotations介绍

顾名思义,就是注释的意思。有两个功能:

  • 注释性信息,不影响调度
  • 工具和库等客户端可以检索Annotation数据

查看Annotations

[root@master01 ~]# kubectl describe nodes node01
Name:               node01
Roles:              work
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=node01
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/work=
Annotations:        kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    projectcalico.org/IPv4Address: 172.20.102.221/20
                    projectcalico.org/IPv4IPIPTunnelAddr: 192.168.196.128
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Sat, 10 Aug 2019 12:42:08 +0800
Taints:             <none>
Unschedulable:      false
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Sat, 10 Aug 2019 12:42:54 +0800   Sat, 10 Aug 2019 12:42:54 +0800   CalicoIsUp                   Calico is running on this node
  MemoryPressure       False   Sun, 11 Aug 2019 00:01:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Sun, 11 Aug 2019 00:01:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Sun, 11 Aug 2019 00:01:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Sun, 11 Aug 2019 00:01:21 +0800   Sat, 10 Aug 2019 12:42:28 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  172.20.102.221
  Hostname:    node01
Capacity:
 cpu:                2
 ephemeral-storage:  41147472Ki
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             8009180Ki
 pods:               110
Allocatable:
 cpu:                2
 ephemeral-storage:  37921510133
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             7906780Ki
 pods:               110
System Info:
 Machine ID:                 20190711105006363114529432776998
 System UUID:                7ABFD479-B967-4A73-9D8A-5E0993B76A2D
 Boot ID:                    f61e9e10-1864-4610-a98c-c8c9924bd8e9
 Kernel Version:             3.10.0-957.21.3.el7.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://18.6.2
 Kubelet Version:            v1.15.2
 Kube-Proxy Version:         v1.15.2
PodCIDR:                     192.168.1.0/24
Non-terminated Pods:         (3 in total)
  Namespace                  Name                 CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                 ------------  ----------  ---------------  -------------  ---
  default                    label-demo           0 (0%)        0 (0%)      0 (0%)           0 (0%)         16m
  kube-system                calico-node-nsjfq    250m (12%)    0 (0%)      0 (0%)           0 (0%)         11h
  kube-system                kube-proxy-dd78n     0 (0%)        0 (0%)      0 (0%)           0 (0%)         11h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                250m (12%)  0 (0%)
  memory             0 (0%)      0 (0%)
  ephemeral-storage  0 (0%)      0 (0%)
Events:              <none>

创建Annotations

1、命令行创建

[root@master01 ~]# kubectl annotate nodes node01 test_people=heyang
node/node01 annotated
[root@master01 ~]# kubectl describe nodes node01
Name:               node01
Roles:              work
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=node01
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/work=
Annotations:        kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    projectcalico.org/IPv4Address: 172.20.102.221/20
                    projectcalico.org/IPv4IPIPTunnelAddr: 192.168.196.128
                    test_people: heyang
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Sat, 10 Aug 2019 12:42:08 +0800
Taints:             <none>
Unschedulable:      false
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Sat, 10 Aug 2019 12:42:54 +0800   Sat, 10 Aug 2019 12:42:54 +0800   CalicoIsUp                   Calico is running on this node
  MemoryPressure       False   Sun, 11 Aug 2019 00:03:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Sun, 11 Aug 2019 00:03:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Sun, 11 Aug 2019 00:03:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Sun, 11 Aug 2019 00:03:21 +0800   Sat, 10 Aug 2019 12:42:28 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  172.20.102.221
  Hostname:    node01
Capacity:
 cpu:                2
 ephemeral-storage:  41147472Ki
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             8009180Ki
 pods:               110
Allocatable:
 cpu:                2
 ephemeral-storage:  37921510133
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             7906780Ki
 pods:               110
System Info:
 Machine ID:                 20190711105006363114529432776998
 System UUID:                7ABFD479-B967-4A73-9D8A-5E0993B76A2D
 Boot ID:                    f61e9e10-1864-4610-a98c-c8c9924bd8e9
 Kernel Version:             3.10.0-957.21.3.el7.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://18.6.2
 Kubelet Version:            v1.15.2
 Kube-Proxy Version:         v1.15.2
PodCIDR:                     192.168.1.0/24
Non-terminated Pods:         (3 in total)
  Namespace                  Name                 CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                 ------------  ----------  ---------------  -------------  ---
  default                    label-demo           0 (0%)        0 (0%)      0 (0%)           0 (0%)         19m
  kube-system                calico-node-nsjfq    250m (12%)    0 (0%)      0 (0%)           0 (0%)         11h
  kube-system                kube-proxy-dd78n     0 (0%)        0 (0%)      0 (0%)           0 (0%)         11h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                250m (12%)  0 (0%)
  memory             0 (0%)      0 (0%)
  ephemeral-storage  0 (0%)      0 (0%)
Events:              <none>

2、yaml创建

[root@master01 ~]# touch pod-annotations.yaml
[root@master01 ~]# vim pod-annotations.yaml
[root@master01 ~]# cat pod-annotations.yaml
apiVersion: v1
kind: Pod
metadata:
  name: annotations-demo
  annotations:
    imageregistry: "https://hub.docker.com/"
spec:
  containers:
  - name: nginx
    image: nginx:1.7.9
    ports:
    - containerPort: 80
[root@master01 ~]# kubectl apply -f pod-annotations.yaml
pod/annotations-demo created
[root@master01 ~]# kubectl get pods
NAME               READY   STATUS              RESTARTS   AGE
annotations-demo   0/1     ContainerCreating   0          7s
label-demo         1/1     Running             0          21m
[root@master01 ~]# kubectl describe pods annotations-demo
Name:         annotations-demo
Namespace:    default
Priority:     0
Node:         node02/172.20.102.220
Start Time:   Sun, 11 Aug 2019 00:05:46 +0800
Labels:       <none>
Annotations:  cni.projectcalico.org/podIP: 192.168.140.65/32
              imageregistry: https://hub.docker.com/
              kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"imageregistry":"https://hub.docker.com/"},"name":"annotations-demo","namespace...
Status:       Running
IP:           192.168.140.65
Containers:
  nginx:
    Container ID:   docker://8fbbd1b6a180a55442301cc7113da92ddb74c34b13db670b27944137f13708fc
    Image:          nginx:1.7.9
    Image ID:       docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sun, 11 Aug 2019 00:05:54 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-zh752 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-zh752:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-zh752
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  19s   default-scheduler  Successfully assigned default/annotations-demo to node02
  Normal  Pulling    18s   kubelet, node02    Pulling image "nginx:1.7.9"
  Normal  Pulled     11s   kubelet, node02    Successfully pulled image "nginx:1.7.9"
  Normal  Created    11s   kubelet, node02    Created container nginx
  Normal  Started    11s   kubelet, node02    Started container nginx

删除Annotations

[root@master01 ~]# kubectl annotate nodes node01 test_people-
node/node01 annotated
[root@master01 ~]# kubectl describe nodes node01
Name:               node01
Roles:              work
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=node01
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/work=
Annotations:        kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    projectcalico.org/IPv4Address: 172.20.102.221/20
                    projectcalico.org/IPv4IPIPTunnelAddr: 192.168.196.128
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Sat, 10 Aug 2019 12:42:08 +0800
Taints:             <none>
Unschedulable:      false
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  NetworkUnavailable   False   Sat, 10 Aug 2019 12:42:54 +0800   Sat, 10 Aug 2019 12:42:54 +0800   CalicoIsUp                   Calico is running on this node
  MemoryPressure       False   Sun, 11 Aug 2019 00:07:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Sun, 11 Aug 2019 00:07:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure          False   Sun, 11 Aug 2019 00:07:21 +0800   Sat, 10 Aug 2019 12:42:08 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready                True    Sun, 11 Aug 2019 00:07:21 +0800   Sat, 10 Aug 2019 12:42:28 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  172.20.102.221
  Hostname:    node01
Capacity:
 cpu:                2
 ephemeral-storage:  41147472Ki
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             8009180Ki
 pods:               110
Allocatable:
 cpu:                2
 ephemeral-storage:  37921510133
 hugepages-1Gi:      0
 hugepages-2Mi:      0
 memory:             7906780Ki
 pods:               110
System Info:
 Machine ID:                 20190711105006363114529432776998
 System UUID:                7ABFD479-B967-4A73-9D8A-5E0993B76A2D
 Boot ID:                    f61e9e10-1864-4610-a98c-c8c9924bd8e9
 Kernel Version:             3.10.0-957.21.3.el7.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://18.6.2
 Kubelet Version:            v1.15.2
 Kube-Proxy Version:         v1.15.2
PodCIDR:                     192.168.1.0/24
Non-terminated Pods:         (3 in total)
  Namespace                  Name                 CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                 ------------  ----------  ---------------  -------------  ---
  default                    label-demo           0 (0%)        0 (0%)      0 (0%)           0 (0%)         23m
  kube-system                calico-node-nsjfq    250m (12%)    0 (0%)      0 (0%)           0 (0%)         11h
  kube-system                kube-proxy-dd78n     0 (0%)        0 (0%)      0 (0%)           0 (0%)         11h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                250m (12%)  0 (0%)
  memory             0 (0%)      0 (0%)
  ephemeral-storage  0 (0%)      0 (0%)
Events:              <none>

相关推荐