From 2ae5fdb126f8acc74d2930730d323e9cc6034539 Mon Sep 17 00:00:00 2001 From: Timothy McCallum Date: Wed, 13 Mar 2024 22:27:52 +1000 Subject: [PATCH 1/2] Remove TODO and update specifics about scaling resources with HPA Signed-off-by: tpmccallum tim.mccallum@fermyon.com Signed-off-by: Timothy McCallum --- .../tutorials/scaling-with-hpa.md | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md b/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md index 5d369b1..a2299ff 100644 --- a/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md +++ b/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md @@ -152,13 +152,51 @@ spec: averageUtilization: 50 ``` - +For more information about HPA, please visit the following links: +- [Kubernetes Horizontal Pod Autoscaling](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) +- [Kubernetes HorizontalPodAutoscaler Walkthrough](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/) +- [HPA Container Resource Metrics](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#container-resource-metrics) -The Kubernetes documentation is the place to learn more about [limits and requests](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits) and [other metrics supported by HPA](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#container-resource-metrics). +Below is an example of the configuration to scale resources: -Let’s deploy the SpinApp and the HPA instance onto our cluster with the following command: +```yaml +apiVersion: core.spinoperator.dev/v1alpha1 +kind: SpinApp +metadata: + name: hpa-spinapp +spec: + image: ghcr.io/spinkube/spin-operator/cpu-load-gen:20240311-163328-g1121986 + executor: containerd-shim-spin + enableAutoscaling: true + resources: + limits: + cpu: 500m + memory: 500Mi + requests: + cpu: 100m + memory: 400Mi +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: spinapp-autoscaler +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: hpa-spinapp + minReplicas: 1 + maxReplicas: 10 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 +``` + +Let’s deploy the SpinApp and the HPA instance onto our cluster (using the above `.yaml` configuration). To apply the above configuration we use the following `kubectl apply` command: ```console # Install SpinApp and HPA From 670161059675ce127052b50f5eafcc6193c1d898 Mon Sep 17 00:00:00 2001 From: Timothy McCallum Date: Wed, 13 Mar 2024 22:42:34 +1000 Subject: [PATCH 2/2] Update with link to `spin kube` command Signed-off-by: tpmccallum tim.mccallum@fermyon.com Signed-off-by: Timothy McCallum --- content/en/docs/spin-operator/tutorials/scaling-with-hpa.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md b/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md index a2299ff..ae670a0 100644 --- a/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md +++ b/content/en/docs/spin-operator/tutorials/scaling-with-hpa.md @@ -219,6 +219,8 @@ NAME REFERENCE TARGETS MINPODS MAXPODS REPL spinapp-autoscaler Deployment/hpa-spinapp 6%/50% 1 10 1 97m ``` +> Please note: The [Kubernetes Plugin for Spin](https://www.spinkube.dev/docs/spin-plugin-kube/installation/) is a tool designed for Kubernetes integration with the Spin command-line interface. The [Kubernetes Plugin for Spin has a scaling tutorial](https://www.spinkube.dev/docs/spin-plugin-kube/tutorials/autoscaler-support/) that demonstrates how to use the `spin kube` command to tell Kubernetes when to scale your Spin application up or down based on demand). + ## Generate Load to Test Autoscale Now let’s use Bombardier to generate traffic to test how well HPA scales our SpinApp. The following Bombardier command will attempt to establish 40 connections during a period of 3 minutes (or less). If a request is not responded to within 5 seconds that request will timeout: