4 minute read
Kubernetes’ users want to use HPA to optimize resource utilization. But it is often that we don’t know which applications are suitable for HPA or how to configure the parameters of HPA. With HPA Recommendation you can analyze the actual application usage and get recommended configurations. You can use it to improve application resource utilization.
HPA recommendation is still in Alpha phase, comments are welcome.
In Kubernetes, the HPA (HorizontalPodAutoscaler) automatically updates the workload replicas (such as Deployment or StatefulSet) to meet the target utilization. However, in the actual world, we observe following problems:
Based on the historical metrics data and algorithm analysis, HPA Recommendation provide the following suggestions: Which applications are suitable for HPA and How to configure it.
An HPA recommendation sample yaml looks like below:
apiVersion: analysis.crane.io/v1alpha1
kind: Recommendation
metadata:
labels:
analysis.crane.io/recommendation-rule-name: workload-hpa
analysis.crane.io/recommendation-rule-recommender: HPA
analysis.crane.io/recommendation-rule-uid: 0214c84b-8b39-499b-a7c6-559ac460695d
analysis.crane.io/recommendation-target-kind: Rollout
analysis.crane.io/recommendation-target-name: eshop
analysis.crane.io/recommendation-target-version: v1alpha1
name: workload-hpa-hpa-blr4r
namespace: zytms
ownerReferences:
- apiVersion: analysis.crane.io/v1alpha1
blockOwnerDeletion: false
controller: false
kind: RecommendationRule
name: workload-hpa
uid: 0214c84b-8b39-499b-a7c6-559ac460695d
spec:
adoptionType: StatusAndAnnotation
completionStrategy:
completionStrategyType: Once
targetRef:
apiVersion: argoproj.io/v1alpha1
kind: Rollout
name: eshop
namespace: eshop
type: HPA
status:
action: Create
lastUpdateTime: "2022-12-05T06:12:54Z"
recommendedInfo: '{"kind":"EffectiveHorizontalPodAutoscaler","apiVersion":"autoscaling.crane.io/v1alpha1","metadata":{"name":"eshop","namespace":"eshop","creationTimestamp":null},"spec":{"scaleTargetRef":{"kind":"Rollout","name":"eshop","apiVersion":"argoproj.io/v1alpha1"},"minReplicas":1,"maxReplicas":1,"scaleStrategy":"Preview","metrics":[{"type":"Resource","resource":{"name":"cpu","target":{"type":"Utilization","averageUtilization":58}}},{"type":"Pods","pods":{"metric":{"name":"k8s_pod_cpu_core_used"},"target":{"type":"AverageValue","averageValue":"500m"}}}]},"status":{}}'
recommendedValue: |
effectiveHPA:
maxReplicas: 1
metrics:
- resource:
name: cpu
target:
averageUtilization: 58
type: Utilization
type: Resource
- pods:
metric:
name: k8s_pod_cpu_core_used
target:
averageValue: 500m
type: AverageValue
type: Pods
minReplicas: 1
In this sample:
The process for one HPA recommendation:
It should meet the following conditions:
The following is a typical workload with peaks and troughs which is suitable for HPA.
The method is consistent with replica recommendation. Please referring to: Replicas Recommendation
Support StatefulSet and Deployment by default,but all workloads that support Scale SubResource
are supported.
Configuration items | Default | Description |
---|---|---|
workload-min-replicas | 1 | Workload replicas that less than this value will abort recommendation |
pod-min-ready-seconds | 30 | Defines the min seconds to identify Pod is ready |
pod-available-ratio | 0.5 | Workload ready Pod ratio that less than this value will abort recommendation |
default-min-replicas | 1 | default minReplicas |
cpu-percentile | 0.95 | Percentile for historical cpu usage |
mem-percentile | 0.95 | Percentile for historical memory usage |
cpu-target-utilization | 0.5 | Target of CPU peak historical usage |
mem-target-utilization | 0.5 | Target of Memory peak historical usage |
predictable | false | When set to true, it will not recommend for HPA if CPU usage is not predictable |
reference-hpa | true | The recommended result will inherits custom/external metric from existing ehpa |
min-cpu-usage-threshold | 1 | Workload CPU peak usage that less than this value will abort recommendation |
fluctuation-threshold | 1.5 | Workload CPU usage fluctuation that less than this value will abort recommendation |
min-cpu-target-utilization | 30 | minimum CPU TargetUtilization |
max-cpu-target-utilization | 75 | maximum CPU TargetUtilization |
max-replicas-factor | 3 | the factor when calculate maxReplicas |
How to update recommendation configuration please refer to:Recommendation Framework