카테고리 없음
[ EKS ] affinity 설정
김붕어87
2023. 4. 3. 15:33
반응형
개요
affinity 이란?
affinity은 pod를 특정 노드에 배포할 수 있도록 해줍니다.
nodeSelector와 동일한 기능을 하지만 affinity가 디테일하게 다양한 옵션을 사용할 수 있다.
nodeSelector와 affinity 차이점
nodeSelector
- 지정한 labels("key : value")이 설정된 노드에 pod를 배포해준다.
affinity
- 지정한 labels("key : value")외 다양한 조건으로 노드에 pod를 배포해준다.
ex) 하나의 노드에 같은 서비스의 pod가 중복으로 배포되지 않도록 설정해준다.
ex) was pod은 DB pod가 올라간 노드에 배포되도록 설정한다.
[ affinity 종류 ]
- node affinity
- 지정된 label을 가지고 있는 노드에 배포하도록 설정
- pod affinity
- 기존에 배포된 pod를 기준으로 배포할 node 선택한다.
- antiaffinity
- 지정한 옵션의 노드에는 배포하지 않도록 설정
- ex) master / Slave DB가 같은 wokernode에 배포되지 않도록 설정
- ex) klaytn-ng 노드에는 배포되지 않도록 설정
[ node affinity 옵션 ]
- hard
- requiredDuringSchedulingIgnoredDuringExecution
- requiredDuringSchedulingRequiredDuringExecution
- soft
- preferredDuringSchedulingIgnoredDuringExecution
- preferredDuringSchedulingRequiredDuringExecution
- node affinity 옵션 설명
- required : 지정한 옵션과 반드시 맞는 곳에만 배포
- preferred : 선호하는 옵션으로, 지정한 옵션이 있는 노드가 있으면 해당 노드에 배포하고, 아니면 다른곳에 배포
- Ignored : 운영 중에 WokerNode label이 변경되면 label를 무시
- Required : 운영 중에 WokerNode label이 변경되면 label에 맞는 WokerNode에 재배포
- operator 옵션
- In
- 일치 할 경우
- NotIn
- 일치하지 않을 경우
- Exists
- DoesNotExist
- Gt
- Lt
- In
1. node affinity yaml 설정
- 설명
- requiredDuringSchedulingIgnoredDuringExecution
- matchExpressions 조건에 반드시 맞는 wokernode에 배포, 운영 중 wokernode label 변경되면 무시
- key: nodegroupname , operator: In
- wokernode label이 nodegroupname:app-ng 노드그룹에 배포
- requiredDuringSchedulingIgnoredDuringExecution
spec:
containers:
affinity:
nodeAffinity: # nodeaffinity
requiredDuringSchedulingIgnoredDuringExecution: # 반드시 맞는 WokerNode에 배포 + WokerNode label 변경시 무시
nodeSelectorTerms:
- matchExpressions: # 조건
- key: nodegroupname # WokerNode label Key
operator: In # label 값이 일치할 경우
values:
- app-ng # WokerNode label value
2. pod affinity yaml 설정
- 설명
- preferredDuringSchedulingIgnoredDuringExecution
- matchExpressions 조건과 맞는 wokernode에 배포, 없을 경우 다른 wokernode에 배포
- key: app , operator: In
- app:nginx 라벨인 pod가 배포된 wokernode에 배포
- topologyKey: kubernetes.io/hostname
- 배포 대상 wokernode label key 지정
- app:nginx 라벨인 pod가 배포된 wokernode의 Name은 ip-123-123-123이다.
- 배포 대상 wokernode label은 kubernetes.io/hostname:ip-123-123-123
- preferredDuringSchedulingIgnoredDuringExecution
spec:
containers:
affinity:
podAffinity: # podaffinity
preferredDuringSchedulingIgnoredDuringExecution: # 선호하는 WokerNode에 배포 + WokerNode label 변경시 무시
- labelSelector: # 조건
matchExpressions:
- key: app # WokerNode label Key
operator: In # label 값이 일치할 경우
values:
- nginx # WokerNode label value
topologyKey: kubernetes.io/hostname
2. pod anti affinity yaml 설정
- 설명
- requiredDuringSchedulingIgnoredDuringExecution
- matchExpressions 조건에 반드시 맞는 wokernode에 배포, 운영 중 wokernode label 변경되면 무시
- key: app , operator: In
- app:nginx 라벨인 pod가 배포된 wokernode에 절대 배포하지 않는다.
- requiredDuringSchedulingIgnoredDuringExecution
spec:
containers:
affinity:
podAntiAffinity: # podAntiAffinity
requiredDuringSchedulingIgnoredDuringExecution: # 선호하는 WokerNode에 배포 + WokerNode label 변경시 무시
- labelSelector: # 조건
matchExpressions:
- key: app # WokerNode label Key
operator: In # label 값이 일치할 경우
values:
- nginx # WokerNode label value
topologyKey: kubernetes.io/hostname
반응형