Skip to content

Commit bf9422f

Browse files
committed
done
1 parent 3e6544f commit bf9422f

11 files changed

Lines changed: 705 additions & 0 deletions

Kubernetese/hpa/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Horizontal Pod autoscaler
2+
3+
## Install Metrics server -
4+
5+
> Clone this repository and install metrics server. Please do note that this setup is good for dev/qa environment. A lot of considerations must be put while installing metrics server in production environment. The official metrics-server repository is kept at https://github.com/kubernetes-incubator/metrics-server and we are using the same repo with few changes.
6+
7+
> Install the metrics server
8+
9+
` cd metrics-server`
10+
11+
` kubectl create -f . `
12+
13+
14+
## Create nginx deployment, service & hpa
15+
16+
> It is mandatory to set requests on cpu utilization as HPA requires CPU metrics.
17+
18+
` kubectl create -f hpa.yaml`
19+
20+
~~~
21+
kubectl get hpa
22+
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
23+
nginx Deployment/nginx 0%/40% 3 5 3 55s
24+
~~~
25+
26+
## Test the HPA using apache bench
27+
28+
> Apache Bench (ab) is a load testing and benchmarking tool for Hypertext Transfer Protocol (HTTP) server. It can be run from command line and it is very simple to use. A quick load testing output can be obtained in just one minute
29+
30+
### install apache benchmark tool
31+
32+
` apt-get install apache2-utils`
33+
34+
#### Get the service IP address using
35+
36+
`kubectl get svc`
37+
38+
### send load on to the PODS
39+
40+
` ab -n 500000 -c 1000 http://10.97.161.152/`
41+
42+
` -n requests Number of requests to perform`
43+
44+
` -c concurrency Number of multiple requests to make at a time`

Kubernetese/hpa/hpa.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: nginx
6+
labels:
7+
app: nginx
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: nginx
13+
template:
14+
metadata:
15+
name: nginxpod
16+
labels:
17+
app: nginx
18+
spec:
19+
containers:
20+
- name: nginx
21+
image: nginx:latest
22+
resources:
23+
limits:
24+
cpu: 20m ## 10% of 1 core on your system
25+
26+
---
27+
28+
apiVersion: v1
29+
kind: Service
30+
metadata:
31+
name: nginx-svc
32+
spec:
33+
type: ClusterIP ## this is default if we do not type in service definition
34+
selector:
35+
app: nginx
36+
ports:
37+
- protocol: TCP
38+
port: 80
39+
targetPort: 80
40+
41+
---
42+
43+
apiVersion: autoscaling/v1
44+
kind: HorizontalPodAutoscaler
45+
metadata:
46+
name: nginx-hpa
47+
spec:
48+
scaleTargetRef:
49+
apiVersion: apps/v1
50+
kind: Deployment
51+
name: nginx
52+
minReplicas: 1
53+
maxReplicas: 10
54+
targetCPUUtilizationPercentage: 10
55+

0 commit comments

Comments
 (0)