diff --git a/content/en/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling.md b/content/en/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling.md new file mode 100755 index 000000000..0399c7588 --- /dev/null +++ b/content/en/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling.md @@ -0,0 +1,139 @@ +--- +title: "Horizontal Pod Autoscaling" +keywords: "Horizontal, Pod, Autoscaling, Autoscaler" +description: "How to configure Horizontal Pod Autoscaling on KubeSphere." +weight: 10290 + +--- + +This document describes how to configure Horizontal Pod Autoscaling (HPA) on KubeSphere. + +The HPA feature automatically adjusts the number of Pods to maintain average resource usage (CPU and memory) of Pods around preset values. For details about how HPA functions, see the [official Kubernetes document](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/). + +This document uses HPA based on CPU usage as an example. Operations for HPA based on memory usage are similar. + +## Prerequisites + +- You need to [enable the Metrics Server](https://kubesphere.io/docs/pluggable-components/metrics-server/). +- You need to create a workspace, a project and an account (for example, `project-regular`). `project-regular` must be invited to the project and assigned the `operator` role. For more information, see [Create Workspaces, Projects, Accounts and Roles](/docs/quick-start/create-workspace-and-project/). + +## Create a Service + +1. Log in to the KubeSphere web console as `project-regular` and go to your project. + +2. Choose **Services** in **Application Workloads** on the left navigation bar and click **Create** on the right. + + ![create-service](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-service.png) + +3. In the **Create Service** dialog box, click **Stateless Service**. + + ![stateless-service](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/stateless-service.png) + +4. Set the Service name (for example, `hpa`) and click **Next**. + + ![service-name](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/service-name.png) + +5. Click **Add Container Image**, set **Image** to `mirrorgooglecontainers/hpa-example` and click **Use Default Ports**. + + ![add-container-image](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/add-container-image.png) + +6. Set the CPU request (for example, 0.15 cores) for each container, click **√**, and click **Next**. + + {{< notice note >}} + + * To use HPA based on CPU usage, you must set the CPU request for each container, which is the minimum CPU resource reserved for each container (for details, see the [official Kubernetes document](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/)). The HPA feature compares the average Pod CPU usage with a target percentage of the average Pod CPU request. + * For HPA based on memory usage, you do not need to configure the memory request. + + {{}} + + ![cpu-request](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cpu-request.png) + +7. Click **Next** on the **Mount Volumes** tab and click **Create** on the **Advanced Settings** tab. + +## Configure HPA + +1. Choose **Deployments** in **Workloads** on the left navigation bar and click the HPA Deployment (for example, hpa-v1) on the right. + + ![hpa-deployment](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-deployment.png) + +2. Click **More** and choose **Horizontal Pod Autoscaling** from the drop-down list. + + ![horizontal-pod-autoscaling](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/horizontal-pod-autoscaling.png) + +3. In the **Horizontal Pod Autoscaling** dialog box, configure the HPA parameters and click **OK**. + + * **CPU Target Utilization**: Target percentage of the average Pod CPU request. + * **Memory Target Usage**: Target average Pod memory usage in MiB. + * **Min Replicas Number**: Minimum number of Pods. + * **Max Replicas Number**: Maximum number of Pods. + + In this example, **CPU Target Utilization** is set to `60`, **Min Replicas Number** is set to `1`, and **Max Replicas Number** is set to `10`. + + {{< notice note >}} + + Ensure that the cluster can provide sufficient resource for all Pods when the number of Pods reaches the maximum. Otherwise, the creation of some Pods will fail. + + {{}} + + ![hpa-parameters](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-parameters.png) + +## Verify HPA + +This section uses a Deployment that sends requests to the HPA Service to verify that HPA automatically adjusts the number of Pods to meet the resource usage target. + +### Create a load generator Deployment + +1. Choose **Workloads** in **Application Workloads** on the left navigation bar and click **Create** on the right. + + ![create-deployment](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-deployment.png) + +2. In the **Create Deployment** dialog box, set the Deployment name (for example, `load-generator`) and click **Next**. + + ![deployment-name](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/deployment-name.png) + +3. Click **Add Container Image** and set **Image** to `busybox`. + + ![busybox](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/busybox.png) + +4. Scroll down in the dialog box, select **Start Command**, and set **Run Command** to `sh,-c` and **Parameters** to `while true; do wget -q -O- http://..svc.cluster.local; done` (for example, `while true; do wget -q -O- http://hpa.demo-project.svc.cluster.local; done`). + + ![start-command](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/start-command.png) + +5. Click **√** and click **Next**. + +6. Click **Next** on the **Mount Volumes** tab and click **Create** on the **Advanced Settings** tab. + +### View the HPA Deployment status + +1. After the load generator Deployment is created, choose **Workloads** in **Application Workloads** on the left navigation bar and click the HPA Deployment (for example, hpa-v1) on the right. + + The number of Pods automatically increases to meet the resource usage target. + + ![target-cpu-utilization](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/target-cpu-utilization.png) + + ![pods-increase](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-increase.png) + +2. Choose **Workloads** in **Application Workloads** on the left navigation bar, click the three dots on the right of the load generator Deployment (for example, load-generator-v1), and choose **Delete** from the drop-down list. After the load-generator Deployment is deleted, check the status of the HPA Deployment again. + + The number of Pods decreases to the minimum. + + ![pods-decrease](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-decrease.png) + +{{< notice note >}} + +The system may require a few minutes to adjust the number of Pods and collect data. + +{{}} + +## Edit HPA Configuration + +You can repeat steps in [Configure HPA](#configure-hpa) to edit the HPA configuration. + +## Cancel HPA + +1. Choose **Workloads** in **Application Workloads** on the left navigation bar and click the HPA Deployment (for example, hpa-v1) on the right. + +2. Click the three dots on the right of **Horizontal Pod Autoscaling** and choose **Cancel** from the drop-down list. + + ![cancel-hpa](/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cancel-hpa.png) + diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/add-container-image.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/add-container-image.png new file mode 100644 index 000000000..85592ab88 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/add-container-image.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/busybox.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/busybox.png new file mode 100644 index 000000000..41346ab6d Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/busybox.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cancel-hpa.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cancel-hpa.png new file mode 100644 index 000000000..4b0df6230 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cancel-hpa.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cpu-request.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cpu-request.png new file mode 100644 index 000000000..58e73e508 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/cpu-request.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-deployment.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-deployment.png new file mode 100644 index 000000000..255d4c2d5 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-deployment.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-service.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-service.png new file mode 100644 index 000000000..d14d65811 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/create-service.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/deployment-name.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/deployment-name.png new file mode 100644 index 000000000..1d93452cb Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/deployment-name.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/horizontal-pod-autoscaling.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/horizontal-pod-autoscaling.png new file mode 100644 index 000000000..57929f090 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/horizontal-pod-autoscaling.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-deployment.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-deployment.png new file mode 100644 index 000000000..deb53c24d Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-deployment.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-parameters.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-parameters.png new file mode 100644 index 000000000..65180ecbb Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/hpa-parameters.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-decrease.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-decrease.png new file mode 100644 index 000000000..bffd5efbc Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-decrease.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-increase.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-increase.png new file mode 100644 index 000000000..93954de67 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/pods-increase.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/service-name.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/service-name.png new file mode 100644 index 000000000..b2be49d14 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/service-name.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/start-command.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/start-command.png new file mode 100644 index 000000000..43fda3994 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/start-command.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/stateless-service.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/stateless-service.png new file mode 100644 index 000000000..3d441fec2 Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/stateless-service.png differ diff --git a/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/target-cpu-utilization.png b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/target-cpu-utilization.png new file mode 100644 index 000000000..01dc4828f Binary files /dev/null and b/static/images/docs/project-user-guide/application-workloads/horizontal-pod-autoscaling/target-cpu-utilization.png differ