Label과 LabelSelector, Annotations
2022. 5. 29. 21:47ㆍkubernetes
Label
파드와 같은 오브젝트에 첨부된 키와 값의 쌍으로
각 오브젝트 및 파드의 특성을 식별하는 데 사용
Label 확인 및 관리- 명령형 커맨드
pod들의 label들을 확인
kubectl get pods --show-labels
특정 pod의 label을 yaml 형식으로 확인
kubectl get pods pod명 -o yaml
특정 podd의 label 및 자세한 정보 확인
kubectl describe pods pod명
특정 파드의 label 등록 및 설정
kubectl label pods pod명 ENV=developments
이미 label이 등록 되있는 pod의 label의 value 값을 변경
kubectl label pods pod명 ENV=staging --overwirte
등록 되있는 label의 값을 제거
kubectl label pods pod명 ENV(key값)-
LabelSelector
- Label을 통한 검색 및 리소스간에 연결을 하기 위해 설정
일치성(equality base)
- =
- ==
- !=
ex) =, ==
kubectl get pods -l APP=nginx
kubectl get pods -l APP==nginx
ex) !=
kubectl get pods -l 'APP!=nginx'
집합성 (set base)
- in : 속해 있는
- notin : 속해 있지 않은
- exists : 지정한 키값이 존재하는 것만 매칭
ex) kubectl get pods -l 'APP'
- dosenotexists : 지정한 키값이 존재하지 않는 것만 매칭
ex) kubectl get pods -l '!APP"
Annotations
Label과 비슷하지만 식별 되지 않는 메타데이타
- 명령형 커맨드
annotations 등록
kubectl annotate pods 파드명 created-by=Jang(annotations명)
annotations 변경
kubectl annotate pods 파드명 created-by=Kim(변경할 annotations명) --overwrite
annotations 제거
kubectl annotate pods 파드명 created-by-
YAML 파일 형식으로 pod의 label 및 annotations 정의
apiVersion: v1
kind: Pod
metadata:
name: myweb-label-anno
labels:
APP: apache
ENV: staging
annotations:
Created-by: Jang
spec:
containers:
- name: myweb
image: httpd
ports:
- containerPort: 80
protocol: TCP
'kubernetes' 카테고리의 다른 글
Pod Lifecycle/Lifetime (0) | 2022.05.31 |
---|---|
Namespace (0) | 2022.05.29 |
Workload - Pod (0) | 2022.05.29 |
Kubernetes Objects (0) | 2022.05.19 |
Kubespray로 Kubernetes 설치 (0) | 2022.05.17 |