Horizontal Pod Autoscaler (HPA)๋ Kubernetes ํ๊ฒฝ์์ Pod์ ์๋ฅผ ์๋์ผ๋ก ์กฐ์ ํ์ฌ ํด๋ฌ์คํฐ์ ๋ฆฌ์์ค ์ฌ์ฉ๋ฅ ์ ์ต์ ํํ๋ ๊ธฐ๋ฅ์ด๋ค. ์ด๋ฅผ ์ค๋ช
ํ ๋ ์ด๋ค ๊ด์ ์ผ๋ก ์ ๊ทผํ ์ง๋ ์ํฉ์ ๋ฐ๋ผ ๋ค๋ฆ
๋๋ค. ๊ฐ ๊ด์ ์์์ ๋ด์ฉ์ ์ดํด๋ณด์.
Kubernetes ๊ด์ ์์ HPA๋ ๋ฆฌ์์ค ์ฌ์ฉ๋ฅ ์ ๊ธฐ๋ฐํด Pod์ ์๋ฅผ ์กฐ์ ํ๋ Kubernetes ๊ฐ์ฒด์ด๋ค. CPU ๋ฐ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ฅ ๋ฟ๋ง ์๋๋ผ ์ปค์คํ
๋ฉํธ๋ฆญ์ ํตํด์๋ ์ค์ผ์ผ๋ง์ ์ง์ํ๋ค.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
annotations:
meta.helm.sh/release-name: staging
meta.helm.sh/release-namespace: nestjs-boilerplate-config-variable
creationTimestamp: "2024-05-09T01:57:58Z"
labels:
app: staging
app.kubernetes.io/instance: staging
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: staging
chart: auto-deploy-app-2.80.1
helm.sh/chart: auto-deploy-app-2.80.1
heritage: Helm
release: staging
name: staging-auto-deploy
namespace: nestjs-boilerplate-config-variable
resourceVersion: "39297159"
uid: d5d40b25-453f-43f2-a3d3-35e5d174fdf9
spec:
maxReplicas: 10
metrics:
- resource:
name: cpu
target:
averageUtilization: 70
type: Utilization
type: Resource
minReplicas: 3
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: staging
status:
conditions:
- lastTransitionTime: "2024-05-09T01:58:13Z"
message: recommended size matches current size
reason: ReadyForNewScale
status: "True"
type: AbleToScale
- lastTransitionTime: "2024-05-09T01:58:29Z"
message: the HPA was able to successfully calculate a replica count from cpu resource
utilization (percentage of request)
reason: ValidMetricFound
status: "True"
type: ScalingActive
- lastTransitionTime: "2024-05-09T04:49:43Z"
message: the desired replica count is less than the minimum replica count
reason: TooFewReplicas
status: "True"
type: ScalingLimited
currentMetrics:
- resource:
current:
averageUtilization: 0
averageValue: 1m
name: cpu
type: Resource
currentReplicas: 3
desiredReplicas: 3
lastScaleTime: "2024-05-09T04:44:28Z"
Helm์ ์ฌ์ฉํ๋ฉด HPA ๊ฐ์ฒด๋ฅผ ์ฝ๊ฒ ๊ด๋ฆฌํ ์ ์๋ค. values.yaml
ํ์ผ์ ์ฌ์ฉํด ์ค์ ๊ฐ์ ๋งค๊ฐ๋ณ์ํํ์ฌ ๋ฐ๋ณต์ ์ธ ๋ฐฐํฌ์ ํ์ฉํ ์ ์๋ค.
{{- if and .Values.hpa.enabled .Values.resources.requests -}}
{{- if .Values.hpa.metrics }}
apiVersion: autoscaling/v2
{{- else }}
apiVersion: autoscaling/v1
{{- end }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ template "fullname" . }}
labels:
{{ include "sharedlabels" . | indent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "appname" . }}
minReplicas: {{ .Values.hpa.minReplicas }}
maxReplicas: {{ .Values.hpa.maxReplicas }}
{{- if .Values.hpa.metrics }}
metrics:
{{- toYaml .Values.hpa.metrics | nindent 2 }}
{{- else }}
targetCPUUtilizationPercentage: {{ .Values.hpa.targetCPUUtilizationPercentage }}
{{- end }}
{{- end}}
hpa:
enabled: true
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80