본문으로 건너뛰기
버전: docs v25.02

EKS 와 관련 인프라 및 리소스 설치


목차

  1. 사전 준비
  2. EKS Cluster 생성하기
  3. Cluster AutoScaler 설정하기
  4. Amazon EBS CSI Driver 설치하기
  5. Amazon EFS CSI Driver 설치하기
  6. NodeGroup 생성하기


자세한 단계

{변수}의 자세한 설명은 Terminology 페이지를 참고하세요


1. 사전 준비

설치를 위한 환경 설정이 완료 되어야 합니다. (1. 설치 환경 셋업하기 참고)



2. EKS Cluster 생성하기

  • eksctl 명령어를 이용해서 클러스터를 생성합니다.

  • 아래 명령어는 EKS Cluster 와 VPC 를 자동으로 생성합니다.

    • zones : VPC의 subnet을 a와 c 로 설정합니다.
    • vpc-cidr : VPC 의 IP 대역을 설정합니다.
    eksctl create cluster \
    --name ${AWS_CLUSTER_NAME} \
    --version ${AWS_CLUSTER_VERSION} \
    --region ${AWS_DEFAULT_REGION} \
    --zones ${AWS_DEFAULT_REGION}a,${AWS_DEFAULT_REGION}c \
    --vpc-cidr 10.0.0.0/16 \
    --without-nodegroup \
    --managed \
    --with-oidc
  • 생성 후 {AWS_VPC_NAME} 을 확인 합니다.

    • {AWS_VPC_NAME} = eksctl-eks-{AWS_DEFAULT_REGION_ALAIS}-{CLUSTER_NAME}-{DEPLOY_ENV}-{AWS_CLUSTER_VERSION_STR}-eks-master-cluster/VPC
    # 아래 명령어를 통해서 "Key": "Name" 의 "VALUE": ${AWS_VPC_NAME} 을 확인 합니다.
    aws ec2 describe-vpcs --query "Vpcs[-2].Tags"
    export AWS_VPC_NAME=


3. Cluster AutoScaler 설정하기

참고 페이지 : https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler

  • 아래 명령어로 Cluster AutoSclaer가 이용할 IAM policy 및 Service Account 를 생성합니다.
    cat <<EOT > policy-cluster-autoscaler.json
    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Sid": "VisualEditor0",
    "Effect": "Allow",
    "Action": [
    "autoscaling:SetDesiredCapacity",
    "autoscaling:TerminateInstanceInAutoScalingGroup"
    ],
    "Resource": "*",
    "Condition": {
    "StringEquals": {
    "aws:ResourceTag/k8s.io/cluster-autoscaler/$AWS_CLUSTER_NAME": "owned"
    }
    }
    },
    {
    "Sid": "VisualEditor1",
    "Effect": "Allow",
    "Action": [
    "autoscaling:DescribeAutoScalingInstances",
    "autoscaling:DescribeAutoScalingGroups",
    "ec2:DescribeLaunchTemplateVersions",
    "autoscaling:DescribeTags",
    "autoscaling:DescribeLaunchConfigurations",
    "ec2:DescribeInstanceTypes"
    ],
    "Resource": "*"
    }
    ]
    }
    EOT
    aws iam create-policy --policy-name policy-cluster-autoscaler --policy-document file://policy-cluster-autoscaler.json
    eksctl create iamserviceaccount \
    --cluster=$AWS_CLUSTER_NAME \
    --region=$AWS_DEFAULT_REGION \
    --namespace=kube-system \
    --name=cluster-autoscaler \
    --attach-policy-arn=arn:aws:iam::$AWS_ACCOUNT_ID:policy/policy-cluster-autoscaler \
    --role-name=role-cluster-autoscaler \
    --override-existing-serviceaccounts \
    --approve
  • Cluster AutoScaler를 설정합니다.
    curl -O https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml

    cp cluster-autoscaler-autodiscover.yaml cluster-autoscaler.yaml
    export CLUSTER_AUTOSCALER_VERSION=$(curl -sL https://registry.k8s.io/v2/autoscaling/cluster-autoscaler/tags/list | grep -o '"tags":\[.*\]' | sed 's/"tags":\[//;s/\]//' | tr ',' '\n' | tr -d '"' | grep "$AWS_CLUSTER_VERSION" | sort -V | tail -n 1)
    yq e 'select(documentIndex == 5)' cluster-autoscaler.yaml > deployment.yaml

    yq e -i '.spec.template.metadata.annotations."cluster-autoscaler.kubernetes.io/safe-to-evict" = "false"' deployment.yaml

    yq e -i '.spec.template.spec.containers[] |= select(.name == "cluster-autoscaler").image = "registry.k8s.io/autoscaling/cluster-autoscaler:" + env(CLUSTER_AUTOSCALER_VERSION)' deployment.yaml

    yq e -i '
    .spec.template.spec.containers[] |=
    select(.name == "cluster-autoscaler").command =
    (.command | map(select(. != "--node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/<YOUR CLUSTER NAME>")) +
    ["--node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/" + env(AWS_CLUSTER_NAME),
    "--scale-down-unneeded-time=10m",
    "--scale-down-utilization-threshold=0.7"])' deployment.yaml

    yq eval 'select(documentIndex != 5)' cluster-autoscaler.yaml > temp.yaml
    echo "---" >> temp.yaml
    cat temp.yaml deployment.yaml > cluster-autoscaler.yaml
    rm temp.yaml deployment.yaml
    kubectl apply -f cluster-autoscaler.yaml


4. Amazon EBS CSI Driver 설치하기

참고 페이지 : https://docs.aws.amazon.com/eks/latest/userguide/ebs-csi.html

  • 아래 명령어를 설정 합니다.

    export EBS_CSI_SA_ROLE_NAME=role-ebs-csidriver-${AWS_CLUSTER_NAME}
    export EBS_CSI_SA_ROLE_ARN=arn:aws:iam::${AWS_ACCOUNT_ID}:role/${EBS_CSI_SA_ROLE_NAME}
  • Cluster에 OIDC 설정이 되어있는지 확인합니다.

    oidc_id=$(aws eks describe-cluster --name ${AWS_CLUSTER_NAME} --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
    echo $oidc_id
  • EBS CSI Driver를 관리할 Service Account IAM을 생성합니다.

    eksctl create iamserviceaccount \
    --name ebs-csi-controller-sa \
    --namespace kube-system \
    --cluster ${AWS_CLUSTER_NAME} \
    --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
    --approve \
    --role-only \
    --role-name ${EBS_CSI_SA_ROLE_NAME}
  • Amazon EBS CSI add-on 을 생성합니다.

    eksctl create addon --name aws-ebs-csi-driver --cluster ${AWS_CLUSTER_NAME} --service-account-role-arn ${EBS_CSI_SA_ROLE_ARN} --force
  • ebs-csi-controller가 생성되었는지 확인합니다.

    kubectl get deploy -n kube-system

    출력예시

    NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
    ebs-csi-controller 2/2 2 2 30s


5. Amazon EFS CSI Driver 설치하기 (Edge Conductor를 On-premise에 설치할 경우 건너뜁니다.)

참고 페이지 : https://docs.aws.amazon.com/eks/latest/userguide/efs-csi.html

  • 아래 명령어를 설정 합니다.

    export EFS_CSI_SA_ROLE_NAME=role-efs-csidriver-${AWS_CLUSTER_NAME}
    export EFS_CSI_SA_ROLE_ARN=arn:aws:iam::${AWS_ACCOUNT_ID}:role/${EFS_CSI_SA_ROLE_NAME}
  • EFS CSI Driver를 관리할 Service Account IAM을 생성합니다.

    eksctl create iamserviceaccount \
    --name efs-csi-controller-sa \
    --namespace kube-system \
    --cluster ${AWS_CLUSTER_NAME} \
    --role-name ${EFS_CSI_SA_ROLE_NAME} \
    --role-only \
    --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEFSCSIDriverPolicy \
    --override-existing-serviceaccounts \
    --approve
  • EFS Trust policy를 확인하고 IAM policy를 업데이트 합니다.

    TRUST_POLICY=$(aws iam get-role --role-name ${EFS_CSI_SA_ROLE_NAME} --query 'Role.AssumeRolePolicyDocument' | \
    sed -e 's/efs-csi-controller-sa/efs-csi-*/' -e 's/StringEquals/StringLike/')
    aws iam update-assume-role-policy --role-name ${EFS_CSI_SA_ROLE_NAME} --policy-document "${TRUST_POLICY}"
  • Amazon EFS CSI add-on 을 생성합니다.

    eksctl create addon --name aws-efs-csi-driver --cluster ${AWS_CLUSTER_NAME} --service-account-role-arn ${EFS_CSI_SA_ROLE_ARN} --force
  • efs-csi-controller가 생성되었는지 확인합니다.

    kubectl get deploy -n kube-system

    출력예시

    NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
    efs-csi-controller 2/2 2 2 30s


6. NodeGroup 생성하기

  • 생성된 클러스터에 AI Conductor 운영을 위한 노드그룹을 추가합니다.

    • 노드그룹 생성에 관한 자세한 가이드는 AI Conductor Manage NodeGroup를 참조하세요
    • 노드그룹의 생성을 정의한 nodegroup-aicond.yaml 을 생성합니다.
    [Expand nodegroup-aicond.yaml]
    cat <<EOT > nodegroup-aicond.yaml
    apiVersion: eksctl.io/v1alpha5
    kind: ClusterConfig

    metadata:
    name: ${AWS_CLUSTER_NAME}
    region: ${AWS_DEFAULT_REGION}
    availabilityZones: ["${AWS_DEFAULT_REGION}a", "${AWS_DEFAULT_REGION}c"]
    managedNodeGroups:
    - name: 'ng-${AWS_DEFAULT_REGION_ALIAS}-aicond-${INFRA_NAME}-controller'
    instanceType: m5.2xlarge
    # autoscaling
    minSize: 1
    maxSize: 3
    desiredCapacity: 2
    # volume
    volumeType: gp2
    volumeSize: 200
    labels: {aic-role: controller}
    propagateASGTags: true
    iam:
    withAddonPolicies:
    autoScaler: true
    EOT
    • 클러스터에 노드그룹을 추가합니다.
    eksctl create nodegroup --config-file=nodegroup-aicond.yaml
  • Edge Conductor가 on premise로 설치된 경우 건너뜁니다.

    • 생성된 클러스터에 Edge Conductor 운영을 위한 노드그룹을 추가합니다.

      • 노드그룹의 생성을 정의한 nodegroup-edgecond.yaml 을 생성합니다.
      [Expand nodegroup-edgecond.yaml]
      cat <<EOT > nodegroup-edgecond.yaml
      apiVersion: eksctl.io/v1alpha5
      kind: ClusterConfig

      metadata:
      name: ${AWS_CLUSTER_NAME}
      region: ${AWS_DEFAULT_REGION}
      availabilityZones: ["${AWS_DEFAULT_REGION}a", "${AWS_DEFAULT_REGION}c"]
      managedNodeGroups:
      - name: 'ng-${AWS_DEFAULT_REGION_ALIAS}-edgecond-${INFRA_NAME}-controller'
      instanceType: m5.2xlarge
      # autoscaling
      minSize: 1
      maxSize: 3
      desiredCapacity: 2
      # volume
      volumeType: gp2
      volumeSize: 200
      labels: {edgecond-role: 'ng-${AWS_DEFAULT_REGION_ALIAS}-edgecond-${INFRA_NAME}'}
      propagateASGTags: true
      iam:
      withAddonPolicies:
      autoScaler: true
      EOT
      • 클러스터에 노드그룹을 추가합니다.
      eksctl create nodegroup --config-file=nodegroup-edgecond.yaml