IT/AWS

[AWS] eksctl을 이용한 EKS 생성 (Managed NodeGroup with Launchtemplate + Custom AMI)

반응형

Intro

작업순서

  • custom AMI 준비
  • eksctl yaml파일 작성
  • eksctl

custom AMI 준비

  • AWS 공식 문서에서 EKS Optimized AMI id 를 조회 https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/eks-optimized-ami.html
  • 또는 해당 명령어를 사용하여 AMI id 조회 aws ssm get-parameter --name /aws/service/eks/optimized-ami/<1.20>/<amazon-linux-2>/recommended/image_id --region <region-code> --query "Parameter.Value" --output text
  • 해당 이미지를 EC2 instance 로 생성하여 작업후 커스텀 이미지 생성

eksctl install on MAC OS

  • homebrew 설치 (설치 되어있다면 생략)
  • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  • weaveworks/tap 설정 (tap은 homebrew 소프트웨어 저장소라고 생각하면됨)
  • brew tap weaveworks/tap
  • eksctl install
  • brew install weaveworks/tap/eksctl
  • 설치 확인 및 버전확인
  • eksctl version

eksctl yaml - 기존에 VPC/SUBNET가 생성되어 있는 경우

  • eksctl-managedng-customami-my-vpc.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: EKSCTL-TEST
  region: ap-northeast-2

vpc:
  id: "vpc-05d00b602d162a059"
  # (optional, must match VPC ID used for each subnet below)

  #cidr: "10.144.0.0/16"
  # (optional, must match CIDR used by the given VPC)

  subnets:
    # must provide 'private' and/or 'public' subnets by availibility zone as shown

    ### public
    public:
      public-a:
        id: "subnet-06fb73df586ec2ece"
        #cidr: "10.144.10.0/24"
        # (optional, must match CIDR used by the given subnet)
      public-c:
        id: "subnet-07c47dbd3cadfeed3"
        #cidr: "10.144.20.0/24"
        # (optional, must match CIDR used by the given subnet)

    ### private
    private:
      private-frontend-a:
        id: "subnet-085c37d277deb8a14"
        #cidr: "10.144.152.0/25"
        # (optional, must match CIDR used by the given subnet)

      private-frontend-c:
        id: "subnet-0b0e51e1564e0e025"
        #cidr: "10.144.152.128/25"
        # (optional, must match CIDR used by the given subnet)

      private-backend-a:
        id: "subnet-01572e5b92343ff55"
        #cidr: "10.144.152.128/25"
        # (optional, must match CIDR used by the given subnet)

      private-backend-c:
        id: "subnet-0df15081b7284decc"
        #cidr: "10.144.152.128/25"
        # (optional, must match CIDR used by the given subnet)

      private-manage-a:
        id: "subnet-0207fdd851e02e013"
        #cidr: "10.144.152.128/25"
        # (optional, must match CIDR used by the given subnet)

      private-manage-c:
        id: "subnet-0f18b6ac70cec3a47"
        #cidr: "10.144.152.128/25"
        # (optional, must match CIDR used by the given subnet)

managedNodeGroups:
  - name: custom-nodegroup
    instanceType: m5.large
    minSize: 1
    desiredCapacity: 1
    maxSize: 2
    volumeSize: 20
    ami: ami-078d540cf1d599e95
    privateNetworking: true
    subnets:
      - private-backend-a
      - private-backend-c
    ssh:
      allow: true
      publicKeyName: GSN-KYM
    # securitygroup 을 추가로 붙히고 싶을 경우 사용(기본으로 cluster sg, workernode sg 2개가 붙음)  
    #securityGroups:
    #attachIDs: ["sg-123", "sg-321"]
    overrideBootstrapCommand: |
      #!/bin/bash
      /etc/eks/bootstrap.sh EKSCTL-TEST --kubelet-extra-args '--node-labels=eks.amazonaws.com/nodegroup=custom-nodegroup,eks.amazonaws.com/nodegroup-image=ami-078d540cf1d599e95'

참고

  • 이 경우 security group은 eksstyle로 생성이 되지 않고 aws console 스타일로 생성이 됨
  • EKS securigy group 파헤치기 참고 URL : https://kim-dragon.tistory.com/71
반응형