1

可以通过api成功访问,可以清晰的获取信息,通过/apis/custom.metrics.k8s.io/v1beta1

kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1/namespaces/default/services/rabbitmq-exporter/rabbitmq_queue_messages_ready?metricLabelSelector=queue%3Dtest-1 | jq .

{
  "kind": "MetricValueList",
  "apiVersion": "custom.metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/services/rabbitmq-exporter/rabbitmq_queue_messages_ready"
  },
  "items": [
    {
      "describedObject": {
        "kind": "Service",
        "namespace": "default",
        "name": "rabbitmq-exporter",
        "apiVersion": "/v1"
      },
      "metricName": "rabbitmq_queue_messages_ready",
      "timestamp": "2020-02-17T13:50:20Z",
      "value": "14",
      "selector": null
    }
  ]
}

HPA 文件

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: test-hpa
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: test
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: Object
    object:
      metric: 
        name: "rabbitmq_queue_messages_ready"
        selector: 
          matchLabels: 
            "queue": "test-1"
      describedObject:
        apiVersion: "custom.metrics.k8s.io/v1beta1"
        kind: Service
        name: rabbitmq-exporter
      target:
        type: Value
        value: 4

错误信息

Name:                                                                           test-hpa
Namespace:                                                                      default
Labels:                                                                         <none>
Annotations:                                                                    kubectl.kubernetes.io/last-applied-configuration:
                                                                                  {"apiVersion":"autoscaling/v2beta2","kind":"HorizontalPodAutoscaler","metadata":{"annotations":{},"name":"test-hpa","namespace":"defa...
CreationTimestamp:                                                              Mon, 17 Feb 2020 21:38:08 +0800
Reference:                                                                      Deployment/test
Metrics:                                                                        ( current / target )
  "rabbitmq_queue_messages_ready" on Service/rabbitmq-exporter (target value):  <unknown> / 4
Min replicas:                                                                   1
Max replicas:                                                                   5
Deployment pods:                                                                1 current / 0 desired
Conditions:
  Type           Status  Reason                 Message
  ----           ------  ------                 -------
  AbleToScale    True    SucceededGetScale      the HPA controller was able to get the target's current scale
  ScalingActive  False   FailedGetObjectMetric  the HPA was unable to compute the replica count: unable to get metric rabbitmq_queue_messages_ready: Service on default rabbitmq-exporter/object metrics are not yet supported
Events:
  Type     Reason                        Age                   From                       Message
  ----     ------                        ----                  ----                       -------
  Warning  FailedComputeMetricsReplicas  97s (x12 over 4m22s)  horizontal-pod-autoscaler  Invalid metrics (1 invalid out of 1), last error was: failed to get object metric value: unable to get metric rabbitmq_queue_messages_ready: Service on default rabbitmq-exporter/object metrics are not yet supported
  Warning  FailedGetObjectMetric         82s (x13 over 4m22s)  horizontal-pod-autoscaler  unable to get metric rabbitmq_queue_messages_ready: Service on default rabbitmq-exporter/object metrics are not yet supported

4

0 回答 0