减少负载后Kubernetes HPA不会按比例缩小 [英] Kubernetes HPA doesn't scale down after decreasing the loads
问题描述
当Pod的负载增加时,Kubernetes HPA可以正常工作,但是在负载减少之后,部署规模不会改变.这是我的HPA文件:
the Kubernetes HPA works correctly when load of the pod increased but after the load decreased, the scale of deployment doesn't change. This is my HPA file:
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: baseinformationmanagement
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: baseinformationmanagement
minReplicas: 1
maxReplicas: 3
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
我的kubernetes版本:
My kubernetes version:
> kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.1", GitCommit:"d647ddbd755faf07169599a625faf302ffc34458", GitTreeState:"clean", BuildDate:"2019-10-02T17:01:15Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89", GitTreeState:"clean", BuildDate:"2020-01-18T23:22:30Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"}
这是我对HPA的描述:
And this is my HPA describe:
> kubectl describe hpa baseinformationmanagement
Name: baseinformationmanagement
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"autoscaling/v2beta2","kind":"HorizontalPodAutoscaler","metadata":{"annotations":{},"name":"baseinformationmanagement","name...
CreationTimestamp: Sun, 27 Sep 2020 06:09:07 +0000
Reference: Deployment/baseinformationmanagement
Metrics: ( current / target )
resource memory on pods (as a percentage of request): 49% (1337899008) / 70%
resource cpu on pods (as a percentage of request): 2% (13m) / 50%
Min replicas: 1
Max replicas: 3
Deployment pods: 2 current / 2 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from memory resource utilization (percentage of request)
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
Events: <none>
推荐答案
您的HPA同时指定内存和CPU目标. Horizontal Pod Autoscaler 文档说明:
Your HPA specifies both memory and CPU targets. The Horizontal Pod Autoscaler documentation notes:
如果在HorizontalPodAutoscaler中指定了多个指标,则将对每个指标进行此计算,然后选择所需的最大副本数.
If multiple metrics are specified in a HorizontalPodAutoscaler, this calculation is done for each metric, and then the largest of the desired replica counts is chosen.
实际副本目标是当前副本数以及当前和目标利用率(相同链接)的函数:
The actual replica target is a function of the current replica count and the current and target utilization (same link):
desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]
特别是对于内存:currentReplicas
为2; currentMetricValue
是49; desiredMetricValue
是80.所以目标副本数是
For memory in particular: currentReplicas
is 2; currentMetricValue
is 49; desiredMetricValue
is 80. So the target replica count is
desiredReplicas = ceil[ 2 * ( 49 / 80 )]
desiredReplicas = ceil[ 2 * 0.61 ]
desiredReplicas = ceil[ 1.26 ]
desiredReplicas = 2
即使您的服务完全空闲,这也会导致(至少)有2个副本,除非该服务选择将内存释放回操作系统;通常情况下,这取决于语言运行时,并且有点不受您的控制.
Even if your service is totally idle, this will cause there to be (at least) 2 replicas, unless the service chooses to release memory back to the OS; that's usually up to the language runtime and a little out of your control.
仅删除内存目标并仅基于CPU自动缩放可能会更好地满足您的期望.
Just removing the memory target and autoscaling based only on CPU might match better what you expect.
这篇关于减少负载后Kubernetes HPA不会按比例缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!