我按照这里的https://cloud.google.com/kubernetes-engine/docs/tutorials/external-metrics-autoscaling设置了HorizontalPodAutoscaler,以根据来自发布/订阅的未确认消息的数量进行缩放。我的愿望是,如果存在多于1条未确认的消息,则窗格会扩展。当我运行k describe hpa
时,我得到:
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"autoscaling/v2beta1","kind":"HorizontalPodAutoscaler","metadata":{"annotations":{},"name":"foobar-gke-prod","namespace":"defau...
CreationTimestamp: Mon, 25 May 2020 18:01:33 -0700
Reference: Deployment/foobar-gke-prod
Metrics: ( current / target )
"pubsub.googleapis.com|subscription|num_undelivered_messages" (target average value): 200m / 1
Min replicas: 3
Max replicas: 9
Deployment pods: 5 current / 5 desired
返回的指标数据使我感到困惑。当我运行该命令时,根据控制台指标,未确认的知识消息的数量约为4。所以我不明白200m
是什么意思?为什么不说4?
这是我对HPA的配置
# Template from https://cloud.google.com/kubernetes-engine/docs/tutorials/external-metrics-autoscaling
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: foobar-gke-prod
spec:
minReplicas: 3
maxReplicas: 9
metrics:
- external:
metricName: pubsub.googleapis.com|subscription|num_undelivered_messages
metricSelector:
matchLabels:
resource.labels.subscription_id: prod_foobar_subscription
targetAverageValue: "1"
type: External
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: foobar-gke-prod
答案 0 :(得分:1)
参考示例:
Name: pubsub
...
Metrics: ( current / target )
"pubsub.googleapis.com|subscription|num_undelivered_messages" (target average value): 2250m / 2
Min replicas: 1
Max replicas: 4
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True SucceededRescale the HPA controller was able to update the target scale to 4
ScalingLimited True TooManyReplicas the desired replica count is more than the maximum replica count
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulRescale 7s horizontal-pod-autoscaler New size: 4; reason: external metric pubsub.googleapis.com|subscription|num_undelivered_messages(&LabelSelector{MatchLabels:map[string]string{resource.labels.subscription_id: echo-read,},MatchExpressions:[],}) above target
返回的指标数据使我感到困惑。当我运行该命令时,根据控制台指标,未确认的知识消息的数量约为4。所以我不明白200m是什么意思?为什么不说4?
200m/1
意味着,在HPA测量时,此时每个正在运行的副本的未送达邮件的平均数量为0.2(20%)。注意事项:
读取5个Pod的4条消息将导致800m的负载,但那时候hpa可能已经在运行另一个放大事件。
我建议您同时阅读指标控制台和hpa,然后再次进行验证。
如果您仍然认为结果与此处更新的hpa describe与此处发布的结果不匹配,我们可以再看看。
编辑:
是否有办法使指标不是豆荚的平均值?即如果有5条未确认的消息,则指标数据将读取5000m?
来自Kubernetes API参考ExternalMetricSource v2beta1 Autoscaling:
targetAverageValue
是全局指标(以数量为单位)的目标单舱值。
targetValue
是指标的目标值(以数量为单位)。
请注意,targetAverageValue
和targetValue
是互斥的。
因此,如果要总计而不是平均值,只需将其交换到HPA上即可。