Auto scaling

Yu Sang Min·2025년 6월 10일

CKA

목록 보기
37/110

🔺확장에 관하여

  • Vertical Scale
  • Horizontal Scale

↕️ Vertical Scale

  • 전통적인 인프라에서 CPU, Memory(리소스)의 확장

↔️ Horizontal Scale

  • 전통적인 인프라에서 서버(또는 노드)의 확장

#💡 쿠버네티스 환경에선?

↕️ Cluster Autoscaler (노드 자동 스케일)

↔️ Pod Scaling

  • Horizontal Pod Autoscaler (HPA)
  • Vertical Pod Autoscaler (VPA)

💡 Scaling a workload the manual way (수동 워크로드 확장 방법)

$ vi my-app.yaml
spec:
  replicas: 1
<중략>…
    spec:
      containers:
      - name: my-app
         image: nginx
         resources:
           requests:
             cpu: “250m”
           limits:
             cpu: “500m”

$ kubectl top pod my-app-pod // 리소스 사용량 모니터링
  • CPU 사용량이 임계값인 500m(밀리코어)에 거의 근접했다고 가정
  • scale 커맨드로 파드를 추가한다
$ kubectl scale deployment my-app —replicas=3
  • 이 경우 계속해서 컴퓨터 앞에 앉아 리소스 사용량을 모니터링 해야만 하고
  • 애플리케이션이나 트래픽에 대응하지 못할 수 도 있다

✅ Horizontal Pod Autoscaler (HPA)

  • Observes metrics : 지속적인 모니터링
  • Adds pods: replicaset, deployment, pod, statefulset 의 파드 수를 자동으로 늘리거나 줄인다.
  • Balances thresholds : 임계값의 균형을 맞춘다.
  • Tracks multiple metrics : 메트릭을 추가한다.
# 명령적 방식

$ kubectl autoscale deployment my-app \
      --cpu-percent=50 --min=1 --max=10

$ kubectl get hpa

$ kubectl delete hpa

# 선언적 방식

$ vi my-app-hpa.yaml

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app-hpa
spec:
  scaleTargetRef:          // metric server가 타겟하여 모니터링 하는 개체
    apiVersion: apps/v1
    kind: Deployment
    name: my-app
  minReplicas:1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: env
      target:
        type: Utilization
        averageUtilization: 50

🔎 metrics server

  • 위와같이 내장된 서버를 사용할 수 있고 Custom Metrics Adapter 를 사용할 수도있다.
  • 하지만 모든것은 클러스터 내부에 존재한다.
  • External Adapter (Data Dog, Dynatrace 등) 외부 소스도 참조 가능 (클러스터 외부)
profile
React, Node.js, AWS, Git, Github, Github Action, Docker, K8S

0개의 댓글