Using request count for hpa

8/28/2019

I am trying to deploy HorizontalPodAutoscaler on GKE referring the following link

#HPA.yaml
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: hello-hpa
spec:
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - external:
      metricName: loadbalancing.googleapis.com|https|backend_request_count
      metricSelector:
        matchLabels:
          resource.labels.forwarding_rule_name:
            k8s-fw-default-hello-hpa--fbeacb94cfa9120e
      targetAverageValue: "1"
    type: External
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: hello-hpa

Here k8s-fw-default-hello-hpa--fbeacb94cfa9550e is the name of the forwarding rule in ingress.

The above works for us but we would like to automate the deployment process where even when there is a change in the Ingress/HPA object it should work without human intervention. AFAIK the forwarding rule name changes per deployment and this requires us to go and change the HPA object accordingly.

Is there some way to get that value as a reference to point to something that is same across deployments?

Where can I describe the external metrics to see if we can use some other selector? Referenced this and this but did not find anything

It would be great if I could use the service name (or may be service name and project id pair) to filter.

example-

       matchLabels:
          resource.labels.forwarding_rule_name:
            k8s-fw-default-hello-hpa.*

OR

       matchLabels:
          resource.labels.backend_name: hello-hpa

OR

       matchLabels:
          resource.labels.backend_name: hello-hpa
          resource.labels.project_id: hello-project
-- Aditya Guru
autoscaling
google-cloud-platform
google-kubernetes-engine
kubernetes

0 Answers