k8s autoscale
- 파드 수를 부하에 맞게 자동으로 조절하는 기능으로 수평 파드 오토스케일러(Horizontal Pod Autoscaler, HPA)를 사용할 수 있다.
- 스케일 업은 이전 동작에서 3분 뒤에 발동하고, 스케일 다운은 5분 뒤에 발동된다.
- HPA가 목표로 하는 CPU 사용률은 파드의 실제 CPU 사용 시간을 매니페스트에 기재한 CPU 요구 시간으로 나누어서 구한다
- HPA는 파드의 개수만 조절할 수 있기 때문에, 노드의 개수까지 조절하고 싶은 경우에는 클러스터 오토스케일러(Cluster Autoscaler, CA)를 고려한다. 단, 이 기능은 클라우드 프로바이더의 기능 지원이 필수다
yml
apiVersion: apps/v1 kind: Deployment metadata: name: web-php spec: replicas: 1 selector: matchLabels: run: web-php template: metadata: labels: run: web-php spec: containers: - image: maho/web-php:0.2 name: web-php resources: requests: cpu: 200m --- apiVersion: v1 kind: Service metadata: name: web-php spec: type: NodePort selector: run: web-php ports: - port: 80 protocol: TCP nodePort: 31446
Command
$ kubectl autoscale deployment web-php --cpu-percent=50 --min=1 --max=10 horizontalpodautoscaler.autoscaling/web-php autoscaled
커맨드 | 동작 |
---|---|
kubectl describe node [노드명] | 노드의 자세한 내용을 출력. 리소스 보유량이나 사용량 등 HPA 사용을 계획할 때 필요한 정보 확인 가능 |
kubectl autoscale [컨트롤러] [오브젝트명] | HPA 설정. kubectl autoscale help 를 통해 사용법 확인 가능 |
kubectl get hpa | HPA 상태 출력. get 을 describe로 바꾸면 상세 내용 출력 |