본문으로 건너뛰기

Affinity

nodeAffinity

Reference
  • kubectl explain pod.spec.affinity.nodeAffinity

nodeAffinity는 Pod가 스케줄링될 Node의 조건을 정의합니다.

spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values:
- amd64
  • requiredDuringSchedulingIgnoredDuringExecution
    • nodeSelectorTerms: []
      • 여러 개를 선언하면 OR 조건이 적용됩니다
      • matchExpressions: []
        • 여러 개를 선언하면 AND 조건이 적용됩니다
        • key: <key>
        • operator: In|NotIn|Exists|DoesNotExist|Gt|Lt
        • values: []
      • matchFields: []
        • 여러 개를 선언하면 AND 조건이 적용됩니다
        • key: metadata.name
        • operator: In|NotIn|Exists|DoesNotExist|Gt|Lt
        • values: []
  • preferredDuringSchedulingIgnoredDuringExecution: []
    • 여러 개를 선언하면 만족하는 조건의 weight의 총합이 높은 Node에 Pod을 스케줄링합니다
    • weight: 1 ~ 100
    • preference
      • matchExpressions: []
      • matchFields: []

podAffinity & podAntiAffinity

Reference
  • kubectl explain pod.spec.affinity.podAffinity

Pod가 스케줄링될 때 topologyKey조건 내에서 label이 일치하는 Pod을 찾습니다. podAffinity의 경우 조건이 일치하는 토폴로지에 Pod를 배치하고, podAntiAffinity의 경우 조건이 일치하는 토폴로지를 피해서 Pod을 배치합니다.

spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
topologyKey: kubernetes.io/hostname
labelSelector:
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values:
- test-app
  • requiredDuringSchedulingIgnoredDuringExecution
    • topologyKey: <labelKey>
      • Node의 label을 확인하여 <topologyKey>: <topologyValue>가 같은 Node를 기준으로 selector의 조건을 확인합니다
      • kubernetes.io/hostname: 한 Node 내에서 조건을 만족해야합니다
      • topology.kubernetes.io/zone: 같은 zone 내에서 조건을 만족해야합니다
    • namespaces: []
    • namespaceSelector
      • {}인 경우 모든 namespace를 기준으로 합니다
      • null인 경우 namespaces가 null이거나 []이면 Pod의 namespace가 조건이 됩니다
      • matchExpressions: []
        • key: <key>
        • operator: In|NotIn|Exists|DoesNotExist
        • values: []
      • matchLabels
        • <key>: <value>
    • matchLabelKeys: []
      • labelSelector가 설정되어 있어야 합니다.
    • mismatchLabelKeys: []
      • labelSelector가 설정되어 있어야 합니다.
    • labelSelector
      • matchExpressions: []
      • matchLabels: {}
  • preferredDuringSchedulingIgnoredDuringExecution: []