본문 바로가기
AWS

AWS EKS tolerations, taints의 정의, 설정하기

by parkjp 2024. 2. 5.

서론

Kubernetes(쿠버네티스)를 설정하다보면 tolerations와 taints라는 것이 보일 것이다.

taints와 tolerations가 무엇이고 설정은 어떻게 하는지 알아보자.

 

AWS EKS에서 설정하는 법으로 예시를 들어보겠다.

반응형

Taints란?

간단하게 말하면 Taints는 노드가 pod를 제외시킬 수 있는 설정이다.

다르게 말하면 특정 노드에 대해 특정 pod만 실행할 수 있도록 역할을 제한하기 위한 목적으로 사용된다.

하나의 노드에 여러 taints를 설정할 수 있다.

 

예를 들어, Batch를 돌리는 노드에서는 Batch에 관련된 pod만 실행되어야한다. 그렇다면 해당 Batch 노드에 taints설정을 하여 제한할 수 있다.

 

Tolerations란?

Tolerations는 pod에 적용되는 설정이다. tolerations를 통해 스케쥴러는 그와 일치하는 테인트가 있는 파드만 실행한다.

여기서 taints와 tolerations는 함께 작동하여 pod가 부적절한 노드에 스케쥴되지 않게한다.

하나의 pod에 여러 tolerations를 설정할 수 있다.

 

예를 들어, AWS Batch를 모니터링하기 위하여 cloudwatch나 fluent-bit을 설치한다면 해당 Demonset에 아래와 같이 배치노드에 스케쥴될 수 있도록 설정한다.

tolerations:
- key: "batch.amazonaws.com/batch-node"
  operator: "Exists"

 

Taints 설정하기

AWS EKS에서 Taints는 노드 그룹 별로 설정할 수 있는데

여러 방법으로 설정이 가능하다.

 

  •  yaml파일로 적용 예시
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: eks-taint-demo
  region: us-west-1

# Unmanaged nodegroups with and without taints.
nodeGroups:
  - name: ng1
    instanceType: m5.xlarge
    minSize: 2
    maxSize: 3
    taints:
      - key: classified_workload
        value: "true"
        effect: NoSchedule
      - key: machine_learning_workload
        value: "true"
        effect: NoSchedule

  - name: ng2
    instanceType: m5.xlarge
    minSize: 2
    maxSize: 3

 

 

update-nodegroup-config — AWS CLI 1.32.34 Command Reference

Note: You are viewing the documentation for an older major version of the AWS CLI (version 1). AWS CLI version 2, the latest major version of AWS CLI, is now stable and recommended for general use. To view this page for the AWS CLI version 2, click here. F

docs.aws.amazon.com

 

이 외에도 kubectl이나 aws 콘솔 창에서도 수정이 가능하다.

 

NoSchedule toleration이 없으면 pod 스케쥴 X 기존에 실행되던 pod 적용 X
PreferNoSchedule 특정 상황에 따라서 pod가 스케쥴 될 수 있다. 기존에 실행되던 pod 적용 X
NoExecute toleration이 없으면 pod 스케쥴 X 기존에 실행되던 pod 적용 O
(toleration이 없으면 실행중인 pod도 종료)

 

 

Tolerations 설정하기

아래는 Tolerations를 설정하는 Deployment.yaml의 예시이다.

operator에는 Equal과 Exists가 있는데 Equal은 key와 value, effect가 모두 일치하는지 확인하고 Exists는 key만 체크한다.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: microservice-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: java-microservice
  template:
    metadata:
      labels:
        app.kubernetes.io/name: java-microservice
    spec:
      tolerations: 
        - key: "<Taint key1>"
          operator: Equal
          value: "<Taint value>"
          effect: "NoSchedule" 
        - key: "<Taint key2>"
          operator: Exists
          effect: "NoSchedule"
        - key: "<Taint key3>"
          operator: Exists
      containers:
        - name: java-microservice-container
          image: <account_number>.dkr.ecr<region>.amazonaws.com/<repository_name>:latest
          ports:
            - containerPort: 4567

 

 

반응형