brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Jul 02. 2021

EKS 1탄-7. EKS 클러스터 오토스케일링-7/7

실습 1탄 = 7/7

클러스터 오토스케일러(AutoScaling)  = CA  실습해보자

EC2 NODE 서버를 증가시키는 것이다. = 물리 서버를 증가시키는 것이다.


<1> Amazon EKS 클러스터 AutoScaling 설정하기

<2> 확인

<3> node 수 증가 감소 = 물리서버 증가 감소해보기 (실습)

<4> 삭제 전 Workshop 해보기

<5> EKS 삭제

<6> 다음  - EKS 2탄 



<1> Amazon EKS 클러스터 AutoScaling 설정하기


1

# EC2 접속


export AWS_REGION=ap-northeast-2


echo ${AWS_REGION}


리전 변경 필요시

export AWS_REGION=us-east-1

export AWS_REGION=us-east-2

export AWS_REGION=us-west-1

export AWS_REGION=us-west-2


US East (N. Virginia)us-east-1

US East (Ohio)us-east-2

US West (N. California)us-west-1

US West (Oregon)us-west-2


echo ${AWS_REGION}



2

# Auto Scaling Group 설정 확인



ClusterName=$CLUSTER_NAME

RegionName=$AWS_DEFAULT_REGION


echo ${ClusterName}


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



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


-------------------------------------------------------------

|                 DescribeAutoScalingGroups                 |

+-------------------------------------------+----+----+-----+

|  eks-fabd0a31-606c-4fea-80f1-b2ffd868a937 |  3 |  3 |  3  |

+-------------------------------------------+----+----+-----+



3

콘솔 > EC2 > Auto Scaling Group > details  > 편집 >  용량을 늘려준다.

Maximum capacity  3->  7



4

예제 다운로드

wget https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml



5

vi cluster-autoscaler-autodiscover.yaml


변경전

 - --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/${ClusterName}


...          

         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/eks-demo

 ...

// 클러스터 이름을 eks-demo로 수정해야 한다!!!




<2> 확인


1

다른 터미널에서 모니터링


watch -d kubectl get nodes,ns,deploy,rs,pod,svc


watch -d 'kubectl get pods,rs,deploy -o wide'



2

k-ops-view로 확인


EC2 > LB > Classic LB DNS로 웹 접속




변경전




4

kubectl apply -f cluster-autoscaler-autodiscover.yaml



5

kubectl get nodes -w


NAME                             STATUS   ROLES    AGE   VERSION

ip-192-168-4-245.ec2.internal    Ready    <none>   13d   v1.19.6-eks-49a6c0

ip-192-168-49-221.ec2.internal   Ready    <none>   13d   v1.19.6-eks-49a6c0

ip-192-168-60-100.ec2.internal   Ready    <none>   13d   v1.19.6-eks-49a6c0



kubectl get rs -w


NAME                            DESIRED   CURRENT   READY   AGE

demo-flask-backend-669cb864d8   1         1         0       12d

demo-flask-backend-7d5fdf8bcb   1         1         0       12d

kube-ops-view-894bc75fb         1         1         1       12d



kubectl get deploy -w


NAME                 READY   UP-TO-DATE   AVAILABLE   AGE

demo-flask-backend   0/1     1            0           12d

kube-ops-view        1/1     1            1           12d



6

kubectl create deployment autoscaler-demo --image=nginx

kubectl scale deployment autoscaler-demo --replicas=20

kubectl get deployment autoscaler-demo --watch



kubectl create deployment autoscaler-demo --image=nginx

deployment.apps/autoscaler-demo created



kubectl scale deployment autoscaler-demo --replicas=20

deployment.apps/autoscaler-demo scaled



kubectl get deployment autoscaler-demo --watch

NAME              READY    UP-TO-DATE   AVAILABLE   AGE

autoscaler-demo   65/100   100          65          90s



7

워커노드 scale- out 확인


k-ops-view로 확인


변경전


변경후



8

디플로이먼트 지우기

kubectl delete deployment autoscaler-demo


워커노드 scale- in 확인





<3> node 수 증가 감소 = 물리서버 증가 감소해보기 (실습)


 물리장비를 4대로 늘렸다가 다시 1대로 줄여보자.



1

# 터미널2


watch -d kubectl get svc,nodes -A



2

service/kube-ops-view 웹브라우저료 접속 : 8080




3

# 서버 4대로 늘려보자

# group name 콘솔에서 확인후 적용 



export CLUSTER_NAME=eks-demo


eksctl scale nodegroup --cluster $CLUSTER_NAME --name node-group --nodes 4 --nodes-min 4 --nodes-max 6




4

#  줄어 드는데 시간이 좀 걸린다.  10분

# 1대로 줄여 보자


eksctl scale nodegroup --cluster $CLUSTER_NAME --name node-group --nodes 1 --nodes-min 1 --nodes-max 6






<4> 삭제 전 Workshop 해보기


1

한글버전


https://catalog.us-east-1.prod.workshops.aws/workshops/9c0aa9ab-90a9-44a6-abe1-8dff360ae428/ko-KR


2

영문 버전


https://catalog.us-east-1.prod.workshops.aws/workshops/9c0aa9ab-90a9-44a6-abe1-8dff360ae428/en-US



<5>  EKS 삭제


1

Cloudformation에서 삭제

EC2 삭제 확인

로드밸런서 삭제 확인




2

수동 삭제 ?


1) EC2 > AutoScaling group  > 삭제


필수!!

삭제하지 않으면 EC2를 삭제해도 다시 자동 생성된다.




2) 노드 삭제

EKS > Clusters > Compute > Node 삭제



3) 클러스터 삭제

EKS > Clusters  삭제



4) LB 삭제



5)

EC2 >  삭제 되었는지 확인




6)

로드밸러서 LB도 삭제


7) 

Cloudwatch logs 삭제






3

#   (EKS 실습 1탄)  애플리케이션  다시보기


https://brunch.co.kr/@topasvga/1883



EKS 1탄~ 11탄 전체 다시 보기

https://brunch.co.kr/@topasvga/1679




<6> 다음


 EKS 2탄 


https://brunch.co.kr/@topasvga/1692



브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari