본문 바로가기

Kubernetes

[Kubernetes] Annotation

반응형

Annotation

 - Label과 동일하게 key-value를 통해 리소스의 특성을 기록

 - Kubernetes 에게 특정 정보 전달할 용도로 사용

  . 예를 들어 Deployment의 rolling update 정보 기록

     annotations:

         kubernetes.io/change-cause: version 1.15

 - 관리를 위해 필요한 정보를 기록할 용도로 사용

  . 릴리즈, 로깅, 모니터링에 필요한 저보들을 기록

     annotations:

         builder: "test (tset@gmail.com)"

         buildDate: "20221217"

         imageRegistry: https://hub.docker.com/ 

 

annotation.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pod-annotation
  annotations:
    builder: "seongmi Lee (seongmi.lee@gmail.com)"
    buildDate: "20210502"
    imageRegistry: https://hub.docker.com/
spec:
  containers:
  - name: nginx
    image: nginx:1.14
    ports:
    - containerPort: 80

  

annotation.yaml 실행 후 describe에서 annotations 내용 확인

# kubectl create -f annotation.yaml
pod/pod-annotation created

# kubectl get pods
NAME             READY   STATUS    RESTARTS   AGE
pod-annotation   1/1     Running   0          3s

# kubectl describe pod pod-annotation 
Name:             pod-annotation
Namespace:        default
Priority:         0
Service Account:  default
Node:             node2.example.com/10.100.0.102
Start Time:       Sat, 17 Dec 2022 15:52:21 +0900
Labels:           <none>
Annotations:      buildDate: 20210502
                  builder: seongmi Lee (seongmi.lee@gmail.com)
                  imageRegistry: https://hub.docker.com/
Status:           Running
IP:               10.44.0.1
IPs:
  IP:  10.44.0.1
Containers:
  nginx:
    Container ID:   containerd://899b4fbb57e31f9b48716bd6fa0802c8241a8214fd5149efc5c39433824059c1
    Image:          nginx:1.14
    Image ID:       docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sat, 17 Dec 2022 15:52:23 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-cvplf (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  kube-api-access-cvplf:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  12s   default-scheduler  Successfully assigned default/pod-annotation to node2.example.com
  Normal  Pulled     12s   kubelet            Container image "nginx:1.14" already present on machine
  Normal  Created    11s   kubelet            Created container nginx
  Normal  Started    11s   kubelet            Started container nginx

 

 

 

[참고]

- https://www.youtube.com/watch?v=Q5UBx7MAQLw

반응형