๐Ÿ’ป
DevOps Cookbook
  • Home
    • Meiko DevOps Cookbook
  • Gitlab
    • Tips
      • ์‚ฌ์ „ ์ •์˜๋œ CI/CD ๋ณ€์ˆ˜์˜ ๊ธฐ๋ณธ ์„ธํŠธ
    • ๋”ฅ๋‹ค์ด๋ธŒ Gitlab CI/CD
      • GitLab CI/CD ์‹œ์ž‘ํ•˜๊ธฐ
        • .gitlab-ci.yml ํŒŒ์ผ
        • Runner
        • ํŒŒ์ดํ”„๋ผ์ธ
        • CI/CD ๋ณ€์ˆ˜
        • CI/CD ์ปดํฌ๋„ŒํŠธ
      • CI/CD YAML ๊ตฌ๋ฌธ ์ฐธ์กฐ
    • CI/CD Notifications
      • CI/CD slack notifiaction ๊ตฌ์ถ•์ž‘์—… ๊ฒฐ๊ณผ
  • Kubernetes
    • Persistence Volume
      • play-cluster
    • Ingress
      • Ingress๋ž€
      • ์ˆ˜๋™์œผ๋กœ ingress ๋ฐฐํฌํ•˜๊ธฐ
    • Security
    • HPA
      • hpa troubleshooting history
        • 1. HELM_UPGRADE_VALUES_FILE๋กœ hpa๊ฐ€ ์ถ”๊ฐ€๋˜์ง€ ์•Š๋Š” ์›์ธ
        • 2. targetCPUUtilizationPercentage ๊ณ„์‚ฐ์€ ์–ด๋–ป๊ฒŒ ๋˜๋Š”๊ฐ€
        • 3. helm values์— cpu resource ๋‹จ์œ„๋ฅผ 1๋กœ ํ–ˆ์„ ๋•Œ ์‹ค์ œ ํŒŒ๋“œ์— 1m( 0.001 ) ์ฝ”์–ด๊ฐ€ ๋ถ€์—ฌ๋œ ๊ฒƒ
        • 4. pod cpu resources๊ฐ€ ํ• ๋‹น๋ฐ›์€ ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์ธ ์ง€ ํ˜„์žฌ ์‚ฌ์šฉ๋Ÿ‰์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฒƒ์ธ์ง€ ๊ฒ€์ฆ
        • 5. ์„ค์ •ํ•œ hpa๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ pod auto scaling์ด ๋™์ž‘ํ•˜๋Š” ์ง€ ๊ฒ€์ฆ
      • HorizontalPodAutoscaler์˜ behavior ํ•„๋“œ ์ค‘ stabilizationWindowSeconds ๊ฐ’์ด Kubernetes ์ฝ”๋“œ์—์„œ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉ๋˜๋Š”์ง€ ๋ถ„์„
  • prometheus
    • prometheus ๋ฆฌ์†Œ์Šค alert ์„ธํŒ…
      • ์Šฌ๋ž™ ์ฑ„๋„ ๊ตฌ์„ฑ
      • alert ํ™˜๊ฒฝ ๊ตฌ์„ฑ ๊ฐ€์ด๋“œ
  • Loki
    • loki-grafana alert ์„ธํŒ…
      • 1์ฐจ ๊ฒ€์ฆ ๊ฒฐ๊ณผ
      • Alert ํ™˜๊ฒฝ ๊ตฌ์„ฑ ๊ฐ€์ด๋“œ
  • load test
    • nGrinder
      • nGrinder Test Configuration ๊ฐ’๋“ค
      • ์งˆ๋ฌธ๋ฆฌ์ŠคํŠธ
        • groovy๋Š” JUnit ์Šคํƒ€์ผ์— ํฌํ•จ๋˜์ง€ ์•Š๋Š”๊ฑด๊ฐ€ ? + GTest๊ฐ€ ๋ญ”์ง€ ์ข€ ํ—ท๊ฐˆ๋ฆฐ๋‹ค
      • Script
        • Groovy Script Structure
          • reference
          • Groovy script deep dive
          • Groovy Script ์‹คํ–‰ ๊ตฌ์กฐ ๋ถ„์„
      • Test
        • [nGrinder] single endpoint load test ํ•˜๊ธฐ
          • [nGrinder] single endpoint load test script ๊ธฐ๋ฐ˜ cpu ์‚ฌ์šฉ๋Ÿ‰ ํ…Œ์ŠคํŠธ
          • [nGrinder] single endpoint load test script ๊ธฐ๋ฐ˜ pod autoscaling ํ…Œ์ŠคํŠธ
        • [nGrinder] multi endpoint load test ํ•˜๊ธฐ
          • [nGrinder] multi endpoint load test script์— ์ •์˜ํ•œ test๋“ค์ด ์‹คํ–‰ ์ˆœ์„œ๋ฅผ ๋ณด์žฅ ๋ฐ›๋Š”๊ฐ€?
  • AWS
    • aws-cli
      • eks cluster vpc ์ŠคํŽ™๋ณด๊ธฐ
    • aws-vpc
  • EKS
    • youtube links
    • EKS best practice
    • ์งˆ๋ฌธ ์ •๋ฆฌ
  • Istio
    • Istio Basic
      • Istio ์ปดํฌ๋„ŒํŠธ ๋ณ„ ์—ญํ• 
      • Kubernetes Ingress์™€ Istio VirtualService์˜ ๊ด€๊ณ„
    • Gateway
      • Gateway ์ฃผ์š” ํŠน์ง•
      • Istio Gateway์™€ Kubernetes Ingress์˜ ์ฃผ์š” ์ฐจ์ด์ 
  • IAC
    • Terraform
      • ํ…Œ๋ผํผ ์„ค์น˜
      • ํ…Œ๋ผํผ ๋ฌธ์„œ
      • ํ…Œ๋ผํผ ๊ฐœ๋…
        • ์–ธ์–ด ๊ตฌ์กฐ
        • ์‚ฌ์šฉ ์ˆœ์„œ
        • ์ƒํƒœํŒŒ์ผ (tfstate)
        • ๋ณ€์ˆ˜ ์ •์˜ ๋ฐฉ๋ฒ•
      • Terraform - AWS VPC
    • Ansible
      • Ansible ์ดˆ๊ธฐ ํ•™์Šต ๋‚ด์šฉ
      • Ansible Playbook
      • Ansible Study
        • Inventory
        • Playbook
          • Module
        • Variable
  • etc
    • Toss SLASH24
    • Elastic Load Balancing
    • ๋‚™์„œ์žฅ
      • IRSA
    • deep dive
      • Istio ๊ณต์‹๋ฌธ์„œ ๋ฒˆ์—ญ
        • Overview
          • What is Istio?
          • Why choose Istio?
          • Sidecar or ambient?
        • Concepts
          • Traffic Management
        • Page
      • eks ์—์„œ control plane < - > data plane ํ†ต์‹  ์›๋ฆฌ
Powered by GitBook
On this page
Edit on GitHub
  1. Kubernetes

HPA

PreviousSecurityNexthpa troubleshooting history

Last updated 1 year ago

Horizontal Pod Autoscaler (HPA)๋Š” Kubernetes ํ™˜๊ฒฝ์—์„œ Pod์˜ ์ˆ˜๋ฅผ ์ž๋™์œผ๋กœ ์กฐ์ ˆํ•˜์—ฌ ํด๋Ÿฌ์Šคํ„ฐ์˜ ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ๋ฅ ์„ ์ตœ์ ํ™”ํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋‹ค. ์ด๋ฅผ ์„ค๋ช…ํ•  ๋•Œ ์–ด๋–ค ๊ด€์ ์œผ๋กœ ์ ‘๊ทผํ• ์ง€๋Š” ์ƒํ™ฉ์— ๋”ฐ๋ผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ๊ฐ ๊ด€์ ์—์„œ์˜ ๋‚ด์šฉ์„ ์‚ดํŽด๋ณด์ž.

1. Kubernetes ๊ด€์ ์—์„œ์˜ HPA

Kubernetes ๊ด€์ ์—์„œ HPA๋Š” ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ๋ฅ ์— ๊ธฐ๋ฐ˜ํ•ด Pod์˜ ์ˆ˜๋ฅผ ์กฐ์ ˆํ•˜๋Š” Kubernetes ๊ฐ์ฒด์ด๋‹ค. CPU ๋ฐ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋ฅ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ปค์Šคํ…€ ๋ฉ”ํŠธ๋ฆญ์„ ํ†ตํ•ด์„œ๋„ ์Šค์ผ€์ผ๋ง์„ ์ง€์›ํ•œ๋‹ค.

์ฃผ์š” ๊ธฐ๋Šฅ

  • ์ž๋™ ์Šค์ผ€์ผ๋ง: CPU, ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋ฅ  ๋˜๋Š” ์ปค์Šคํ…€ ๋ฉ”ํŠธ๋ฆญ์„ ๊ธฐ๋ฐ˜์œผ๋กœ Pod ์ˆ˜๋ฅผ ์ž๋™์œผ๋กœ ์กฐ์ ˆ.

  • ์ตœ์†Œ/์ตœ๋Œ€ ํŒŒ๋“œ ์ˆ˜ ์„ค์ •: minReplicas์™€ maxReplicas๋กœ Pod ์ˆ˜์˜ ์ตœ์†Œ ๋ฐ ์ตœ๋Œ€์น˜๋ฅผ ์„ค์ •.

  • API ๋ฒ„์ „ ์ฐจ์ด:

    • autoscaling/v1: CPU ์‚ฌ์šฉ๋ฅ ๋งŒ ์ง€์›.

    • autoscaling/v2: ๋ฉ”๋ชจ๋ฆฌ ๋ฐ ์ปค์Šคํ…€ ๋ฉ”ํŠธ๋ฆญ์„ ์ง€์›.

์„ค์ • ์˜ˆ์‹œ

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"

๊ณต์‹ ๋ฌธ์„œ

2. Helm ๊ด€์ ์—์„œ์˜ HPA

Helm์„ ์‚ฌ์šฉํ•˜๋ฉด HPA ๊ฐ์ฒด๋ฅผ ์‰ฝ๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. values.yaml ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ด ์„ค์ •๊ฐ’์„ ๋งค๊ฐœ๋ณ€์ˆ˜ํ™”ํ•˜์—ฌ ๋ฐ˜๋ณต์ ์ธ ๋ฐฐํฌ์— ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฃผ์š” ๊ธฐ๋Šฅ

  • ํ…œํ”Œ๋ฆฟํ™”: HPA ์„ค์ •์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ถ”์ถœํ•˜์—ฌ ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅ.

  • ๋ฒ„์ „ ๊ด€๋ฆฌ: Helm ์ฐจํŠธ ๋ฒ„์ „์„ ํ†ตํ•ด ๋ฐฐํฌ๋œ HPA ๋ฒ„์ „์„ ๊ด€๋ฆฌ.

  • ์ž๋™ํ™” ๋ฐฐํฌ: GitLab CI/CD ํŒŒ์ดํ”„๋ผ์ธ ๋˜๋Š” ๋‹ค๋ฅธ CI/CD ๋„๊ตฌ๋ฅผ ํ†ตํ•œ ์ž๋™ํ™” ๋ฐฐํฌ.

์„ค์ • ์˜ˆ์‹œ

  • hpa.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}}
  • values.yaml:

hpa:
  enabled: true
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80

Horizontal Pod Autoscaler ๊ณต์‹ ๋ฌธ์„œ
Horizontal Pod Autoscaler Walkthrough
Kubernetes์—์„œ HPA๋ฅผ ํ™œ์šฉํ•œ ์˜คํ† ์Šค์ผ€์ผ๋ง(Auto Scaling)saramin
Logo
Horizontal Pod Autoscaling
Horizontal Pod Autoscaler - Amazon EKSAmazon EKS
Logo
Logo