1. cordon
2. drain
3. nodename
4. label
5. nodeSelector
6. node affinity & anti affinity : 선호하는 노드 설정하기
7. Taints & Tolerations : 노드 보호하기
1. cordon
cordon 설정한 노드에는 pod가 뜨지 않는다, 스케줄링 되지 않는다.
kubectl cordon k8s-node3(노드이름)
#cordon 상태 해제
kubectl uncordon k8s-node3(노드이름)
2. drain
drain 설정한 노드에 있는 pod를 다른 노드로 옮기고 cordon 설정 된다.
kubectl drain k8s-node3(노드이름) --ignore-daemonsets --force
- demonset이 있으면 drain 할 수 없다.
- deploy로 보호받지 않는 pod는 축출과정에서 삭제된다.
3. nodename
내가 원하는 노드에 파드가 뜰 수 있도록 nodename을 설정 할 수 있다.
apiVersion: v1
kind: Pod
metadata:
name: nodename
spec:
containers:
- name: nginx
image: nginx
nodeName: k8s-node3
nodename 에 지정된 노드에 파드가 생성 된다.
하지만 잘 쓰지 않는 방법. 노드 관리는 label이 더 효과적이다.
4. label
node가 가지고 있는 전체 label 값 조회하기
kubectl get node --show-labels
node3에 input=test 라는 label 값 매기기
kubectl label node k8s-node3 input=test
input=test 라는 label을 가진 node 전부 검색하기
kubectl get node -l input=test
#노드가 엄-청 많을 경우에 검색하기 유용하다
#input이 key, test가 value. key만으로도 검색 가능
노드3에 매겨진 label 삭제하기
# node에 적용한 label값 없애기
# node이름 key값- (-)로 label값을 없애라는 뜻
kubectl label node k8s-node3 input-
*한 노드에 label값이 여러개여도 됨
5. nodeSelector
nodeSelector로 기존 선언한 레이블을 명시해서 파드를 띄울 워커노드를 지정할 수 있다.
apiVersion: v1
kind: Pod
metadata:
name: nodeselector-inmemory
spec:
containers:
- name: nginx
image: nginx
nodeSelector:
inmemory: redis #inmemory 는 레이블에 매긴 key값 redis는 레이블 value
그러니까 이 yaml 로 선언한 이 파드는 노드셀렉트에 의해 inmemory=redis 레이블을 가진 워커노드에 띄워진다.
또 레이블은 워커 노드에 중복선언 가능하기 때문에, 이 레이블이 달린 워커노드 전부에 이 파드가 띄워진다.
6. node affinity & anti affinity : 선호하는 node 설정하기
affinity : 밀접한 관계, 애호, 맞는 성질 (affinity로 어느쪽과 친하다 라는 부분을 지정하는 것) > 선호하는 node 설정하기
배포 조건
required 꼭 이쪽 노드에서 배포하자 > requiredDuringSchedulingIgnoredDuringExecution
perferred 이 노드에서 배포하길 선호함 > preferredDuringSchedulingIgnoredDuringExecution
연산자(operator)
In/NotIn (키값 체크)
Exists/DoesNotExist (키 존재 여부 체크)
Gt/Lt (키 값 크고 작음 체크)
.yaml
apiVersion: apps/v1
kind: Deployment
.
.
.
spec:
containers:
- image: nginx
name: nginx
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: input
operator: In
values:
- test
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: preferlabel
operator: In
values:
- prefertest
input=test label에 배정 할 건데, preferlabel=prefertest 라는 label이 붙은 쪽을 선호하게 설정
operator에 NotIn으로 설정하면 prefertest를 선호하지 않게 설정할 수 도 있다. (anti-affiniti)
주의 : required설정과 prefered설정은 or조건이다 (and조건이 아님)
7.Taints & Tolerations : 노드를 보호하는 방법
쿠버네티스 세계에서의 Taints : 자물쇠, 걸어잠구는
쿠버네티스 세계에서의 Tolerations : 열쇠
masterNode에는 taint가 걸려있다.
tolerations에 taint와 같은 값을 주면 taint설정을 통과해서
(taint와 동일한 tolerations의 값이 열쇠가 되는 것) 파드를 생성할 수 있게 된다.
taint값의 조건은 effect, key, value, operator로 4가지 조건이 있다.
key, value는 label과 비슷하게 식별을 위해 사용된다고 생각하면 된다.
effect는 Noschedule, PreferNoSchedule, NoExecute 인데 주로 기본값인 NoSchedule으로 사용한다.
operator는 키와 값에 대한 연산자로 Exists, Equal 이 있는데 설정을 입력하지 않으면 디폴트값은 Equal이다.
Effect
- NoSchedule
노드에 테인트가 설정되어있지 않으면 노드에 파드가 스케줄 되지 않음. 이 경우 톨러레이션으로만 배포 가능
- PreferNoSchedule
스케줄러에 더이상 할당할 노드가 없는 경웨는 테인트 설정을 무시하고 파드를 스케줄함
- NoExecute
톨러레이션 없는 파드는 모두 노드에서 제거
Operater
Exists, Equal
Operater Equal, Exists 경우에 따라 파드 할당 조건이 다르다. > 매우 복잡
.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deploy-tolerations
name: deploy-tolerations
spec:
.
.
.
spec:
containers:
- image: nginx
name: nginx
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
kubectl get nod k8s-master -o yaml | grep -i taint -F5
#-F5 : -F는 검색어 앞뒤로 몇 개를 볼 건지 설정
#k83-master 는 마스터 노드 이름
확인해보면 아래와 같이 taint가 설정되어 있는 것을 볼 수 있다.
taints:
- effect: NoSchedule
key: node-role.kubernetes.io/master
taint & toleraiton은 자물쇠를 채웠다가 풀었다가 하는 기능이다.
어느 한쪽 노드에 파드를 생성하고 싶다면 affinity 사용해야한다.
자물쇠인 taint는 taint하고 싶은 node에 아래처럼 적용할 수 있다.
kubectl taint node k8s-node3 input=test:NoSchedule
#kubectl taint node {nodename} {key}={value}:{option}
tolerations는 apply -f 단계에서 yaml에 아래처럼 tolerations를 적용할 수 있다.
tolerations:
- effect: NoSchedule
key: input
value: test
taint 정보는 describe로도 확인이 가능하다.
kubectl describe node k8s-node3
'Container & Orchestration' 카테고리의 다른 글
인터넷 없는 환경에서 docker image 불러오는 방법 (0) | 2024.05.30 |
---|---|
자주 쓰는 kubectl 명령어 (0) | 2023.08.17 |
[k8s] kustomize로 애플리케이션 동적 배포 (0) | 2023.08.11 |
[k8s] 기본 오브젝트의 yaml 파일 (0) | 2023.08.04 |