Search
moon
sun

HPA

Metric Server

•
k8s 클러스터 리소스 사용량 데이터를 집계하는 역할
•
kubelet에서 리소스 메트릭 (예. 컨테이너의 CPU 및 메모리 메트릭)을 수집하고 이를 Metrics API를 통해 apiserver에 노출하여 Horizontal Pod Autoscaler 및 Vertical Pod Autoscaler에서 활용
•
클러스터 내에 Deployment 형태로 설치
Metric Server Install
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Shell
복사

Horizontal Pod Autoscaler (HPA)

•
Deployment / Replicaset의 레플리카 수를 CPU / 메모리 부하 등에 따라 자동으로 스케일 해주는 오브젝트
•
Pod의 Resource Requests를 기준으로 동작
•
metric server에서 가져온 각 파드의 1분 평균 값
Horizontal Pod Autoscaler의 기준
•
cpu (resource)
•
memory (resource)
•
packets-per-second (pod)
•
request-per-second (ingress)
Horizontal Pod Autoscaler와 Cluster Autoscaler의 상호작용
•
컨테이너(Pod)의 로드가 증가하면 HPA는 우선 클러스터에 충분한 공간이 있든 없든 새 replica를 생성
•
리소스가 충분하지 않은 경우 CA는 HPA에서 생성한 Pod가 실행될 노드를 새로 기동
•
반대로 로드가 감소되면 HPA는 일부 replica를 삭제하고, 결과적으로 활용되지 않는 노드가 생기면 CA가 이러한 노드를 종료
•
Deployment 딴에서 CPU 요청과 제한을 모두 설정하여 리소스 사용량을 명확히 해야함.
# 예시 yaml 파일 apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment namespace: dev-ns spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 resources: requests: cpu: "100m" limits: cpu: "200m"
YAML
복사
Basic
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: <HPA Name> namespace: <Namespace> spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: <Deployment Name> minReplicas: <Number> maxReplicas: <Number> metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: <Number>
YAML
복사
Segmentation
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: <HPA Name> namespace: <Namespace> spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: <Deployment Name> minReplicas: <Number> maxReplicas: <Number> behavior: scaleUp: stabilizationWindowSeconds: <Number> policies: - type: Pods value: <Number> periodSeconds: <Number> scaleDown: stabilizationWindowSeconds: 1<Number> policies: - type: Pods value: <Number> periodSeconds: <Number> metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: <Number> - type: Resource resource: name: memory target: type: Utilization averageValue: <Number>Mi
YAML
복사
kubectl apply -f hpa.yaml
Shell
복사