수직 파드 오토스케일링 (Vertical Pod Autoscaling)
Vertical Pod Autoscaling(VPA)은 파드의 리소스 요청량을 자동으로 조정해 클러스터 리소스 사용률을 높이고 유지보수 비용을 줄여 주는 쿠버네티스 기능입니다. 이 문서에서는 Argo Rollouts과 함께 VPA를 사용하는 방법과 동작 모드, 요구 사항을 예제와 함께 설명해 드립니다.
출처: Argo Rollouts 문서
본문
수직 파드 오토스케일링(VPA)은 리소스 요구 사항의 구성을 자동화하여 클러스터 리소스의 유지보수 비용을 줄이고 사용률을 개선합니다.
VPA 모드
VPA가 동작하는 네 가지 모드가 있습니다.
- "Auto": VPA는 파드 생성 시 리소스 요청을 할당하는 동시에 기존 파드에 대해서는 선호하는 업데이트 메커니즘을 사용해 요청을 갱신합니다. 현재 이는 아래의 "Recreate"와 동일합니다. 재시작이 필요 없는("in-place") 파드 요청 업데이트가 사용 가능해지면 "Auto" 모드의 선호 업데이트 메커니즘으로 사용될 수 있습니다. NOTE: VPA의 이 기능은 실험적이며 애플리케이션에 다운타임을 유발할 수 있습니다.
- "Recreate": VPA는 파드 생성 시 리소스 요청을 할당하고, 요청된 리소스가 새 권장값과 크게 다를 때(Pod Disruption Budget이 정의된 경우 이를 존중하면서) 파드를 축출(evict)하여 기존 파드의 요청을 갱신합니다. 이 모드는 리소스 요청이 변경될 때마다 파드가 재시작되도록 해야 하는 경우에만 드물게 사용해야 합니다. 그렇지 않으면, 재시작 없이 업데이트를 활용할 수 있는 "Auto" 모드를 선호하세요. NOTE: VPA의 이 기능은 실험적이며 애플리케이션에 다운타임을 유발할 수 있습니다.
- "Initial": VPA는 파드 생성 시에만 리소스 요청을 할당하고 이후에는 절대 변경하지 않습니다.
- "Off": VPA는 파드의 리소스 요구 사항을 자동으로 변경하지 않습니다. 권장값은 계산되며 VPA 객체에서 확인할 수 있습니다.
예제
다음은 Argo Rollouts과 함께 사용하는 Vertical Pod Autoscaler의 예제입니다.
Rollout 샘플 애플리케이션:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: vpa-demo-rollout
namespace: test-vpa
spec:
replicas: 5
strategy:
canary:
steps:
- setWeight: 20
- pause: {duration: 10}
- setWeight: 40
- pause: {duration: 10}
- setWeight: 60
- pause: {duration: 10}
- setWeight: 80
- pause: {duration: 10}
revisionHistoryLimit: 10
selector:
matchLabels:
app: vpa-demo-rollout
template:
metadata:
labels:
app: vpa-demo-rollout
spec:
containers:
- name: vpa-demo-rollout
image: ravihari/nginx:v1
ports:
- containerPort: 80
resources:
requests:
cpu: "5m"
memory: "5Mi"
Rollout 샘플 애플리케이션을 위한 VPA 구성:
apiVersion: "autoscaling.k8s.io/v1beta2"
kind: VerticalPodAutoscaler
metadata:
name: vpa-rollout-example
namespace: test-vpa
spec:
targetRef:
apiVersion: "argoproj.io/v1alpha1"
kind: Rollout
name: vpa-demo-rollout
updatePolicy:
updateMode: "Auto"
resourcePolicy:
containerPolicies:
- containerName: '*'
minAllowed:
cpu: 5m
memory: 5Mi
maxAllowed:
cpu: 1
memory: 500Mi
controlledResources: ["cpu", "memory"]
애초에 배포했을 때의 VPA를 describe 하면 권장값이 보이지 않는데, 몇 분이 걸리기 때문입니다.
Name: kubengix-vpa
Namespace: test-vpa
Labels: <none>
Annotations: <none>
API Version: autoscaling.k8s.io/v1
Kind: VerticalPodAutoscaler
Metadata:
Creation Timestamp: 2022-03-14T12:54:06Z
Generation: 1
Managed Fields:
API Version: autoscaling.k8s.io/v1beta2
Fields Type: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.:
f:kubectl.kubernetes.io/last-applied-configuration:
f:spec:
.:
f:resourcePolicy:
.:
f:containerPolicies:
f:targetRef:
.:
f:apiVersion:
f:kind:
f:name:
f:updatePolicy:
.:
f:updateMode:
Manager: kubectl-client-side-apply
Operation: Update
Time: 2022-03-14T12:54:06Z
Resource Version: 3886
UID: 4ac64e4c-c84b-478e-92e4-5f072f985971
Spec:
Resource Policy:
Container Policies:
Container Name: *
Controlled Resources:
cpu
memory
Max Allowed:
Cpu: 1
Memory: 500Mi
Min Allowed:
Cpu: 5m
Memory: 5Mi
Target Ref:
API Version: argoproj.io/v1alpha1
Kind: Rollout
Name: vpa-demo-rollout
Update Policy:
Update Mode: Auto
Events: <none>
몇 분 후 VPA가 처리 및 권장값 제공을 시작하면:
Name: kubengix-vpa
Namespace: test-vpa
Labels: <none>
Annotations: <none>
API Version: autoscaling.k8s.io/v1
Kind: VerticalPodAutoscaler
Metadata:
Creation Timestamp: 2022-03-14T12:54:06Z
Generation: 2
Managed Fields:
API Version: autoscaling.k8s.io/v1beta2
Fields Type: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.:
f:kubectl.kubernetes.io/last-applied-configuration:
f:spec:
.:
f:resourcePolicy:
.:
f:containerPolicies:
f:targetRef:
.:
f:apiVersion:
f:kind:
f:name:
f:updatePolicy:
.:
f:updateMode:
Manager: kubectl-client-side-apply
Operation: Update
Time: 2022-03-14T12:54:06Z
API Version: autoscaling.k8s.io/v1
Fields Type: FieldsV1
fieldsV1:
f:status:
.:
f:conditions:
f:recommendation:
.:
f:containerRecommendations:
Manager: recommender
Operation: Update
Time: 2022-03-14T12:54:52Z
Resource Version: 3950
UID: 4ac64e4c-c84b-478e-92e4-5f072f985971
Spec:
Resource Policy:
Container Policies:
Container Name: *
Controlled Resources:
cpu
memory
Max Allowed:
Cpu: 1
Memory: 500Mi
Min Allowed:
Cpu: 5m
Memory: 5Mi
Target Ref:
API Version: argoproj.io/v1alpha1
Kind: Rollout
Name: vpa-demo-rollout
Update Policy:
Update Mode: Auto
Status:
Conditions:
Last Transition Time: 2022-03-14T12:54:52Z
Status: True
Type: RecommendationProvided
Recommendation:
Container Recommendations:
Container Name: vpa-demo-rollout
Lower Bound:
Cpu: 25m
Memory: 262144k
Target:
Cpu: 25m
Memory: 262144k
Uncapped Target:
Cpu: 25m
Memory: 262144k
Upper Bound:
Cpu: 1
Memory: 500Mi
Events: <none>
여기에서 cpu와 memory에 대한 권장값이 lower bound, upper bound, Target 등과 함께 제공되는 것을 볼 수 있습니다. 파드의 상태를 확인해 보면, 초기 구성의 기존 파드는 종료되고 새 파드가 생성됩니다.
# kubectl get po -n test-vpa -w
NAME READY STATUS RESTARTS AGE
vpa-demo-rollout-f5df6d577-65f26 1/1 Running 0 17m
vpa-demo-rollout-f5df6d577-d55cx 1/1 Running 0 17m
vpa-demo-rollout-f5df6d577-fdpn2 1/1 Running 0 17m
vpa-demo-rollout-f5df6d577-jg2pw 1/1 Running 0 17m
vpa-demo-rollout-f5df6d577-vlx5x 1/1 Running 0 17m
...
vpa-demo-rollout-f5df6d577-jg2pw 1/1 Terminating 0 17m
vpa-demo-rollout-f5df6d577-vlx5x 1/1 Terminating 0 17m
vpa-demo-rollout-f5df6d577-jg2pw 0/1 Terminating 0 18m
vpa-demo-rollout-f5df6d577-vlx5x 0/1 Terminating 0 18m
vpa-demo-rollout-f5df6d577-w7tx4 0/1 Pending 0 0s
vpa-demo-rollout-f5df6d577-w7tx4 0/1 Pending 0 0s
vpa-demo-rollout-f5df6d577-w7tx4 0/1 ContainerCreating 0 0s
vpa-demo-rollout-f5df6d577-vdlqq 0/1 Pending 0 0s
vpa-demo-rollout-f5df6d577-vdlqq 0/1 Pending 0 1s
vpa-demo-rollout-f5df6d577-jg2pw 0/1 Terminating 0 18m
vpa-demo-rollout-f5df6d577-jg2pw 0/1 Terminating 0 18m
vpa-demo-rollout-f5df6d577-vdlqq 0/1 ContainerCreating 0 1s
vpa-demo-rollout-f5df6d577-w7tx4 1/1 Running 0 6s
vpa-demo-rollout-f5df6d577-vdlqq 1/1 Running 0 7s
vpa-demo-rollout-f5df6d577-vlx5x 0/1 Terminating 0 18m
vpa-demo-rollout-f5df6d577-vlx5x 0/1 Terminating 0 18m
새 파드의 cpu와 memory를 확인하면 VPA 권장값에 따라 업데이트된 것을 볼 수 있습니다.
# kubectl describe po vpa-demo-rollout-f5df6d577-vdlqq -n test-vpa
Name: vpa-demo-rollout-f5df6d577-vdlqq
Namespace: test-vpa
Priority: 0
Node: argo-rollouts-control-plane/172.18.0.2
Start Time: Mon, 14 Mar 2022 12:55:06 +0000
Labels: app=vpa-demo-rollout
rollouts-pod-template-hash=f5df6d577
Annotations: vpaObservedContainers: vpa-demo-rollout
vpaUpdates: Pod resources updated by kubengix-vpa: container 0: cpu request, memory request
Status: Running
IP: 10.244.0.17
IPs:
IP: 10.244.0.17
Controlled By: ReplicaSet/vpa-demo-rollout-f5df6d577
Containers:
vpa-demo-rollout:
Container ID: containerd://b79bd88851fe0622d33bc90a1560ca54ef2c27405a3bc9a4fc3a333eef5f9733
Image: ravihari/nginx:v1
Image ID: docker.io/ravihari/nginx@sha256:205961b09a80476af4c2379841bf6abec0022101a7e6c5585a88316f7115d17a
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 14 Mar 2022 12:55:11 +0000
Ready: True
Restart Count: 0
Requests:
cpu: 25m
memory: 262144k
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-mk4fz (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-mk4fz:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 38s default-scheduler Successfully assigned test-vpa/vpa-demo-rollout-f5df6d577-vdlqq to argo-rollouts-control-plane
Normal Pulled 35s kubelet Container image "ravihari/nginx:v1" already present on machine
Normal Created 35s kubelet Created container vpa-demo-rollout
Normal Started 33s kubelet Started container vpa-demo-rollout
요구 사항 (Requirements)
VPA가 롤아웃을 조작하려면, rollout CRD를 호스팅하는 쿠버네티스 클러스터가 CRD에 대한 하위 리소스(subresources)를 지원해야 합니다. 이 기능은 쿠버네티스 1.10에서 alpha로 도입되었고 1.11에서 beta로 전환되었습니다. v1.10에서 VPA를 사용하려면 쿠버네티스 클러스터 운영자가 API 서버에 커스텀 feature flag를 추가해야 합니다. 1.10 이후부터는 이 플래그가 기본적으로 켜져 있습니다. 커스텀 feature flag 설정에 대한 자세한 내용은 다음 링크를 참고하세요.
VPA를 설치할 때, 기본적으로 VPA가 모든 버전에서 rollout을 지원하지 않을 수 있으므로 system:vpa-target-reader 클러스터 역할에 다음을 RBAC 구성에 추가해야 할 수 있습니다.
- apiGroups:
- argoproj.io
resources:
- rollouts
- rollouts/scale
- rollouts/status
- replicasets
verbs:
- get
- list
- watch
클러스터에 Metrics-Server가 설치되어 있고, VPA 최신 버전이 파드에 권장값을 제대로 적용할 수 있도록 openssl이 최신 상태인지 확인하세요.
더 알아보기 (Learn more)
- VPA 동작 모드(Auto, Recreate, Initial, Off)의 차이 이해하기
- Canary 배포 전략과 VPA를 함께 적용하는 방법 익히기
- 쿠버네티스 Metrics Server와 리소스 수집 구조 알아보기
- RBAC를 통한 rollout 리소스 접근 제어 설정하기