HPA labelSelector不过滤外部指标

时间:2019-11-07 21:45:17

标签: kubernetes prometheus autoscaling

我正在尝试在EKS群集(v1.13.10-eks-5ac0f1)上设置基于自定义指标的自动缩放器,但是看起来外部指标标签的labelSelector过滤器未过滤。

使用k8s-prometheus-adaptermetrics-server(v0.3.6),我已经成功地从prometheus导出了指标作为kubernetes外部指标。

该指标已正确导出,并在kubernetes api上可见:

kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/*/sqs_queue_messages"

{
  "kind": "ExternalMetricValueList",
  "apiVersion": "external.metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/external.metrics.k8s.io/v1beta1/namespaces/%2A/sqs_queue_messages"
  },
  "items": [
    {
      "metricName": "sqs_queue_messages",
      "metricLabels": {
        "__name__": "sqs_queue_messages",
        ...
        "queue_name": "temp-queue"
      },
      "timestamp": "2019-11-07T21:14:44Z",
      "value": "0"
    },
    {
      "metricName": "sqs_queue_messages",
      "metricLabels": {
        "__name__": "sqs_queue_messages",
        ...
        "queue_name": "random-queue"
      },
      "timestamp": "2019-11-07T21:14:44Z",
      "value": "0"
    }
  ]
}

horizo​​ntal-pod-autoscaler.yml

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: api
  namespace: api
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 2
  maxReplicas: 5
  metrics:
    - external:
        metricName: sqs_queue_messages
        metricSelector:
          matchLabels:
            queue_name: temp-queue
        targetAverageValue: "100"
      type: External

问题在于HPA并没有只选择具有匹配标签的指标,实际上通过查看日志我可以看到执行了以下调用

kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/*/sqs_queue_messages?labelSelector=queue_name%3Dtemp-queue"

预期结果仅为一项(与 queue_name:temp-queue 标签匹配的一项),但过滤器将被忽略,并返回所有结果。

0 个答案:

没有答案