Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions hpa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# HPA

Doc:
- https://cloud.google.com/kubernetes-engine/docs/how-to/horizontal-pod-autoscaling
- https://kubernetes.io/zh/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/


## CPU
### Generate Load
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"



## Memory
18 changes: 18 additions & 0 deletions hpa/cpu/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
39 changes: 39 additions & 0 deletions hpa/cpu/php.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-apache
spec:
selector:
matchLabels:
run: php-apache
replicas: 1
template:
metadata:
labels:
run: php-apache
spec:
containers:
- name: php-apache
image: k8s.gcr.io/hpa-example
ports:
- containerPort: 80
resources:
limits:
cpu: 500m
requests:
cpu: 200m

---

apiVersion: v1
kind: Service
metadata:
name: php-apache
labels:
run: php-apache
spec:
ports:
- port: 80
selector:
run: php-apache

18 changes: 18 additions & 0 deletions hpa/memory/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-memory-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: example-memory-hpa
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: memory
target:
type: AverageValue
averageValue: 1Gi
36 changes: 36 additions & 0 deletions hpa/memory/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-memory-hpa
spec:
selector:
matchLabels:
run: example-memory-hpa
replicas: 1
template:
metadata:
labels:
run: example-memory-hpa
spec:
containers:
- name: example-memory-hpa
image: python:3.10
command: ["sh"]
args: ["-c", "tail -f /dev/null" ]
# # command: ["sh -c tail -f /dev/null"]
# command: ["sh -c tail -f /dev/null"]

---

apiVersion: v1
kind: Service
metadata:
name: example-memory-hpa
labels:
run: example-memory-hpa
spec:
ports:
- port: 80
selector:
run: example-memory-hpa