diff --git a/hpa/README.md b/hpa/README.md new file mode 100644 index 0000000..2245e0e --- /dev/null +++ b/hpa/README.md @@ -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 diff --git a/hpa/cpu/hpa.yaml b/hpa/cpu/hpa.yaml new file mode 100644 index 0000000..cba8876 --- /dev/null +++ b/hpa/cpu/hpa.yaml @@ -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 diff --git a/hpa/cpu/php.yaml b/hpa/cpu/php.yaml new file mode 100644 index 0000000..5eb04cf --- /dev/null +++ b/hpa/cpu/php.yaml @@ -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 + diff --git a/hpa/memory/hpa.yaml b/hpa/memory/hpa.yaml new file mode 100644 index 0000000..cc0973f --- /dev/null +++ b/hpa/memory/hpa.yaml @@ -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 diff --git a/hpa/memory/python.yaml b/hpa/memory/python.yaml new file mode 100644 index 0000000..3f68d19 --- /dev/null +++ b/hpa/memory/python.yaml @@ -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 +