DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Thomas Kim
Thomas Kim

Posted on • Updated on

AWS EKS 의 Cluster Autoscaler μ„€μ •

https://docs.aws.amazon.com/eks/latest/userguide/autoscaling.html λ₯Ό μ°Έκ³ ν•˜μ—¬ μ„€μ •

VPA 및 Goldilocksλ₯Ό 톡해 Kubernetes 의 resource request, limit 섀정을 μ™„λ£Œν•˜κ³  HPAλ₯Ό 톡해 Podλ₯Ό 늘리고 κ²°κ΅­ Node의 μžμ›μ΄ λΆ€μ‘±ν•˜λ©΄ Cluster Autoscaler λ₯Ό 톡해 Nodeλ₯Ό μΆ”κ°€λ‘œ μƒμ„±ν•˜κ²Œ λœλ‹€. Cluster Autoscaler λŠ” Cloud Vendor λ§ˆλ‹€ μ„€μ • 방법이 λ‹€λ₯΄λ‹€

AWS μ—μ„œ eksctl 을 μ΄μš©ν•˜μ—¬ kubernetes cluster λ₯Ό λ§Œλ“€μ—ˆλ‹€λ©΄ EKS documentation 의 Prerequisites 에 μžˆλŠ” λ‚΄μš©μ€ λͺ¨λ‘ μ™„λ£Œ 된 μƒνƒœμ΄λ‹€. κ·Έ μ•„λž˜λΆ€ν„° μ°¨λ‘€λŒ€λ‘œ direction을 따라 μ„€μ •ν•˜λ©΄ μ‰½κ²Œ Cluster Autoscaler λ₯Ό μ„€μΉ˜ν•  수 μžˆλ‹€.

IAM Policy 및 role 생성

Cluster Autoscaler κ°€ IAM role 을 μ‚¬μš©ν•˜κΈ° μœ„ν•΄ ν•„μš”ν•œ κΆŒν•œμ„ μ£ΌκΈ° μœ„ν•΄ IAM Policy 생성이 ν•„μš”ν•˜λ‹€.

IAM Policy 생성

  1. μ•„λž˜μ™€ 같이 cluster-autoscaler-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"
        }
    ]
    }
    
  2. μ•„λž˜μ™€ 같이 policy λ₯Ό μƒμ„±ν•œλ‹€.

    aws iam create-policy \
    --policy-name AmazonEKSClusterAutoscalerPolicy \
    --policy-document file://cluster-autoscaler-policy.json
    

μœ„ command λ₯Ό μ‹€ν–‰ν•˜κ³  λ‚˜μ˜€λŠ” output μ—μ„œ Amazon Resource Name (ARN)을 μ•„λž˜μ—μ„œ μ‚¬μš©ν•΄μ•Ό ν•œλ‹€.

IAM role 생성

μ•„λž˜μ™€ 같이 eksctl을 μ‚¬μš©ν•˜μ—¬ IAM role을 생성할 수 μžˆλ‹€.

eksctl create iamserviceaccount \
  --cluster=eks-demo \
  --namespace=kube-system \
  --name=cluster-autoscaler \
  --attach-policy-arn=<μœ„μ—μ„œ μƒμ„±ν•œ policy의 arn> \
  --override-existing-serviceaccounts \
  --approve
Enter fullscreen mode Exit fullscreen mode

Deploy Cluster Autoscaler

  1. μš°μ„  Cluster Autoscaler YALM νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œ ν•œλ‹€.

    curl -o cluster-autoscaler-autodiscover.yaml https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml
    
  2. YAML νŒŒμΌμ„ μ—΄μ–΄μ„œ <YOUR CLUSTER NAME> 을 μ°Ύμ•„μ„œ eks-demo 둜 replace ν•œλ‹€.

  3. 그리고 μ μš©ν•œλ‹€.

    kubectl apply -f cluster-autoscaler-autodiscover.yaml
    


    ℹ️ λ¬Έμ„œμ—λŠ” 이 λ‹€μŒμ— service account을 annotate ν•˜λŠ” 뢀뢄이 μžˆλŠ”λ° 확인해보면 이미 λ˜μ–΄μžˆλ‹€

  4. cluster-autoscaler.kubernetes.io.safe-to-evictλ₯Ό μΆ”κ°€ν•˜κΈ° μœ„ν•΄ μ•„λž˜μ™€ 같이 patch ν•œλ‹€.

    kubectl patch deployment cluster-autoscaler \
    -n kube-system \
    -p '{"spec":{"template":{"metadata":{"annotations":{"cluster-autoscaler.kubernetes.io/safe-to-evict": "false"}}}}}'
    
  5. 그리고 cluster-autoscaler deploymentλ₯Ό μˆ˜μ •ν•œλ‹€.

    kubectl -n kube-system edit deployment.apps/cluster-autoscaler
    


    <YOUR CLUSTER NAME> 을 eks-demo 둜 μˆ˜μ •ν•˜κ³  container command 에 --balance-similar-node-groups 와 --skip-nodes-with-system-pods=false λ₯Ό μΆ”κ°€ν•˜μ—¬ μ•„λž˜μ™€ 같이 μˆ˜μ •ν•œλ‹€.

    spec:
      containers:
      - command
        - ./cluster-autoscaler
        - --v=4
        - --stderrthreshold=info
        - --cloud-provider=aws
        - --skip-nodes-with-local-storage=false
        - --expander=least-waste
        - --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/<YOUR CLUSTER NAME>
        - --balance-similar-node-groups
        - --skip-nodes-with-system-pods=false
    
  6. Cluster Autoscaler release νŽ˜μ΄μ§€λ₯Ό μ—΄μ–΄μ„œ μ„€μΉ˜ν•œ kubernetes λ²„μ „μ˜ μ΅œμ‹  cluster autoscaler λ₯Ό ν™•μΈν•œλ‹€.

  7. μœ„μ—μ„œ ν™•μΈν•œ 버전을 μ•„λž˜μ™€ 같이 μ μš©ν•œλ‹€. (v1.21.2λ₯Ό κ°€μ •ν•œλ‹€.)

    kubectl set image deployment cluster-autoscaler \
    -n kube-system \
    cluster-autoscaler=k8s.gcr.io/autoscaling/cluster-autoscaler:v1.21.2
    

Cluster Autoscaler 둜그 확인

Cluster Autoscaler λ₯Ό deploy ν•œ 후에 둜그λ₯Ό ν™•μΈν•˜μ—¬ μ œλŒ€λ‘œ λ™μž‘ν•˜λŠ”μ§€ ν™•μΈν•œλ‹€.

kubectl -n kube-system logs -f deployment.apps/cluster-autoscaler
Enter fullscreen mode Exit fullscreen mode

βœ‹ μ΅œκ·Όμ—λŠ” Karpenterκ°€ λ‚˜μ™€μ„œ Cluster Autoscaler λŒ€μ‹  이걸 ν™œμš© ν•  μˆ˜λ„ μžˆλ‹€.

Top comments (0)

🌱 DEV runs on 100% open source code that we started called Forem.

Β 
You can contribute to the codebase or host your own.