Scaling GKE pods based on number of active connections per pod
Ok I managed to figure this out by looking up the schema for the HPA (https://docs.okd.io/latest/rest_api/apis-autoscaling/v2beta1.HorizontalPodAutoscaler.html).
In short, I was using the wrong metric type (as above you can see I am using "Pods", but I should be using "External").
The correct HPA specification is:
apiVersion: autoscaling/v2beta1kind: HorizontalPodAutoscalermetadata: name: hpa-uat-active-connections namespace: defaultspec: minReplicas: 3 maxReplicas: 6 metrics: - type: External external: metricName: custom.googleapis.com|nginx-ingress-controller|nginx_ingress_controller_nginx_process_connections metricSelector: matchLabels: metric.labels.state: active resource.labels.cluster_name: [redacted] targetAverageValue: 5 scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: [redacted]
As soon as I did this, things worked right away:
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGEhpa-uat-active-connections Deployment/bustle-webapp-uat-deployment 334m/5 (avg) 3 6 3 30s