Container/Kubernetes

[Kubernetes] Application 기능으로 이해하기 - HPA

busylee 2024. 6. 5. 19:00
728x90
반응형

- HPA > behavior : 잦은 스케일링 방지

 


ㅁ실습

 

> 부하발생 및 부하확인

http://192.168.56.30:31231/cpu-load?min=3
// 3분 동안 부하 발생


// 개인 PC 사양(core 수)에 따라 부하가 너무 오르거나/오르지 않을 경우 queryparam으로 수치 조정
http://192.168.56.30:31231/cpu-load?min=3&thread=5
// 3분 동안 5개의 쓰레드로 80% 부하 발생 
// default : min=2, thread=10


// 실시간 업데이트는 명령어로 확인하는 게 빨라요
kubectl top -n anotherclass-123 pods
kubectl get hpa -n anotherclass-123

// Grafana는 Prometheus를 거쳐 오기 때문에 좀 늦습니다
Grafana > Home > Dashboards > [Default] Kubernetes / Compute Resources / Pod

 

- 이상 현싱 발생시 원복 방법

// 1. hpa 삭제
kubectl delete -n anotherclass-123 hpa api-tester-1231-default

// 2. deployment replicas 2로 변경
kubectl scale -n anotherclass-123 deployment api-tester-1231 --replicas=2

// 3. hpa 다시 생성
kubectl apply -f - <<EOF
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  namespace: anotherclass-123
  name: api-tester-1231-default
  labels:
    part-of: k8s-anotherclass
    component: backend-server
    name: api-tester
    instance: api-tester-1231
    version: 1.0.0
    managed-by: dashboard
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api-tester-1231
  minReplicas: 2
  maxReplicas: 4
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 60
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 120
EOF

 

> 2. behavior 미사용으로 적용

kubectl edit -n anotherclass-123 hpa api-tester-1231-default
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  namespace: anotherclass-123
  name: api-tester-1231-default
spec:
  behavior:  # 삭제
    scaleUp:   # 삭제
      stabilizationWindowSeconds: 120   # 삭제

 

 

 

> 참고 URL:

https://cafe.naver.com/kubeops/49

728x90
반응형