쿠버네티스 (5) - 노드의 관리

Seong·2023년 1월 29일
0

쿠버네티스

목록 보기
5/6
post-thumbnail

출처:
https://www.inflearn.com/course/%EA%B7%B8%EB%A6%BC%EC%9C%BC%EB%A1%9C-%EB%B0%B0%EC%9A%B0%EB%8A%94-%EC%BF%A0%EB%B2%84%EB%84%A4%ED%8B%B0%EC%8A%A4#reviews

Cordon과 Drain

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는 선호하는정도

노드 어피니티의 연산자

  • In NotIn :키 값을 체크
  • Exists DoesNotExist : 키의 존재 여부를 체크
  • Gt Lt : 키 값의 높고 낮음을 체크
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가 설정되어있어서 배포가 된다

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는 기억해둬야할것같다.

profile
필요할때 찾아보는 메모장

0개의 댓글

관련 채용 정보