In my deployment.yaml I know how to pass an env variable to the pod, with value being the value of a field in the yaml - e.g. if I wanted to pass the name of the deployment as POD_NAME:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
What's beyond nice, is to pass also some dynamic data coming from after the deployment has been applied, such as the name of the node or the IP
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
However this is good for same-file attributes, i.e. POD_NAME's value comes from a field in the same yaml.
Enter the case of horizontalpodautoscaler, on an external metric:
external:
metricName: loadbalancing.googleapis.com|https|request_count
metricSelector:
matchLabels:
resource.labels.target_proxy_name: k8s-tps-appname-appname-ingress--bc0438048d5e90
I have a selector based on a label resource.labels.target_proxy_name
.
I would like to reference the annotation target-proxy
of the ingress instead of declaring (hardcoding) k8s-tps-appname-appname-ingress--bc0438048d5e90
Is it possible somehow?
Thanks,
I don't think it's possible. For the matchLabels
field you must provide a string as value. You don't have any means there like the fieldRef
for container environment variables.
A possible way to solve this problem is to create a custom MutatingAdmissionWebhook admission controller which listens for the creation of HorizontalPodAutoscalers and inserts the annotation of the corresponding Ingress in the matchLabels
field before it is persisted in the database.