Vertical Pod Autoscaler (VPA)
•
컨테이너에 할당되는 CPU / 메모리 리소스의 할당을 자동으로 스케일링 해주는 오브젝트 (= scale up)
•
서비스 적용 전 Pod resource request에 어떤 값이 적정한지 명확하지 않을때 유용
•
VPA > HPA > CA 순으로 스케일링 동작
•
사전 조건 : 메트릭 서버가 있어야 하며 VPA Shell을 실행 해야한다.
apiVersion: "autoscaling.k8s.io/v1"
kind: VerticalPodAutoscaler
metadata:
name: <VPA Name>
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: <Deployment Name>
resourcePolicy:
containerPolicies:
- containerName: '*'
minAllowed:
cpu: 100m
memory: 50Mi
maxAllowed:
cpu: 1
memory: 500Mi
controlledResources: ["cpu", "memory"]
YAML
복사
•
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu
spec:
replicas: 2
selector:
matchLabels:
app: ubuntu
template:
metadata:
labels:
app: ubuntu
spec:
containers:
- name: ubuntu
image: ubuntu:latest
command: ["/bin/bash", "-c", "sleep 3600"]
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "512Mi"
YAML
복사
•
vpa.yaml
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: ubuntu-vpa
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: ubuntu
updatePolicy:
updateMode: "Auto"
YAML
복사
kubectl exec -it <ubuntu-pod-name> -- /bin/bash
apt-get update
apt-get install -y stress
stress --cpu 2 --vm 1 --vm-bytes 128M --timeout 60s
# checking
kubectl describe vpa ubuntu-vpa
kubectl get pods
kubectl top pods
kubectl get pod <pod-name> -o yaml
kubectl get pod <pod-name> -o yaml | grep -A 10 resources
YAML
복사