📂
Amazon EKS
  • Amazon EKS
  • 워크스페이스 생성하기
    • Cloud9 IDE 환경 구성
    • IAM 역할 생성
    • SSH & CMK Key 생성하기
  • EKS 클러스터 구축
    • EKS 클러스터 만들기
  • 쿠버네티스 대시보드 배포
    • Kubernetes 공식 대시보드 배포
  • 마이크로서비스 배포
    • 예제 애플리케이션 배포
    • 서비스 스케일(Scaling)
    • 애플리케이션 정리하기
  • 애플리케이션 배포 - Helm
    • HELM 설치
    • Helm으로 Nginx 배포
    • Helm을 사용하여 마이크로서비스 배포
    • 정리하기
  • 리소스 관리 - POD 배치
    • NodeSelector
    • Affinity and Anti-affinity
    • 더 실용적인 사용 사례
    • 정리하기
  • 리소스 관리 - Health Checks
    • Liveness 프로브 구성
    • Readiness 프로브 구성
    • 정리하기
  • 리소스 관리 - AutoScaling
    • HPA 구성하기
    • CA 구성하기
    • 정리하기
  • 네트워킹 - 서비스 노출
    • 서비스와 애플리케이션 연결
    • 서비스에 접근하기
    • 서비스 노출
    • Ingress
    • Ingress Controller
    • 정리하기
  • 네트워크 - Calico 정책
    • Calico 설치하기
    • Stars Policy Demo
    • 정리하기
  • Updating 권한설정 - RBAC
    • 테스트 POD 설치
    • 사용자 생성 및 맵핑
    • 역할과 바인딩
    • 정리하기
  • Updating 권한설정 - IAM 그룹
    • IAM Role, Group & User 생성하기
    • RBAC 설정하기
    • EKS 엑세스 테스트
    • 정리하기
  • Updating 권한설정 - Service account
    • OIDC 자격 증명 공급자 생성하기
    • IAM 역할 생성 및 지정
    • 샘플 POD 배포
    • 정리하기
  • Updating - 네트워크 - POD Security Group
    • SG 생성하기
    • RDS 생성하기
    • CNI 구성하기
    • SG 정책
    • Pod 배포하기
    • 정리하기
  • Updating - 모니터링 - Prometheus and Grafana
    • Prometheus 배포하기
    • Grafana 배포하기
    • 정리하기(Optional)
  • Updating 모니터링 - X-Ray
    • X-Ray DaemonSet 배포하기
    • 샘플 마이크로서비스 배포
    • X-Ray console 확인
    • 정리하기(Optional)
  • Updating 모니터링 - Container Insights
    • 사전 준비
    • Container Insights 구성하기
    • 부하 테스트
    • Container Insights 확인하기
    • 정리하기(Optional)
  • Updating CD - Gitops with Flux
    • 사전 준비
    • Codepipeline
    • EKS에 배포
    • 정리하기
  • Updating Argo Rollouts
  • Updating Service Mesh - AWS App Mesh
    • Fargate 및 OBSERVABILITY 구성
    • Product Catalog App 배포
    • APP MESH 설치
    • Porting to APP MESH
    • Virtual Gateway 구성
    • Canary
    • Observability
  • Updating 버전 업그레이드 - EKS Cluster
    • Upgrade EKS control Plane
    • Upgrade EKS CORE ADD-ONs
    • Upgrade Managed Node Group
Powered by GitBook
On this page
  • 1. ASG 구성하기
  • 2. IAM roles 생성하기
  • 3. CA 배포하기
  • 4. 샘플 애플리케이션 배포하기
  • 5. ReplicaSet 확장하기

Was this helpful?

  1. 리소스 관리 - AutoScaling

CA 구성하기

Cluster Autoscaler (CA) 구성

PreviousHPA 구성하기Next정리하기

Last updated 3 years ago

Was this helpful?

AWS용 Cluster Autoscaler는 Auto Scaling 그룹(ASG)과의 통합을 제공합니다. 이를 통해 사용자는 다음 네 가지 배포 옵션 중에서 선택할 수 있습니다.

  • 1개의 Auto Scaling 그룹

  • 여러개의 Auto Scaling 그룹

  • Auto-Discovery

  • Control-plane 노드 설정

1. ASG 구성하기

최소, 최대 및 원하는 용량을 설정하여 Auto Scaling 그룹의 크기를 구성합니다. 클러스터를 만들 때 이러한 설정을 3으로 설정 했습니다.

aws autoscaling \
    describe-auto-scaling-groups \
    --query "AutoScalingGroups[? Tags[? (Key=='eks:cluster-name') && Value=='eksworkshop-eksctl']].[AutoScalingGroupName, MinSize, MaxSize,DesiredCapacity]" \
    --output table
    

이제 최대 용량을 인스턴스 4개로 늘립니다.

EKS 노드 그룹의 AutoScalingGroup의 이름을 확인하고 최대 용량을 4개로 증가 시킵니다. 그리고 AutoScalingGroup의 값을 다시 확인 합니다.

# we need the ASG name
export ASG_NAME=$(aws autoscaling describe-auto-scaling-groups --query "AutoScalingGroups[? Tags[? (Key=='eks:cluster-name') && Value=='eksworkshop-eksctl']].AutoScalingGroupName" --output text)

# increase max capacity up to 4
aws autoscaling \
    update-auto-scaling-group \
    --auto-scaling-group-name ${ASG_NAME} \
    --min-size 3 \
    --desired-capacity 3 \
    --max-size 4

# Check new values
aws autoscaling \
    describe-auto-scaling-groups \
    --query "AutoScalingGroups[? Tags[? (Key=='eks:cluster-name') && Value=='eksworkshop-eksctl']].[AutoScalingGroupName, MinSize, MaxSize,DesiredCapacity]" \
    --output table
    

2. IAM roles 생성하기

클러스터의 서비스 계정에 대한 IAM 역할 활성화합니다.

eksctl utils associate-iam-oidc-provider \
    --cluster eksworkshop-eksctl \
    --approve
    

CA 파드가 Auto Scaling 그룹과 상호 작용할 수 있도록 서비스 계정에 대한 IAM 정책을 만듭니다.

mkdir ~/environment/cluster-autoscaler

cat <<EoF > ~/environment/cluster-autoscaler/k8s-asg-policy.json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "autoscaling:DescribeAutoScalingGroups",
                "autoscaling:DescribeAutoScalingInstances",
                "autoscaling:DescribeLaunchConfigurations",
                "autoscaling:DescribeTags",
                "autoscaling:SetDesiredCapacity",
                "autoscaling:TerminateInstanceInAutoScalingGroup",
                "ec2:DescribeLaunchTemplateVersions"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
EoF
aws iam create-policy   \
  --policy-name k8s-asg-policy \
  --policy-document file://~/environment/cluster-autoscaler/k8s-asg-policy.json
  

마지막으로 kube-system namespace에서 cluster-autoscaler 서비스 계정에 대한 IAM 역할을 생성합니다. Account ID가 설정되어 있지 않다면 다음의 명령을 실행한 후 IAM 역할을 생성합니다.

ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
eksctl create iamserviceaccount \
    --name cluster-autoscaler \
    --namespace kube-system \
    --cluster eksworkshop-eksctl \
    --attach-policy-arn "arn:aws:iam::${ACCOUNT_ID}:policy/k8s-asg-policy" \
    --approve \
    --override-existing-serviceaccounts
    

IAM 역할의 ARN이 있는 서비스 계정이 Annotation 되었는지 확인합니다.

kubectl -n kube-system describe sa cluster-autoscaler

3. CA 배포하기

다음 명령어를 사용하여 Cluster Autoscaler를 다운로드 후 클러스터에 배포 합니다.

curl https://www.eksworkshop.com/beginner/080_scaling/deploy_ca.files/cluster-autoscaler-autodiscover.yaml -o ~/environment/cluster-autoscaler-autodiscover.yaml
kubectl apply -f ~/environment/cluster-autoscaler-autodiscover.yaml

CA가 자체 파드가 실행중인 노드를 제거하지 못하도록 하기 위해 다음 명령을 사용하여 배포에 cluster-autoscaler.kubernetes.io/safe-to-evict annotation을 추가 합니다.

kubectl -n kube-system \
    annotate deployment.apps/cluster-autoscaler \
    cluster-autoscaler.kubernetes.io/safe-to-evict="false"
    

마지막으로 autoscaler 이미지를 업데이트 합니다.

# we need to retrieve the latest docker image available for our EKS version
export K8S_VERSION=$(kubectl version --short | grep 'Server Version:' | sed 's/[^0-9.]*\([0-9.]*\).*/\1/' | cut -d. -f1,2)
export AUTOSCALER_VERSION=$(curl -s "https://api.github.com/repos/kubernetes/autoscaler/releases" | grep '"tag_name":' | sed -s 's/.*-\([0-9][0-9\.]*\).*/\1/' | grep -m1 ${K8S_VERSION})

kubectl -n kube-system \
    set image deployment.apps/cluster-autoscaler \
    cluster-autoscaler=us.gcr.io/k8s-artifacts-prod/autoscaling/cluster-autoscaler:v${AUTOSCALER_VERSION}
    

로그를 확인 합니다.

kubectl -n kube-system logs -f deployment/cluster-autoscaler

4. 샘플 애플리케이션 배포하기

예제 애플리케이션 nginx를 파드의 1 ReplicaSet으로 배포합니다. 그리고 deployments를 확인합니다.

cat <<EoF> ~/environment/cluster-autoscaler/nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-to-scaleout
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        service: nginx
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx-to-scaleout
        resources:
          limits:
            cpu: 500m
            memory: 512Mi
          requests:
            cpu: 500m
            memory: 512Mi
EoF
kubectl apply -f ~/environment/cluster-autoscaler/nginx.yaml
kubectl get deployment/nginx-to-scaleout

5. ReplicaSet 확장하기

ReplicaSet를 10으로 확장 하겠습니다.

kubectl scale --replicas=10 deployment/nginx-to-scaleout

일부 포드는 Pending 상태가 되어 클러스터 autoscaler가 EC2 노드을 확장 하도록 트리거 합니다.

kubectl get pods -l app=nginx -o wide --watch

클러스터 autoscaler 로그를 확인합니다.

kubectl -n kube-system logs -f deployment/cluster-autoscaler

아래와 유사한 클러스터 autoscaler 처리 이벤트가 표시 됩니다.

또는 kubectl을 사용 합니다.

kubectl get nodes

다음과 같이 출력 됩니다.

Amazon EKS 클러스터의 service account에 대한 IAM 역할을 사용하려면, IAM 역할을 과 연결해야 합니다. 그러면 해당 service account을 사용하는 모든 파드의 컨테이너에 AWS 권한을 제공 할 수 있습니다. 이 기능을 사용하면 해당 노드의 파드가 AWS API를 호출 할 수 있도록 하여 더 이상 노드 IAM 역할에 확장 권한을 제공 할 필요가 없습니다.

에서 Auto Scaling 그룹이 수요를 충족하도록 확장되는지 확인 합니다. 이 작업은 몇 분 정도 걸릴 수 있습니다. 명령 줄에서 파드 배포를 수행 할 수도 있습니다. 노드가 확장됨에 따라 파드가 pending에서 running으로 전환 되는 것을 확인 할 수도 있습니다.

쿠버네티스 서비스 계정
EC2 AWS Management Console