Skip to content

Commit ced4016

Browse files
Kalyan Reddy DaidaKalyan Reddy Daida
authored andcommitted
Welcome to Stack Simplify
1 parent f22476b commit ced4016

17 files changed

+158
-728
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# EKS - Horizontal Pod Autoscaling (HPA)
2+
3+
## Step-01: Introduction
4+
- What is Horizontal Pod Autoscaling?
5+
- How HPA Works?
6+
- How HPA configured?
7+
8+
## Step-02: Install Metrics Server
9+
```
10+
# Verify if Metrics Server already Installed
11+
kubectl -n kube-system get deployment/metrics-server
12+
13+
# Install Metrics Server
14+
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml
15+
16+
# Verify
17+
kubectl get deployment metrics-server -n kube-system
18+
```
19+
20+
## Step-03: Deploy our Application
21+
```
22+
# Deploy
23+
kubectl apply -f kube-manifests/
24+
25+
# List Pods, Deploy & Service
26+
kubectl get pod,svc,deploy
27+
28+
# Access Application
29+
kubectl get nodes -o wide
30+
http://<Worker-Node-Public-IP>:31231
31+
```
32+
33+
## Step-04: Create a Horizontal Pod Autoscaler resource for the "hpa-demo-deployment"
34+
- This command creates an autoscaler that targets 50 percent CPU utilization for the deployment, with a minimum of one pod and a maximum of ten pods.
35+
- When the average CPU load is below 50 percent, the autoscaler tries to reduce the number of pods in the deployment, to a minimum of one.
36+
- When the load is greater than 50 percent, the autoscaler tries to increase the number of pods in the deployment, up to a maximum of ten
37+
```
38+
# Template
39+
kubectl autoscale deployment <deployment-name> --cpu-percent=50 --min=1 --max=10
40+
41+
# Replace
42+
kubectl autoscale deployment hpa-demo-deployment --cpu-percent=50 --min=1 --max=10
43+
44+
# Describe HPA
45+
kubectl describe hpa/hpa-demo-deployment
46+
47+
# List HPA
48+
kubectl get horizontalpodautoscaler.autoscaling/hpa-demo-deployment
49+
```
50+
51+
## Step-05: Create the load & Verify how HPA is working
52+
```
53+
# Generate Load
54+
kubectl run --generator=run-pod/v1 apache-bench -i --tty --rm --image=httpd -- ab -n 500000 -c 1000 http://hpa-demo-service-nginx.default.svc.cluster.local/
55+
56+
# List all HPA
57+
kubectl get hpa
58+
59+
# List specific HPA
60+
kubectl get hpa hpa-demo-deployment
61+
62+
# Describe HPA
63+
kubectl describe hpa/hpa-demo-deployment
64+
65+
# List Pods
66+
kubectl get pods
67+
```
68+
69+
## Step-07: Cooldown / Scaledown
70+
- Default cooldown period is 5 minutes.
71+
- Once CPU utilization of pods is less than 50%, it will starting terminating pods and will reach to minimum 1 pod as configured.
72+
73+
## Step-08: Imperative vs Declarative for HPA
74+
- From Kubernetes v1.18 onwards, we have a declarative way of defining HPA policies using `behavior` object in yaml.
75+
- **Support for configurable scaling behavior**
76+
- Starting from v1.18 the v2beta2 API allows scaling behavior to be configured through the HPA behavior field.
77+
- Behaviors are specified separately for scaling up and down in scaleUp or scaleDown section under the behavior field
78+
```yml
79+
behavior:
80+
scaleDown:
81+
stabilizationWindowSeconds: 300
82+
policies:
83+
- type: Percent
84+
value: 100
85+
periodSeconds: 15
86+
scaleUp:
87+
stabilizationWindowSeconds: 0
88+
policies:
89+
- type: Percent
90+
value: 100
91+
periodSeconds: 15
92+
- type: Pods
93+
value: 4
94+
periodSeconds: 15
95+
selectPolicy: Max
96+
```
97+
- **Reference:** Select V1.18 from top right corner on Kubernetes website for V1.18 documentation
98+
- https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/
99+
100+
## Step-06: Clean-Up
101+
```
102+
# Delete HPA
103+
kubectl delete hpa hpa-demo-deployment
104+
105+
# Delete Deployment & Service
106+
kubectl delete -f V1-HPA/01-kubenginx-Deployment-NodePort-Service-for-HPA-Demo.yml
107+
```
108+
109+
## Referencess
110+
### Metrics Server Releases
111+
- https://github.com/kubernetes-sigs/metrics-server/releases
112+
113+
### Horizontal Pod Autoscaling - Scale based on many type of metrics
114+
- https://v1-16.docs.kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: hpa-demo-deployment
5+
labels:
6+
app: hpa-nginx
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: hpa-nginx
12+
template:
13+
metadata:
14+
labels:
15+
app: hpa-nginx
16+
spec:
17+
containers:
18+
- name: hpa-nginx
19+
image: stacksimplify/kubenginx:1.0.0
20+
ports:
21+
- containerPort: 80
22+
resources:
23+
requests:
24+
memory: "128Mi"
25+
cpu: "100m"
26+
limits:
27+
memory: "500Mi"
28+
cpu: "200m"
29+
---
30+
apiVersion: v1
31+
kind: Service
32+
metadata:
33+
name: hpa-demo-service-nginx
34+
labels:
35+
app: hpa-nginx
36+
spec:
37+
type: NodePort
38+
selector:
39+
app: hpa-nginx
40+
ports:
41+
- port: 80
42+
targetPort: 80
43+
nodePort: 31231
44+

15-Microservices-with-AppMesh/14-01-Install-AppMesh-Components/README.md

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)