Skip to content

Commit 82f5f4f

Browse files
Kalyan Reddy DaidaKalyan Reddy Daida
Kalyan Reddy Daida
authored and
Kalyan Reddy Daida
committed
Welcome to Stack Simplify
1 parent 237782f commit 82f5f4f

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: vpa-demo-deployment
5+
labels:
6+
app: vpa-nginx
7+
spec:
8+
replicas: 4
9+
selector:
10+
matchLabels:
11+
app: vpa-nginx
12+
template:
13+
metadata:
14+
labels:
15+
app: vpa-nginx
16+
spec:
17+
containers:
18+
- name: vpa-nginx
19+
image: stacksimplify/kubenginx:1.0.0
20+
ports:
21+
- containerPort: 80
22+
resources:
23+
requests:
24+
cpu: "5m"
25+
memory: "5Mi"
26+
---
27+
apiVersion: v1
28+
kind: Service
29+
metadata:
30+
name: vpa-demo-service-nginx
31+
labels:
32+
app: vpa-nginx
33+
spec:
34+
type: NodePort
35+
selector:
36+
app: vpa-nginx
37+
ports:
38+
- port: 80
39+
targetPort: 80
40+
nodePort: 31232
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: "autoscaling.k8s.io/v1beta2"
2+
kind: VerticalPodAutoscaler
3+
metadata:
4+
name: kubengix-vpa
5+
spec:
6+
targetRef:
7+
apiVersion: "apps/v1"
8+
kind: Deployment
9+
name: vpa-demo-deployment
10+
resourcePolicy:
11+
containerPolicies:
12+
- containerName: '*'
13+
minAllowed:
14+
cpu: 5m
15+
memory: 5Mi
16+
maxAllowed:
17+
cpu: 1
18+
memory: 500Mi
19+
controlledResources: ["cpu", "memory"]

0 commit comments

Comments
 (0)