|
| 1 | +# EKS - Vertical Pod Autoscaling (VPA) |
| 2 | + |
| 3 | +## Step-01: Introduction |
| 4 | +- The Kubernetes Vertical Pod Autoscaler automatically adjusts the CPU and memory reservations for your pods to help "right size" your applications. |
| 5 | +- This adjustment can improve cluster resource utilization and free up CPU and memory for other pods. |
| 6 | + |
| 7 | +## Step-02: Pre-requisite - Metric server |
| 8 | +- Metric server should be installed & ready, we have done that as part of HPA |
| 9 | + |
| 10 | +## Step-03: Deploy the Vertical Pod Autoscaler (VPA) |
| 11 | +``` |
| 12 | +# Clone Repo |
| 13 | +git clone https://github.com/kubernetes/autoscaler.git |
| 14 | +
|
| 15 | +# Navigate to VPA |
| 16 | +cd autoscaler/vertical-pod-autoscaler/ |
| 17 | +
|
| 18 | +# Uninstall VPA (if we are using old one) |
| 19 | +./hack/vpa-down.sh |
| 20 | +
|
| 21 | +# Install new version of VPA |
| 22 | +./hack/vpa-up.sh |
| 23 | +
|
| 24 | +# Verify VPA Pods |
| 25 | +kubectl get pods -n kube-system |
| 26 | +``` |
| 27 | + |
| 28 | +## Step-04: Review & Deploy our Application Manifests (Deployment & Service) |
| 29 | +- Make a note of resources we have defined `spec.containers.resources.requests`. |
| 30 | +- `limits` we define in VPA definition |
| 31 | +```yml |
| 32 | + resources: |
| 33 | + requests: |
| 34 | + cpu: "5m" |
| 35 | + memory: "5Mi" |
| 36 | +``` |
| 37 | +
|
| 38 | +- **Deploy** |
| 39 | +``` |
| 40 | +# Deploy Application |
| 41 | +kubectl apply -f 01-kubenginx-Deployment-NodePort-Service.yml |
| 42 | + |
| 43 | +# List Pods, Deploy & Service |
| 44 | +kubectl get pod,svc,deploy |
| 45 | + |
| 46 | +# Describe Pod |
| 47 | +kubectl describe pod <pod-name> |
| 48 | + |
| 49 | +# Access Application (If our NodeGroup is in Public Subnet, if not ignore) |
| 50 | +kubectl get nodes -o wide |
| 51 | +http://<Worker-Node-Public-IP>:31232 |
| 52 | +``` |
| 53 | + |
| 54 | +## Step-05: Create & Deploy VPA manifest |
| 55 | + |
| 56 | +### Create VPA Manifest |
| 57 | +- Create a VPA manifest for our above Application which we deployed just now. |
| 58 | +```yml |
| 59 | +apiVersion: "autoscaling.k8s.io/v1beta2" |
| 60 | +kind: VerticalPodAutoscaler |
| 61 | +metadata: |
| 62 | + name: kubengix-vpa |
| 63 | +spec: |
| 64 | + targetRef: |
| 65 | + apiVersion: "apps/v1" |
| 66 | + kind: Deployment |
| 67 | + name: vpa-demo-deployment |
| 68 | + resourcePolicy: |
| 69 | + containerPolicies: |
| 70 | + - containerName: '*' |
| 71 | + minAllowed: |
| 72 | + cpu: 5m |
| 73 | + memory: 5Mi |
| 74 | + maxAllowed: |
| 75 | + cpu: 1 |
| 76 | + memory: 500Mi |
| 77 | + controlledResources: ["cpu", "memory"] |
| 78 | +``` |
| 79 | +
|
| 80 | +### Deploy VPA Manifest |
| 81 | +``` |
| 82 | +# Deploy |
| 83 | +kubectl apply -f kube-manifests/02-VPA-Manifest.yml |
| 84 | + |
| 85 | +# List VPA |
| 86 | +kubectl get vpa |
| 87 | + |
| 88 | +# Describe VPA |
| 89 | +kubectl describe vpa kubengix-vpa |
| 90 | +``` |
| 91 | + |
| 92 | + |
| 93 | +## Step-06: Generate Load |
| 94 | +- Open 3 more new terminals and execute below 3 load generation commands |
| 95 | +``` |
| 96 | +# Terminal 1 - List and watch pods |
| 97 | +kubectl get pods -w |
| 98 | +
|
| 99 | +# Terminal 2 - Generate Load |
| 100 | +kubectl run --generator=run-pod/v1 apache-bench -i --tty --rm --image=httpd -- ab -n 500000 -c 1000 http://vpa-demo-service-nginx.default.svc.cluster.local/hello |
| 101 | +
|
| 102 | +# Terminal 3 - Generate Load |
| 103 | +kubectl run --generator=run-pod/v1 apache-bench2 -i --tty --rm --image=httpd -- ab -n 500000 -c 1000 http://vpa-demo-service-nginx.default.svc.cluster.local/hello |
| 104 | +
|
| 105 | +# Terminal 4 - Generate Load |
| 106 | +kubectl run --generator=run-pod/v1 apache-bench3 -i --tty --rm --image=httpd -- ab -n 500000 -c 1000 http://vpa-demo-service-nginx.default.svc.cluster.local/hello |
| 107 | +``` |
| 108 | + |
| 109 | +## Step-07: Describe pods which were re-launched by VPA Updater |
| 110 | +``` |
| 111 | +# List Pods |
| 112 | +kubectl get pods |
| 113 | +
|
| 114 | +# Describe pods |
| 115 | +kubectl describe pod <recently-relaunched-pod> |
| 116 | +``` |
| 117 | + |
| 118 | +## Step-08: Important Nodes about VPA: |
| 119 | +1. VPA Updater can re-launch new pod with updated CPU and Memory when you atleast have 2 pods in a deployment. |
| 120 | +2. If we have only one pod, unless we manually delete that pod, it will not launch new pod with VPA recommended CPU and memory considerign the application availability scenario. |
| 121 | + |
| 122 | +## Step-09: Clean-Up |
| 123 | +``` |
| 124 | +kubectl delete -f kube-manifests/ |
| 125 | +``` |
0 commit comments