๐Ÿ˜์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์˜คํ†  ์Šค์ผ€์ผ๋ง [HPA, VPC, CA]

๊น€์„ฑ์ธยท2023๋…„ 10์›” 19์ผ
0

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
40/62

HPA (Horizontal Pod AutoScaler)

https://kubernetes.io/ko/docs/tasks/run-application/horizontal-pod-autoscale/

-> ํฌ๋“œ ์ž์ฒด๋ฅผ ๋ณต์ œํ•˜์—ฌ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ํฌ๋“œ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋Š˜๋ฆฌ๋Š” ๋ฐฉ๋ฒ•
HPA๋Š” ์ปจํŠธ๋กค๋Ÿฌ ๋งค๋‹ˆ์ € ์•ˆ์—์„œ ์ฃผ๊ธฐ์ ์œผ๋กœ ์‹คํ–‰ํ•˜๋ฉด์„œ ์„ค์ •๋œ HPA์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•จ.

HPA๊ฐ€ ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— ์†ํ•œ ํŒŒ๋“œ๋“ค์˜ ์ƒํƒœ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋‹ค๊ฐ€ ์ง€์ €์˜ค๋”˜ ์กฐ๊ฑด์— ์ด๋ฅด๋ฉด ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ์Šค์ผ€์ผ ํ•ด์„œ ํŒŒ๋“œ ๊ฐœ์ˆ˜๋ฅผ ๋Š˜๋ฆฌ๊ฑฐ๋‚˜ ์ค„์ž„.

  • ์‹คํ–‰ํ• ๋•Œ๋งˆ๋‹ค ์ง€์ •๋œ ์ž์›์˜ ์‚ฌ์šฉ๋Ÿ‰์„ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค API๋กœ ํ™•์ธํ•œ ํ›„ ์„ค์ •๋œ HPA ์กฐ๊ฑด์— ๋งž์„ ๋•Œ ์˜คํ†  ์Šค์ผ€์ผ๋ง
  • ๋Œ€์ƒํŒŒ๋“œ ๊ฐœ์ˆ˜ = (ํ˜„์žฌ ํŒŒ๋“œ์˜ CPU์‚ฌ์šฉ๋ฅ ์„ ๋ชจ๋‘ ๋”ํ•œ ๊ฐ’ / ๋ชฉํ‘œ CPU์‚ฌ์šฉ๋ฅ ) ์„ ์˜ฌ๋ฆผํ•œ ๊ฐ’

์˜คํ† ์Šค์ผ€์ผ ์ง€์ • ๋ช…๋ น์–ด

kubectl autoscale deployment <๋””ํ”Œ๋กœ์ด๋จผํŠธ ๋ช…> --max 6 --min 4 --cpu-percent 50

yaml

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  targetCPUUtilizationPercentage: 30 # ๋‹จ์œ„ : %

์ ์šฉ

while true; do curl localhost:30080;done

์˜คํ† ์Šค์ผ€์ผ๋ง ๋Œ€์ƒ deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: php-apache
spec:
  selector:
    matchLabels:
      run: php-apache
  replicas: 1
  template:
    metadata:
      labels:
        run: php-apache
    spec:
      containers:
      - name: php-apache
        image: registry.k8s.io/hpa-example
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: 500m
          requests:
            cpu: 200m
---
apiVersion: v1
kind: Service
metadata:
  name: php-apache
  labels:
    run: php-apache
spec:
  ports:
  - port: 80
  selector:
    run: php-apache

autoscale ์ง€์ •

kubectl autoscale deployment php-apache --cpu-percent=30 --min=1 --max=10

  • ํŒŒ๋“œ ์ฆ๊ฐ€ : 3๋ถ„
  • ํŒŒ๋“œ ๊ฐ์†Œ : 5๋ถ„

๋ถ€ํ•˜ ๋ฐœ์ƒ

kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"

๋ถ€ํ•˜ ์ค‘์ง€ ํ›„ HPA ์ƒํƒœ ํ™•์ธ


๋ฒˆ์™ธ๋“ค

VPA (Vertical Pod AutoScaler)

๋ฆฌ์†Œ์Šค๋ฅผ ์ฆ๊ฐ€์‹œ์ผœ ํฌ๋“œ์˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ฆฌ์†Œ์Šค๋ฅผ ๋Š˜๋ฆฌ๋Š” ๋ฐฉ๋ฒ•

CA

ํด๋Ÿฌ์Šคํ„ฐ ์ž์ฒด๋ฅผ ๋Š˜๋ฆฌ๋Š” ๋ฐฉ๋ฒ•(๋…ธ๋“œ ์ถ”๊ฐ€)

0๊ฐœ์˜ ๋Œ“๊ธ€