How to get service's NodePort programmatically in Kubernetes?

Viewed 1091

I developed two web apps(we call them A and B) and deployed them to k8s. The web app A refers to the images generated by web app B. In previous environment, B has the fixed IP and port which makes it very easier to reach the images hosted on B.

In the K8S environment, I use the service type - NodePort. In that case, the port is randomly generated upon deployment each time.

The question is whether there is a way to fetch B service's node port programmatically from the A Pod. Or is it possible to fix the node port for one service?

1 Answers
Related