[k8s] labels-selector, taints-tolerlations

Woong·2025년 8월 27일
0

Docker, k8s

목록 보기
26/26

label, selector

  • label: key-value 형태로 리소스에 메타데이터 부여
  • selector: 특정 label 이 있는 리소스를 선택하는 필드

label

  • 리소스 분류 및 식별을 위한 key-value 쌍
  • 파드, 노드, 서비스 등 모든 리소스에 부여 가능
  • 운영/배포 시 리소스를 그룹화하거나, 특정 리소스만 선택하는 용도로 사용

nodeSelector

  • Pod spec 에서 사용
  • 파드가 특정 label 이 부여된 노드에서만 스케줄링되도록 제약
  • 간단한 key-value 매칭만 지원
    • 복잡한 조건일 경우 nodeAffinity 사용

taint, tolerations

  • taint: 노드에 제약 조건을 부여
  • tolerations: pod 가 특정 taint 를 허용하도록 설정

taint

  • 노드에 부여하는 제약
  • 해당 taint 가 걸린 노드에는 기본적으로 파드가 스케줄링되지 않음
  • 효과(effect)에 따라 동작 구분
    • NoSchedule: toleration 없는 파드는 스케줄링 불가
    • PreferNoSchedule: 가능하면 스케줄링하지 않음
    • NoExecute: 이미 실행 중인 파드도 축출(eviction)

tolerations

  • Pod spec 에서 사용
  • 특정 taint 가 있는 노드에도 스케줄링될 수 있도록 허용
  • taint 를 무시하고 올라갈 수 있음을 명시
    • 노드에 taint를 걸면 일반 파드가 못 올라가고, pod spec에 tolerations을 넣어줘야 올라갈 수 있다
  • 보통 GPU, 특정 워크로드 전용 노드 등에 활용

karpenter 에서

  • NodePool 설정으로 노드에 label, taint 부여 가능
  • Pod spec
    • nodeSelectorlabel 기준으로 스케줄링 제약
    • tolerationstaint 기준으로 스케줄링 허용
  • Pod 가 어느 노드에 배치될지 결정
  • ex)
    • spec.template.metadata.labels 에서 nodegroup:infra 로 노드에 intra 라벨링
    • spec.template.spec.taint 에서 nodegroup=infra:NoSchedule 이므로 pod 는 스케줄링 불가하도록 차단하되, tolerations 가 있으면 허용
jungahn@userui-MacBookPro-66 ~ % kubectl describe nodepool
(...)
Spec:
  Disruption:
    Budgets:
      Nodes:               10%
    Consolidate After:     300s
    Consolidation Policy:  WhenEmpty
  Limits:
    Cpu:  1000
  Template:
    Metadata:
      Labels:
        Nodegroup:  infra
    Spec:
      Expire After:  720h
      Node Class Ref:
        Group:  karpenter.k8s.aws
        Kind:   EC2NodeClass
        Name:   default
      Requirements:
        Key:       node.kubernetes.io/instance-type
        Operator:  In
        Values:
          c6i.large
          c6i.xlarge
          r6i.large
          r6i.xlarge
        Key:       karpenter.sh/capacity-type
        Operator:  In
        Values:
          on-demand
      Taints:
        Effect:  NoSchedule
        Key:     nodegroup
        Value:   infra
(...)
  • manifest 프로젝트에서 아래와 같이 설정하여 위 nodepool 의 node 에 배포되도록 설정
    • nodeSelector infra 로 설정 -> nodegroup=infra 로 라벨링된 노드 선택
    • tolerations infra 로 설정 -> taint 가 nodegroup=infra:NoSchedule 인 노드에 배포되도록 허용
      • key, value, effect 로 taint 와 매칭
      # NodePool의 taints: nodegroup=infra:NoSchedule을 무시하고 노드에 배치되도록 허용
      tolerations:
        - key: "nodegroup"
          operator: "Equal"
          value: "infra"
          effect: "NoSchedule"
      # NodePool의 label: nodegroup=infra 인 노드에만 배치되도록 제한
      nodeSelector:
        nodegroup: infra

reference

0개의 댓글