본문 바로가기
Amazon AWS/EKS

EKS Managed Nodegroup의 인스턴스 유형 변경하기

by 홍띠 2023. 9. 3.

EKS 클러스터에서 Managed Nodegroup의 인스턴스 유형을 바꾸려고 한다.

 

노드그룹의 desired capacity등은 eksctl upgrade 명령어로 간편하게 가능하지만,

인스턴스 type을 바꾸기 위해서는 원하는 유형의 새로운 노드그룹을 생성하고, 기존 노드그룹에서 마이그레이션해서 사용하는 방식으로 변경해야 한다.

 

그래서 아래의 문서를 참고해서 진행하되, 각 상황에 맞게 변경해서 진행하면 된다.

https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/migrate-stack.html

 

새 노드 그룹으로 마이그레이션 - Amazon EKS

새 노드 그룹으로 마이그레이션 이 주제에서는 새로운 노드 그룹을 생성하고, 기존 애플리케이션을 새 그룹으로 안정적으로 마이그레이션한 다음, 이전 노드 그룹을 클러스터에서 제거하는 방

docs.aws.amazon.com

 

새 노드그룹 생성

변경을 원하는 Instance Type으로 새로운 노드그룹을 생성한다. 

여기서 예시로 생성하는 노드그룹은 private subnet에 구성할 managed nodegroup 이다.

 

방법 1 - 명령어를 이용해서 노드그룹 생성

간단하지만, 세세한 설정을 하기 불편하다.

eksctl create nodegroup --cluster <cluster-name> --name <nodegroup-name> --node-type <instance type> --nodes <desired capacity> --nodes-min <Min> --nodes-max <Max> --ssh-access --managed=true --ssh-public-key <ec2-keypair> --node-private-networking
eksctl set labels --cluster <cluster-name> --nodegroup <nodegroup-name> --labels <원하는 라벨 설정 ex.node selector>

 

방법 2 - 설정파일을 작성해서 노드그룹 생성

설정파일을 작성해야 하는 번거로움이 있으나, 좀 더 세세하게 설정이 가능하고 파일형태로 저장해 놓을 수 있다.

eksctl create nodegroup --config-file common/cluster-config/private-managed-ng.yml

private-managed-ng.yml

---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: demo-cluster
  region: ap-northeast-2
  version: "1.25"

managedNodeGroups:
    - name: managed-ng-private-t3-large
      instanceType: t3.large
      subnets:
        - "subnet-id01"
        - "subnet-id02"
      desiredCapacity: 1
      privateNetworking: true
      minSize: 1
      maxSize: 9
      labels:
          nodegroup-type: "managed-private-workloads"
      ssh: 
          publicKeyName: demo-keypair
      iam:
          attachPolicyARNs:
          withAddonPolicies:
              autoScaler: true
              ebs: true
              efs: true

기존 노드그룹 삭제

마이그레이션 할 노드그룹 생성이 완료되었으면, 기존에 사용하던 노드그룹을 삭제해주면 된다.

Node selector 혹은 Node Affinity를 이용한다면, 기존 노드그룹 라벨을 변경해서 파드가 더이상 해당 노드에 스케쥴링 되지 않도록 하고, 리소스들을 새로 배포한다.
이렇게 되면 좀 더 안전하게 deployment / daemonset들을 하나씩 마이그레이션 시킬 수 있다.

아래는 기존의 노드그룹을 삭제하는데 사용되는 명령어이다.

eksctl delete nodegroup --cluster <cluster-name> --name <old-nodegroup-name>