HELM deploy in GCP: Trying to do an ingress forwarding rule lookup to be used in a hpa

9/2/2020

I have a pod with a loadbalancer in front of it, I am setting up a HPA for that pod and want to use a metric to do scaling.

I need the forwarding rule from my ingress to be assigned to the rule name. There are multiple instances so I need to lookup the value and then use in in my template.

I am having trouble using the lookup function in my template

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta1
metadata:
 name: {{ $.Values.HPA_NAME }}-hpa
spec:
 scaleTargetRef:
   apiVersion: apps/v1
   kind: Deployment
   name: {{ $.Values.HPA_NAME }}
 minReplicas: 1
 maxReplicas: 5
 metrics:
 # for gcp
 - type: External
   external:
     metricName: loadbalancing.googleapis.com|https|request_count
     metricSelector:
       matchLabels:
         resource.labels.forwarding_rule_name: {{ (lookup "v1" "ingress" $.Release.Name "ui-ingress").metadata.annotations "ingress.kubernetes.io/static-ip" | quote }}
     targetAverageValue: 1000m

I am getting this error and can't figure out what am I doing wrong

helm.go:84: [debug] template: http/templates/hpa.yaml:19:89: executing "http/templates/hpa.yaml" at <"ui-ingress">: nil pointer evaluating interface {}.name

If I run kubectl describe ingress I see the value I need to pull out

kubectl describe ingress ui-ingress -n sedcasb-feature-gz-120842-hpa
Name:             ui-ingress
Namespace:        sedcasb-feature-gz-120842-hpa
Address:          34.102.252.166
Default backend:  ui:80 (240.8.30.145:80)

Annotations:
  ingress.kubernetes.io/target-proxy:           k8s2-tp-vppbfd9l-sedcasb-feature-gz-120842-h-ui-ingres-awvi47z2
  meta.helm.sh/release-name:                    helper
  ingress.kubernetes.io/backends:               {"k8s-be-30124--5b45cccad852623f":"HEALTHY"}
  ingress.kubernetes.io/https-forwarding-rule:  k8s2-fs-vppbfd9l-sedcasb-feature-gz-120842-h-ui-ingres-awvi47z2
  ingress.kubernetes.io/https-target-proxy:     k8s2-ts-vppbfd9l-sedcasb-feature-gz-120842-h-ui-ingres-awvi47z2
  ingress.kubernetes.io/ssl-cert:               k8s2-cr-vppbfd9l-0wp6j027xj96tnfd-84b423b39108fc0c
  ingress.kubernetes.io/static-ip:              k8s2-fr-vppbfd9l-sedcasb-feature-gz-120842-h-ui-ingres-awvi47z2
  ingress.kubernetes.io/url-map:                k8s2-um-vppbfd9l-sedcasb-feature-gz-120842-h-ui-ingres-awvi47z2
  meta.helm.sh/release-namespace:               sedcasb-feature-gz-120842-hpa
  ingress.kubernetes.io/forwarding-rule:        k8s2-fr-vppbfd9l-sedcasb-feature-gz-120842-h-ui-ingres-awvi47z2
-- GlebZ
google-cloud-platform
kubernetes
kubernetes-helm

0 Answers