"metadata": { "labels": { "key1" : "value1", "key2" : "value2" } }
Annotation
으로 기록해야 합니다.- "release" : "stable", "release" : "canary" - "environment" : "dev", "environment" : "qa", "environment" : "production" - "tier" : "frontend", "tier" : "backend", "tier" : "cache" - "partition" : "customerA", "partition" : "customerB" - "track" : "daily", "track" : "weekly"
apiVersion: v1 kind: Pod metadata: name: nasa-pod-label labels: env: dev tier: frontend spec: containers: - image: nginx:latest name: nasa ports: - containerPort: 8080 protocol: TCP
[root@nasa-master nasa]# kubectl apply -f nasa-lebel.yml pod/nasa-pod-label created [root@nasa-master nasa]# kubectl get po NAME READY STATUS RESTARTS AGE nasa-pod-label 1/1 Running 0 7s
[root@nasa-master nasa]# kubectl get pod --show-labels NAME READY STATUS RESTARTS AGE LABELS nasa-pod-label 1/1 Running 0 68s env=dev,tier=frontend
[root@nasa-master nasa]# kubectl describe pods nasa-pod-label Name: nasa-pod-label Namespace: default Priority: 0 Node: nasa-node3/10.146.0.9 Start Time: Wed, 16 Sep 2020 08:11:15 +0000 Labels: env=dev tier=frontend Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"env":"d ev","tier":"frontend"},"name":"nasa-pod-label","namespace":... ...
-L 옵션
을 사용해 특정 label을 지정하여 표시 할 수 있습니다.[root@nasa-master nasa]# kubectl get pods -L env,tier NAME READY STATUS RESTARTS AGE ENV TIER nasa-pod-label 1/1 Running 0 15m dev frontend
[root@nasa-master nasa]# kubectl label pods nasa-pod-label env=test error: 'env' already has a value (dev), and --overwrite is false
-overwrite
옵션을 추가로 정의하면 됩니다[root@nasa-master nasa]# kubectl label pods nasa-pod-label env=test --overwrite pod/nasa-pod-label labeled [root@nasa-master nasa]# kubectl get pods --show-labels NAME READY STATUS RESTARTS AGE LABELS nasa-pod-label 1/1 Running 0 20m env=test,tier=frontend
env=test
Value이 변경 됨을 확인!## tierKey가 포함된 Label [root@nasa-master nasa]# kubectl get pods --show-labels -l tier NAME READY STATUS RESTARTS AGE LABELS nasa-pod-label 1/1 Running 0 26m env=test,tier=frontend ## tierKey를 제외한 Label [root@nasa-master nasa]# kubectl get pods --show-labels -l '!tier' NAME READY STATUS RESTARTS AGE LABELS nasa-pod 1/1 Running 0 101m env=dev ## envKey에 testValue이 있는 Label [root@nasa-master nasa]# kubectl get pods --show-labels -l env=test NAME READY STATUS RESTARTS AGE LABELS nasa-pod-label 1/1 Running 0 28m env=test,tier=frontend ## envKey는 있지만 devValue은 제외한 Label [root@nasa-master nasa]# kubectl get pods --show-labels -l env!=dev NAME READY STATUS RESTARTS AGE LABELS nasa-pod-label 1/1 Running 0 29m env=test,tier=frontend
## envKey에 debug나 devValue이 포함된 Label [root@nasa-master nasa]# kubectl get pods --show-labels -l 'env in (test,dev)' NAME READY STATUS RESTARTS AGE LABELS nasa-pod-label 1/1 Running 0 31m env=test,tier=frontend ## tierKey에 frontendValue은 제외한 Label [root@nasa-master nasa]# kubectl get pods --show-labels -l 'tier notin (frontend)' NAME READY STATUS RESTARTS AGE LABELS nasa-pod 1/1 Running 0 103m env=dev
- 필드
- 이미지 정보(타임 스탬프, 릴리즈 ID, 빌드 버전, git 브랜치, 이미지 해시, 레지스트리 주소 등)
- 로깅, 모니터링 정보
- 디버깅에 필요한 정보(이름,버전,빌드정보)
- 책임자 연락처
- 사용자 지시 사항
apiVersion: v1 kind: Pod metadata: name: annotations-nasa annotations: imageregistry: "https://hub.docker.com/" spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
[root@nasa-master nasa]# kubectl apply -f ano.yml pod/annotations-nasa created [root@nasa-master nasa]# [root@nasa-master nasa]# kubectl get po NAME READY STATUS RESTARTS AGE annotations-nasa 1/1 Running 0 5s nasa-pod-label 1/1 Running 0 38m
describe
옵션으로 확인이 가능합니다![root@nasa-master nasa]# kubectl describe pods annot Name: annotations-nasa Namespace: default Priority: 0 Node: nasa-node3/10.146.0.9 Start Time: Wed, 16 Sep 2020 08:49:37 +0000 Labels: <none> Annotations: imageregistry: https://hub.docker.com/ <<<######>>> kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"imageregistry":"htt ps://hub.docker.com/"},"name":"annotations-nasa","namespace... Status: Running IP: 10.32.0.3 ...
annotate
명령을 이용해 변경도 가능합니다![root@nasa-master nasa]# kubectl annotate pods annotations-nasa mynameis="John Smith" pod/annotations-nasa annotated [root@nasa-master nasa]# kubectl describe pods annot Name: annotations-nasa Namespace: default Priority: 0 Node: nasa-node3/10.146.0.9 Start Time: Wed, 16 Sep 2020 08:49:37 +0000 Labels: <none> Annotations: imageregistry: https://hub.docker.com/ kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{"imageregistry":"htt ps://hub.docker.com/"},"name":"annotations-nasa","namespace... mynameis: John Smith <<<<----#######
'전혀'
없습니다라고 하고 있습니다.kube-
로 시작하는 NameSpace는 이미 Kubernetes 시스템 NameSpace로 예약되어있으므로 사용하지 않습니다.[root@nasa-master nasa]# kubectl get namespaces NAME STATUS AGE default Active 23d kube-node-lease Active 23d kube-public Active 23d kube-system Active 23d
default
: Object 생성 시 따로 지정하지 않으면 default NameSpace를 사용하게 되어있습니다. kube-system
: Kubernetes 시스템에서 생성한 Object를 위한 NameSpace kube-public
: 전체 Cluster에서 공개되어 예약된 NameSpace. 모든 사용자가 읽기 권한으로 접근 가능합니다. kube-node-lease
: Cluster가 스케일링될 때 노드 health check 성능을 향상시Key는 lease Object에 대한 NameSpace [root@nasa-master nasa]# kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-5c98db65d4-8cg79 1/1 Running 2 23d coredns-5c98db65d4-zbvbn 1/1 Running 1 23d etcd-nasa-master 1/1 Running 1 23d kube-apiserver-nasa-master 1/1 Running 1 23d kube-controller-manager-nasa-master 1/1 Running 1 23d kube-proxy-6w9dk 1/1 Running 1 23d kube-proxy-jqks7 1/1 Running 1 23d kube-proxy-kr9sb 1/1 Running 1 23d kube-proxy-lxn6d 1/1 Running 1 23d kube-scheduler-nasa-master 1/1 Running 1 23d kubernetes-dashboard-6b8c96cf8c-g985n 1/1 Running 1 23d weave-net-dd6f2 2/2 Running 3 23d weave-net-k2jc9 2/2 Running 3 23d weave-net-k2tcb 2/2 Running 3 23d weave-net-v7bff 2/2 Running 3 23d
[root@nasa-master nasa]# kubectl create namespace nasa namespace/nasa created [root@nasa-master nasa]# kubectl get namespace nasa NAME STATUS AGE nasa Active 28s
apiVersion: v1 kind: Namespace metadata: name: nasa-namespace
[root@nasa-master nasa]# kubectl apply -f name.yml namespace/nasa-namespace created [root@nasa-master nasa]# [root@nasa-master nasa]# kubectl get namespace nasa-namespace NAME STATUS AGE nasa-namespace Active 19s
[root@nasa-master nasa]# kubectl apply -f nasa.yml -n nasa-namespace pod/nasa-nginx-pod created [root@nasa-master nasa]# kubectl get po -n nasa-namespace NAME READY STATUS RESTARTS AGE nasa-nginx-pod 0/2 ContainerCreating 0 17s
apiVersion: v1 kind: Pod metadata: name: nasa-pod namespace: nasa spec: containers: - image: nginx:latest name: nasa-pod ports: - containerPort: 8080 protocol: TCP
[root@nasa-master nasa]# kubectl apply -f nasaname.yml pod/nasa-pod created [root@nasa-master nasa]# kubectl get po -n nasa NAME READY STATUS RESTARTS AGE nasa-pod 1/1 Running 0 12s
[root@nasa-master nasa]# kubectl delete pod nasa-pod -n nasa pod "nasa-pod" deleted [root@nasa-master nasa]# kubectl get po -n nasa No resources found.
[root@nasa-master nasa]# kubectl get pod -n nasa-namespace NAME READY STATUS RESTARTS AGE nasa-nginx-pod 1/2 CrashLoopBackOff 6 9m57s [root@nasa-master nasa]# [root@nasa-master nasa]# kubectl delete -f name.yml namespace "nasa-namespace" deleted [root@nasa-master nasa]# kubectl get pod -n nasa-namespace No resources found.
[root@nasa-master nasa]# kubectl get pods -l env=test NAME READY STATUS RESTARTS AGE nasa-pod-label 1/1 Running 0 68m [root@nasa-master nasa]# [root@nasa-master nasa]# kubectl delete pods -l env=test pod "nasa-pod-label" deleted [root@nasa-master nasa]# kubectl get pods -l env=test No resources found.