I have a nodejs app which has refers to the IP Address of the kubernetes service/load balancer public IP. Is there a way to get it from the process/env variables in runtime?
e..g process.env.ENV_VARIABLE
and what is the env variable name
Thanks
It's not available as an environment variable. Also keep in mind that a pod can receive traffic from multiple load balancers and also the external IP could change after the Pod started, leaving a stale value; so an IP in an environment variable might not be an adequate solution.
If you are using an Ingress object you can determine it's external IP by querying the Kubernetes apiserver (try kubectl get myingress -o yaml
, see the status:
part).
For a particular incoming http request check the X-Forwarded-For:
header for the load balancer's IP.
Since the question is tagged google-container-engine, you can also use gcloud to get that IP (perhaps from an initContainer or at startup):
gcloud compute forwarding-rules describe k8s-fw-YOURNAMESPACE-YOURINGRESSNAME--YOURHASHVALUE --global --format='value(IPAddress)'
gcloud compute addresses describe my-static-ip-name --global --format='value(address)'