0
votes

The HPA docs at https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/ provide two examples of the selector property, one for the pod and the other for the object metric types. One of these examples is a nested object, the other is a string. For example:

- type: External
  external:
    metric:
      name: queue_messages_ready
      selector: "queue=worker_tasks"
    target:
      type: AverageValue
      averageValue: 30

and

type: Object
object:
  metric:
    name: http_requests
    selector: {matchLabels: {verb: GET}}

The API docs at https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#metricidentifier-v2beta2-autoscaling provide this description for the selector field:

selector is the string-encoded form of a standard kubernetes label selector for the given metric

So does this mean you can define the selector property as a string (for example selector: "matchLabels: {verb: GET}") as well as a nested object?

1

1 Answers

1
votes

It turns out the selector has to be a map, or you get the following error:

error: error validating "customresource.yml": error validating data: ValidationError(HorizontalPodAutoscaler.spec.metrics[0].object.metric.selector): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector: got "string", expected "map"; if you choose to ignore these errors, turn validation off with --validate=false 

This applies to the external metric type too, so the K8s docs appear to be incorrect when they provide an example passing a string.