如何使用放大/缩小策略实现Kubernetes水平吊舱自动缩放?
AWS EKS中的Kubernetes v1.19 我试图在EKS集群中实现水平pod自动缩放,并试图模仿我们现在使用ECS所做的。使用ECS,我们可以做如下类似的事情如何使用放大/缩小策略实现Kubernetes水平吊舱自动缩放?,kubernetes,kubernetes-helm,amazon-eks,hpa,Kubernetes,Kubernetes Helm,Amazon Eks,Hpa,AWS EKS中的Kubernetes v1.19 我试图在EKS集群中实现水平pod自动缩放,并试图模仿我们现在使用ECS所做的。使用ECS,我们可以做如下类似的事情 在连续3个1分钟的采样周期后,当CPU>=90%时放大 连续3次1分钟采样后,当CPU=85%时,按比例缩小 内存缩小时水平机架自动缩放器根据观察到的指标(如CPU或内存)自动缩放复制控制器、部署、副本集或有状态集中机架的数量 有一个官方的演练,重点是HPA及其扩展: 缩放副本数量的算法如下所示: desiredRe
- 在连续3个1分钟的采样周期后,当CPU>=90%时放大
- 连续3次1分钟采样后,当CPU=85%时,按比例缩小
- 内存缩小时水平机架自动缩放器根据观察到的指标(如
或CPU
)自动缩放复制控制器、部署、副本集或有状态集中机架的数量 有一个官方的演练,重点是HPA及其扩展:内存
缩放副本数量的算法如下所示:desiredReplicas=ceil[currentReplicas*(currentMetricValue/desiredMetricValue)]
清单实现(已渲染的)自动缩放示例,如下所示:YAML
旁注强>apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: HPA-NAME spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: DEPLOYMENT-NAME minReplicas: 1 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 75 - type: Resource resource: name: memory target: type: Utilization averageUtilization: 75
将使用计算两个指标,并选择一个具有更大的HPA
针对我在问题下写的评论:desiredReplicas
我想我们彼此误解了。“当CPU>=90时放大”是完全可以的,但由于公式背后的逻辑,我认为不可能说“当CPU与特定的
值完全匹配时缩小”。您能告诉我您运行的是哪个Kubernetes版本吗(由于ECS
中的1.18
发生了变化)?此外,我认为您可以尝试将HPA
中的平均利用率设置在两个值之间(缩放时会考虑较大的值),并设置HPA
稳定窗口:@DawidKruk,谢谢。我在EKS中使用的是k8s v1.19。所谓“匹配”是指匹配行为。“我已经阅读了你展示的链接,从那时起我开始提问。本质上,我不希望它像文章所描述的那样四处游荡。但我不知道如何在我的模板中匹配链接中提到的那些章节。@DawidKruk,所以没有办法说“当CPU>=90%时放大”例如?我认为我们彼此误解了。当CPU>=90时,放大是完全可以的,但由于公式背后的逻辑,我认为不可能这么说"当CPU@DawidKruk时,我肯定误解了文档,你也是。因此,
值用于放大,默认情况下,targetAverageUtilization
用于缩小?如果你把你的想法放在一个答案中,我会接受它。谢谢!非常感谢!这更清楚地说明了这一点比我读过的任何文档都多。1/2*targetAverageUtilization
apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: HPA-NAME spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: DEPLOYMENT-NAME minReplicas: 1 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 75 - type: Resource resource: name: memory target: type: Utilization averageUtilization: 75
Name: nginx-scaler Namespace: default Labels: <none> Annotations: <none> CreationTimestamp: Sun, 07 Mar 2021 22:48:58 +0100 Reference: Deployment/nginx-scaling Metrics: ( current / target ) resource memory on pods (as a percentage of request): 5% (61903667200m) / 75% resource cpu on pods (as a percentage of request): 79% (199m) / 75% Min replicas: 1 Max replicas: 10 Deployment pods: 5 current / 5 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 cpu resource utilization (percentage of request) ScalingLimited False DesiredWithinRange the desired count is within the acceptable range Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedGetResourceMetric 4m48s (x4 over 5m3s) horizontal-pod-autoscaler did not receive metrics for any ready pods Normal SuccessfulRescale 103s horizontal-pod-autoscaler New size: 2; reason: cpu resource utilization (percentage of request) above target Normal SuccessfulRescale 71s horizontal-pod-autoscaler New size: 4; reason: cpu resource utilization (percentage of request) above target Normal SuccessfulRescale 71s horizontal-pod-autoscaler New size: 5; reason: cpu resource utilization (percentage of request) above target