Inside a service yaml file, you can use jsonpath to select a named nodeport value like so:
- name: MY_NODE_PORT
valueFrom:
fieldRef:
fieldPath: spec.ports[?(@.name=="http")].nodePort
However, in my deployment yaml file, I would like to have an environment variable like MY_NODE_PORT above that is exposed to the container to the pod. I happen to have combined my service and deployment into a single file for me to kubectl create -f. Is it possible to select the named service nodeport in the deployment section, rather than in the service section?
My purpose is to register a Kubernetes service and deployment to a legacy service discovery mechanism, in this case Netflix OSS Eureka.