티스토리 뷰

  1. VPC 생성
  2. Private Cluster 생성
  3. Autoscaling 설정
  4. Istio 설치

 

Node 및 Pod의 오토스케일링을 설정해봅시다.

 

1. Node의 오토스케일링

 

Cluster생성할 때 이미 EC2 Auto Scaling 그룹이 생성되었지만

쿠버네티스에서 Auto Scaling 그룹에 명령을 내리기 위한 설정이 필요합니다.

공식문서

 

cluster-autoscaler를 생성합니다.

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/aws/examples/cluster-autoscaler-autodiscover.yaml

 

cluster-autoscaler.kubernetes.io/safe-to-evict="false" annotation을 추가합니다.

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

 

<YOUR CLUSTER NAME>을 찾아서 클러스터 명을 입력하고 저장합니다.

$ kubectl -n kube-system edit deploy/cluster-autoscaler

 

이제 노드 오토스케일링 설정을 모두 끝이났습니다. 간단히 테스트를 해보겠습니다.

 

 

$ vi test-autoscaler.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-autoscaler
spec:
  replicas: 10
  selector:
    matchLabels:
      service: nginx
      app: nginx
  template:
    metadata:
      labels:
        service: nginx
        app: nginx
    spec:
      containers:
      - image: nginx
        name: test-autoscaler
        resources:
          limits:
            cpu: 300m
            memory: 512Mi
          requests:
            cpu: 300m
            memory: 512Mi
$ kubectl apply -f test-autoscaler.yaml

Pending 상태의 Pod를 확인할 수 있습니다. 노드를 Scale-out한 뒤 Pod가 생성될 것입니다.

 

Worker Node가 추가되고 있습니다.

 

잠시 후 모든 Pod가 Running상태가 된 것을 확인할 수 있습니다.

 

 

2. Pod의 오토스케일링

 

먼저 Metrics Server 를 설치해야 합니다. 이것은 각 파드의 CPU/Memory 이용현황을 수집합니다.

hpa가 이것을 기준으로 pod를 확장할 지 축소할 지 판단합니다.

$ kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

 

hpa 테스트용 샘플 deployment를 생성합니다. 참고

$ kubectl apply -f https://k8s.io/examples/application/php-apache.yaml
$ kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10 # cpu 사용량 50%를 넘어가면 최대 10개 까지 늘어납니다.

 

php-apache pod에 부하를 줍니다.

$ kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"

 

1분정도 기다린 후 다른 터미널로 bastion인스턴스에 접속해 hpa를 확인해봅시다.

타겟의 cpu 사용량이 50%를 초과한 것을 확인할 수 있습니다.

$ kubectl get hpa

 

pod가 증가한 것을 확인할 수 있습니다.

부하를 주는 Pod는 Ctrl + C 로 종료할 수 있습니다.

 

 

3. clean up

$ kubectl delete -f https://k8s.io/examples/application/php-apache.yaml
$ kubectl delete hpa php-apache
$ kubectl delete -f test-autoscaler.yaml

Scale-out은 즉시, Scale-in은 천천히 일어납니다.

pod를 삭제해도 노드는 즉시 제거되지 않습니다.

약 10분~20분이 지나면 pod 및 node가 줄어든 것(Scale-in)을 확인할 수 있습니다.

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함