Kubernetes 리소스 최적화
오토스케일링으로 인스턴스 수를 조절하는 것만으로는 부족합니다. 각 Pod가 소비하는 리소스를 정밀하게 제어해야 비용과 안정성을 동시에 잡을 수 있습니다.
HPA vs VPA — 언제 무엇을 쓸까
Section titled “HPA vs VPA — 언제 무엇을 쓸까”| HPA (Horizontal) | VPA (Vertical) | |
|---|---|---|
| 동작 | Pod 수를 늘림 | Pod 1개의 CPU/메모리를 늘림 |
| 적합 | Stateless API, 웹 서버 | DB, 캐시, 단일 프로세스 앱 |
| 주의 | 최소 requests 설정 필수 | 재시작 발생 (롤링 업데이트) |
VPA (Vertical Pod Autoscaler) 설정
Section titled “VPA (Vertical Pod Autoscaler) 설정”apiVersion: autoscaling.k8s.io/v1kind: VerticalPodAutoscalermetadata: name: api-vpaspec: targetRef: apiVersion: apps/v1 kind: Deployment name: api-deployment updatePolicy: updateMode: "Auto" # Off / Initial / Auto resourcePolicy: containerPolicies: - containerName: api minAllowed: cpu: "100m" memory: "128Mi" maxAllowed: cpu: "2" memory: "2Gi"updateMode 선택 기준:
Off → 권장값만 표시, 실제 적용 안 함 (분석 단계에서 사용)Initial → Pod 생성 시에만 적용, 실행 중 재시작 없음Auto → 실시간 조정, 재시작 발생 허용Cluster Autoscaler
Section titled “Cluster Autoscaler”노드 수를 자동으로 조절합니다. Pod가 스케줄되지 못하면 노드를 추가하고, 유휴 노드는 제거합니다.
# AWS EKS에서 Cluster Autoscaler 배포 예시apiVersion: apps/v1kind: Deploymentmetadata: name: cluster-autoscaler namespace: kube-systemspec: template: spec: containers: - name: cluster-autoscaler image: registry.k8s.io/autoscaling/cluster-autoscaler:v1.29.0 command: - ./cluster-autoscaler - --cloud-provider=aws - --node-group-auto-discovery=asg:tag=k8s.io/cluster-autoscaler/enabled,k8s.io/cluster-autoscaler/my-cluster - --scale-down-delay-after-add=10m # 추가 후 10분간 제거 보류 - --scale-down-unneeded-time=10m # 10분 유휴 시 제거Resource Quota — 네임스페이스 단위 제한
Section titled “Resource Quota — 네임스페이스 단위 제한”팀별 네임스페이스에 리소스 상한을 설정해 한 팀이 클러스터 전체를 잠식하지 못하게 합니다.
apiVersion: v1kind: ResourceQuotametadata: name: team-quota namespace: team-aspec: hard: requests.cpu: "10" # 팀 전체 CPU 요청 합계 requests.memory: "20Gi" limits.cpu: "20" limits.memory: "40Gi" pods: "50" # 최대 Pod 수LimitRange — Pod 기본값 설정
Section titled “LimitRange — Pod 기본값 설정”requests를 명시하지 않은 Pod에 기본값을 자동 적용합니다.
apiVersion: v1kind: LimitRangemetadata: name: default-limits namespace: team-aspec: limits: - type: Container default: # limits 기본값 cpu: "500m" memory: "256Mi" defaultRequest: # requests 기본값 cpu: "100m" memory: "128Mi" max: # 컨테이너당 최대값 cpu: "2" memory: "2Gi"PodDisruptionBudget — 가용성 보장
Section titled “PodDisruptionBudget — 가용성 보장”Cluster Autoscaler가 노드를 제거할 때 최소 가용 Pod 수를 보장합니다.
apiVersion: policy/v1kind: PodDisruptionBudgetmetadata: name: api-pdbspec: minAvailable: 2 # 항상 최소 2개 Pod 유지 selector: matchLabels: app: api리소스 낭비 찾기
Section titled “리소스 낭비 찾기”# requests 대비 실제 사용률이 낮은 Pod 확인kubectl top pods --all-namespaces | sort -k3 -rn
# VPA 권장값 확인 (updateMode: Off 상태에서)kubectl describe vpa api-vpa실제 사용률이 requests의 30% 미만이면 right-sizing 대상입니다.
이 가이드를 내 서비스에 직접 적용해 보세요.
TestForge 무료 스캔 시작 →