kubernetes - 减少负载后 Kubernetes HPA 不会缩减
问题描述
当 pod 的负载增加时,Kubernetes HPA 可以正常工作,但负载降低后,部署规模不会改变。这是我的 HPA 文件:
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 版本:
> 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 描述:
> 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 目标。Horizo ntal Pod Autoscaler文档说明:
如果在 HorizontalPodAutoscaler 中指定了多个指标,则会针对每个指标进行此计算,然后选择所需副本数中的最大值。
实际副本目标是当前副本计数以及当前和目标利用率的函数(相同链接):
desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]
特别是对于内存:currentReplicas
是2;currentMetricValue
是 49;desiredMetricValue
是 80。所以目标副本数是
desiredReplicas = ceil[ 2 * ( 49 / 80 )]
desiredReplicas = ceil[ 2 * 0.61 ]
desiredReplicas = ceil[ 1.26 ]
desiredReplicas = 2
即使您的服务完全空闲,这也会导致(至少)2 个副本,除非服务选择将内存释放回操作系统;这通常取决于语言运行时并且有点超出您的控制。
仅删除内存目标和仅基于 CPU 的自动缩放可能会更符合您的预期。
推荐阅读
- javascript - 我如何在反应中包含第三方库(turn.js)
- php - 当我使用 ionic 从 IOS 设备发送数据时,PHP 错误地接收到数据
- angular - 更改 Angular mat-tabs 的顺序
- talend - 如何忽略talend中特定列中包含null的行?
- python - Python遍历两个列表仅遍历最后一个元素
- azure - 带有服务总线触发器的 v2 Azure 函数未触发
- reactjs - 无法在反应组件中设置加载程序
- node.js - 通过 NodeJS 到 127.0.0.1 的 http 请求获得 ECONNREFUSED 的原因可能是什么?
- django - 如何在Django中使用foreignKey链接两个模型,每个模型都有自己的模板
- node.js - PassportJS openid-client 如何在没有会话的情况下使用,将令牌/用户保存在普通 cookie 中