Labels, Selectors and Annotations

OneDayDev·2023년 1월 27일
0

K8s

목록 보기
6/12

개요

Label과 Annotation은 쿠버네티스에서 resource의 metadata를 관리하는 데 사용된다.
Selector를 이용해 특정 Label을 가진 자원들을 선택할 수 있다.
Annotation은 주석 성격의 metadata를 기록하는 데 사용된다.

Labels and Selectors

Labels

  • 파드같은 오브젝트에 첨부된 key/value pairs
  • 예시
"metadata": {
  "labels": {
    "key1" : "value1",
    "key2" : "value2"
  }
}
  • 레이블은 UI와 CLI에서 효율적인 쿼리를 사용하고 검색에 사용하기에 적합하다.
  • 식별되지 않는 정보는 Annotation으로 기록해야 한다.

Label selectors

  • Label selector를 통해 클라이언트와 사용자는 오브젝트를 식별할 수 있다.
  • 다음 두 종류의 selector를 지원한다 : Equality-based requirement와 Set-based requirement
  • 두 종류의 selector 모두 논리적인 OR(||) 연산자가 없다
  • 쉼표(,)는 AND 연사자로 작동한다.

Equality-based requirement

  • 일치성 또는 불일치 기준의 요구사항으로 레이블의 키와 값의 필터링을 허용한다.
  • =,==,!= 이 세 가지 연산자만 허용한다.

Set-based requirement

  • in, notin, exists의 3개의 연산자를 지원한다.
  • 예시
environment in (production, qa)
tier notin (frontend, backend)
partition # exist
!partition # not exist

API

LIST and WATCH filtering

예시

kubectl get pods -l environment=production,tier=frontend
kubectl get pods -l 'environment in (production),tier in (frontend)'

Set references in API Objects

예시(Service and ReplicationController에서의 equality-based requirement)

"selector": {
    "component" : "redis",
}

예시(Job, Deployment, ReplicaSet and DaemonSet에서의 set-based requirments)

selector:
  matchLabels:
    component: redis
  matchExpressions:
    - {key: tier, operator: In, values: [cache]}
    - {key: environment, operator: NotIn, values: [dev]}

Annotations

예시

"metadata": {
  "annotations": {
    "key1" : "value1",
    "key2" : "value2" # 주의할 점 : 키와 값 모두 String
  }
}

사용 예시

  • 필드는 선언적 구성 계층에 의해 관리된다. 이러한 필드를 어노테이션으로 첨부하는 것은 클라이언트 또는 서버가 설정한 기본 값, 자동 생성된 필드, 그리고 오토사이징 또는 오토스케일링 시스템에 의해 설정된 필드와 구분된다.

  • 빌드, 릴리스, 또는 타임 스탬프, 릴리스 ID, git 브랜치, PR 번호, 이미지 해시 및 레지스트리 주소와 같은 이미지 정보.

  • 로깅, 모니터링, 분석 또는 감사 리포지터리에 대한 포인터.

  • 디버깅 목적으로 사용될 수 있는 클라이언트 라이브러리 또는 도구 정보: 예를 들면, 이름, 버전, 그리고 빌드 정보.

  • 다른 생태계 구성 요소의 관련 오브젝트 URL과 같은 사용자 또는 도구/시스템 출처 정보.

  • 경량 롤아웃 도구 메타데이터. 예: 구성 또는 체크포인트

  • 책임자의 전화번호 또는 호출기 번호, 또는 팀 웹 사이트 같은 해당 정보를 찾을 수 있는 디렉터리 진입점.

  • 행동을 수정하거나 비표준 기능을 수행하기 위한 최종 사용자의 지시 사항.

추천 자료 : Recommended Labels, Add a label to a node, Using labels effectively

출저 : Labels and Selectors, Annotations

profile
안녕하세요. Django 백엔드 개발하고 있습니다.

0개의 댓글