Reference.
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
Labels and Selectors
Labels are key/value pairs that are attached to objects such as Pods. Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system. Labels can
kubernetes.io
레코드에 라벨 값 추가
kubectl get pods -L<라벨>
Pod 조회 시, 특정 라벨을 레코드 기준으로 값을 추가
라벨 값으로 필터링 출력
kubectl get pods -l<라벨>=<특정값>
Pod 조회 시, 특정 라벨=값을 기준으로 필터링 조회
여러개의 라벨로 필터링이 필요하면 ,(쉼표) 로 구분한다
kubectl get pods -l<라벨>=<특정값>,<라벨>=<특정값>,<라벨>=<특정값>,,,<라벨>=<특정값>
라벨을 기준으로 모든 리소스(Pods, Service, ReplicaSet,,,) 출력
지정 Node에 Pod 생성
Node의 Label 확인
kubectl get nodes --show-labels
결과 확인
NAME STATUS ROLES AGE VERSION LABELS
worker0 Ready <none> 1d v1.13.0 ...,<라벨>=<값>,kubernetes.io/hostname=worker0
worker1 Ready <none> 1d v1.13.0 ...,kubernetes.io/hostname=worker1
worker2 Ready <none> 1d v1.13.0 ...,kubernetes.io/hostname=worker2
특정 node 라벨을 지정해서 Pod.yaml 정의 : spec > nodeSelector
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
<라벨>: <값>
yaml 파일을 apply 하면
<라벨>: <값> 을 가지고 있는 노드 중 하나에 배치된 것을 확인할 수 있다
'DevOps' 카테고리의 다른 글
Ubuntu: apt-get update() { the public key is not available; } (2) | 2024.09.05 |
---|---|
Docker : summary() { Docker의 등장 배경, 기본 용어와 원리 } (0) | 2024.04.09 |
Docker : Dockerfile() { Dockerfile 명령어 정리, Dockerfile 빌드 } (0) | 2024.04.09 |
Docker : Install() { Docker 설치, Rootless Mode 설정 } (0) | 2024.04.09 |
댓글