네이버 클라우드 플랫폼의 Kubernetes Service(NKS)에서 Pod들의 오토스케일을 적용하는 방법에 대해서 소개합니다 | Introduce how to apply autoscale of Pods in the Kubernets Service (NKS) of Naver Cloud Platform
1. NAVER Cloud Platform Webinar
Run up!
NKS 에서 Cluster & Pods
autoscaling 적용하기
클라우드 솔루션 아키텍트 한지수
2. Contents
Run up!
- 네이버 클라우드 플랫폼의 Kubernetes Service
- Kubernetes Autoscaler 소개
Overview
NKS 에 Autoscaler 적용
- Cluster Autoscaling
- Horizontal Pod Autoscaling
Q & A
Wrap-up
4. Ncloud Kubernetes Service
Kubernetes Master (Control Plane)
Installation
&Addon Services
Dashboard CSI for Block Storage Weave Scope Ingress Nginx
Block Storage NAS Storage Load Balancer
API Server Scheduler
Replication
Controller
Endpoint
Controller
Node
Controller
Service
Controller
etcd
Controller-Manager
Kubelet Kube-proxy
Worker Node
ContainerContainer ContainerContainer
PodPod
Kubelet Kube-proxy
Worker Node
ContainerContainer ContainerContainer
PodPod
Kubelet Kube-proxy
Worker Node
ContainerContainer
ContainerContainer
PodPod
Related
NCP Service
NKS
Management
Scope
Customer
Management
Scope
Cluster AutoScaler
Cloud Log Analytics
5. Kubernetes Autoscaler
>> Cluster Autoscaler (CA)
K8S
API
Server
Cluster
Auto
Scaler
Check Capacity
Worker
NODE
Worker
NODE
Worker Node Pool
Worker
NODE
Ncloud Kubernetes Service
RequestNode
Additionalnodeallocated
• Pods 가 요청하는 리소스 증가에 따라 Worker Node 를 Scale-Out 하는 Scaler
• 클러스터에 설정한 최소/최대 Worker Node 개수 내에서 Scale-In / Out 진행
>> CA 동작 조건
• Worker Node 의 리소스 부족으로 Pods 가 생성되지 못하고 Pending 상태이고 Node
Pool 이 사용자가 정의한 최대 노드수에 도달하지 않은 경우 Scale-Out
• Cluster Autoscaler 가 10초마다 설정 조건에 따라 불필요한 노드를 확인, 10분 동안
조건에 해당할 경우 Scale Down 진행함
6. Kubernetes Autoscaler
>> Horizontal Pod Autoscaler (HPA)
Metric
Server
HPA
Worker
NODE
Worker
NODE
Worker Node Pool
Worker
NODE
Ncloud Kubernetes Service
• 구동중인 Pods 의 CPU 사용률을 기반으로 Pods 를 Scale-Out 하는 Scaler
• 확장/축소할 최소/최대 Pods 수량은 Pods 의 Deployment 에 의해 제어됨
>> HPA 동작 조건
• HPA 는 기본 30초 간격으로 Pods 의 사용량을 모니터링 하고 HPA 에 설정한 임계값을
초과할 경우 Pods 를 확장함 (기본 메트릭 허용 오차는 10%)
• Scale-out 이벤트 이후 3분 동안 대기하고 Scale-in 이벤트 이후 5분 동안 대기함
Pod Pod Pod Pod
Deployment
Auto Scaling Group
ReplicaSet
Get Resource Metric
Check Pods Metric
Threshold is met
8. Cluster Autoscaler 설치
0. Helm 설치
• https://docs.ncloud.com/ko/nks/nks-1-2.html#helm-설치하기 참고하여 Helm 사용 환경 구성
1. Ncloud helm repository 추가
# helm repo add ncloud https://navercloudplatformdeveloper.github.io/helm-charts
# helm search autoscaler
9. Cluster Autoscaler 설치
2. Cluster Autoscaler 설치
3. CA Pods 생성 확인
# helm --kubeconfig =$KUBE_CONFIG install ncloud/autoscaler
--set min=1
--set max=4
--max-node-provision-time=15m0s
--version 1.12.7-beta-201909190000
최소 유지할 Worker Node 개수
최대 확장할 Worker Node 개수
Node 가 확장되고 다음 Node 를 확장할 때까지의 대기시간
# kubectl --kubeconfig =$KUBE_CONFIG get pods -n kube-system | grep cluster-autoscaler
10. Cluster Autoscaler 설치
4. CA 상태 확인
# kubectl --kubeconfig =$KUBE_CONFIG get cm cluster-autoscaler-status -o yaml -n kube-system
11. Cluster Autoscaler Test – Scale Up
1. NKS Pods 생성 후 replicaset 확대
# kubectl --kubeconfig =$KUBE_CONFIG create deployment nginx --image=nginx
# kubectl --kubeconfig =$KUBE_CONFIG scale deployment nginx --replicas=100
12. Cluster Autoscaler Test – Scale Up
2. Cluster Autoscaler pods 로그 확인
# kubectl --kubeconfig =$KUBE_CONFIG logs $CA_PODS –n kube-system –f
13. Cluster Autoscaler Test – Scale Down
3. NKS Pods 생성 후 replicaset 축소
# kubectl --kubeconfig =$KUBE_CONFIG scale deployment nginx --replicas=10
14. Cluster Autoscaler Test – Scale Down
3. NKS Pods 생성 후 replicaset 축소
# kubectl --kubeconfig =$KUBE_CONFIG logs $CA_PODS –n kube-system –f
16. Horizontal Pod Autoscaler 설정
1. HPA 설정을 적용할 pods 생성
# kubectl --kubeconfig =$KUBE_CONFIG run php-apache --image=k8s.gcr.io/hpa-example --requests=cpu=200m --limits=cpu=500m --expose --
port=80
최초 생성 시 200 밀리코어 (--request) 를 할당하고 추가로 리소스가 필요하다고 판단될 경우 최대 500 밀리코어 (--limits) 까지 추가로 할당을 요청하는 Pods
Limit : Pod 가 사용할 수 있는 최대 리소스
Requests: Pod 가 구동되기 위한 요청 리소스
cpu request = 200m cpu limit = 500m
Worker
NODE
1
2
200
500
1000
… … …
1
2
200
500
1000
… … …
Pod
컨테이너가 보장받을 수 있는 CPU 리소스
컨테이너가 최대로 사용할 수 있는 CPU 리소스
* 밀리코어 (Millicores)
K8S 에서 CPU 사용량을 측정하는 메트릭으로
1000 Core 로 분할된 CPU Core
ex) 코어가 4개인 Node 의 CPU 용량은 4000 m
단일 코어 (1000m) 의 1/10 을 사용할 경우 100m
17. Horizontal Pod Autoscaler 설정
2. Horizontal Pod Autoscaler 생성
# kubectl --kubeconfig =$KUBE_CONFIG autoscale deployment php-apache --cpu-percent=30 --min=1 --max=10
# kubectl --kubeconfig =$KUBE_CONFIG get hpa
현재 CPU 사용률 HPA 가 동작하는 Target CPU 사용률
18. Horizontal Pod Autoscaler 설정
3. HPA 설정한 Pod 에 부하 테스트
# kubectl --kubeconfig =$KUBE_CONFIG run --generator=run-pod/v1 -it --rm load-generator --image=busybox /bin/sh
If you don't see a command prompt, try pressing enter.
/ # while true; do wget -q -O- http://php-apache.default.svc.cluster.local; done
4. HPA 동작 확인
Replica 증가에 따라 current 평균 CPU 사용률이 감소함
19. Horizontal Pod Autoscaler 설정
5. HPA 로그 확인
# kubectl --kubeconfig =$KUBE_CONFIG describe hpa $hpa_name