kubectl cordon <워커노드이름> : cordon 설정하기
kubectl uncordon <워커노드이름> : cordon 해제
워크노드에 Cordon을 설정하면 Pod를 배포할때 스케쥴링되지 않는다
드레인은 해당파드를 다른 워크노드에 추출한다. (Cordon은 자동으로 됨)
기본 명령어로하면 데몬셋이나 단순 Pod등 때문에 안되는경우가 많다
그럴경우 데몬셋 무시 명령어나 force 옵션을 넣어줄 수 있다.
kubectl drain w3-k8s --ignore-daemonsets --force
Pod를 어떤 노드로 보낼지 선택 할 수 있다.
apiVersion: v1
kind: Pod
metadata:
name: nodename
spec:
containers:
- name: nginx
image: nginx
#nodeName: w3-k8s #노드 이름으로 선택하는방법
#nodeSelector: #노드 셀렉터로 레이블을 골라서 선택하는 방법
#inmemory: redis
노드 이름을 통해서 선택하는방법은 자주 사용하진 않는다.
k get node --show-labels : 노드의 레이블 이름 보기
k label node <노드네임> <key>=<value> : 레이블 넣기
k label node <노드네임> <key>- : 키값을넣고 옆에 -를붙이면 간단히 뺄 수 잇다.
노드의 레이블을 통해서 검색이나 배포를할 수 있다.
이름과의 차이는 중복이 된다.
노드 셀렉터 말고 좀더 배포 조건을 세분화 할 수 있다.
required는 실행될때 무조건 스케줄링
preferred는 선호하는정도
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nodeaffinity-preferred
name: nodeaffinity-preferred
spec:
replicas: 3
selector:
matchLabels:
app: nodeaffinity-preferred
template:
metadata:
labels:
app: nodeaffinity-preferred
spec:
containers:
- image: nginx
name: nginx
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: gpupool
operator: In
values:
- nvidia
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1 #얼마만큼 선호하느냐
preference:
matchExpressions:
- key: accelerator
operator: In
values:
- tesla-a100
gpupool value가 nvidia이고 accelerator의 value가 tesla-a100인것에만 배포
NotIn, DoesNotExist등으로 부정형으로 사용하는것을 안티 어피니티라고 부른다.
requiredDuringSchedulingIgnoredDuringExecution가 2개이상이면 그 어피니티는 AND연산자가아닌 OR연산자로 읽힌다. (둘중 하나만 충족해도 조건이 true로됨)
이와 같이 노드에 조건문을 사용할 수 있다.
테인트와 톨러레이션은 주로 노드를 특정 역할만 하도록 설정할 수 있다.
Taints로 락을 걸고 Tolerations으로 락을 푼다는 개념이다.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: daemonset-w-tolerations
labels:
app: daemonset-w-tolerations
spec:
selector:
matchLabels:
app: daemonset-w-tolerations
template:
metadata:
labels:
app: daemonset-w-tolerations
spec:
containers:
- name: nginx
image: nginx
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
마스터에서 node-role.kubernetes.io/master라는 taint가 설정되어있어서 배포가 된다
k taint node w3-k8s DB=customer-info:NoSchedule
이렇게 설정해주면 tolerations으로 설정을 해줘야 w3-k8s에'도' 들어가진다
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deploy-w-tolerations
name: deploy-w-tolerations
spec:
replicas: 6
selector:
matchLabels:
app: deploy-w-tolerations
template:
metadata:
labels:
app: deploy-w-tolerations
spec:
containers:
- image: nginx
name: nginx
tolerations:
- effect: NoSchedule
key: DB
value: customer-info
톨러레이션이 락을 풀어줄뿐이지 그곳으로만 들어가게하는것이아니다.
톨러레이션으로 락을 풀고 그 노드에만 넣고싶으면 조건문(어피니티)를 함께 써야한다
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deploy-w-tolerations-nodeaffinity
name: deploy-w-tolerations-nodeaffinity
spec:
replicas: 6
selector:
matchLabels:
app: deploy-w-tolerations-nodeaffinity
template:
metadata:
labels:
app: deploy-w-tolerations-nodeaffinity
spec:
containers:
- image: nginx
name: nginx
tolerations:
- effect: NoSchedule
key: DB
value: customer-info
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: inmemory
operator: In
values:
- redis
이렇게해야 w3에만 redis가 들어간다
kubectl patch node w3-k8s -p '{"spec":{"taints":[]}}'
kubectl patch로 쿠버네티스의 내용을 수정할 수 있음.
이경우는 taints를 없애는거임
patch는 기억해둬야할것같다.