AbreQueVoy
AbreQueVoy

Reputation: 2316

How to get kubernetes host IP from inside of a pod?

Let's say we have a frontend and a backend pods running in a kubernetes cluster.

Both pods have corresponding services exposing them on the host (type: NodePort). In the end, the frontend uses <Host IP>:<Port 1>, and the backend runs on <Host IP>:<Port 2>.

How to find out the host IP so that it could be used in the frontend pod (to be defined as a value of a variable)? Tried with setting localhost, but it didn't work, so probably the exact IP has to be defined.

Upvotes: 2

Views: 3023

Answers (2)

SHANTIMOY BANERJEE
SHANTIMOY BANERJEE

Reputation: 44

Update "deployment.yaml" like below enter image description here

Upvotes: 0

Botje
Botje

Reputation: 31183

Use the downward API:

spec:
  image: ...
  env:
   - name: REACT_APP_BACKEND_URL
     valueFrom:
       fieldRef:
         fieldPath: status.hostIP

Upvotes: 8

Related Questions