Resolve service IP in environment variable in Kubernetes

4/17/2020

When I pass service name in environment variable in YAML file, that service name is still string, it's not being resolved in real ip address.

Example:

env:
  - name: ES
    value: elasticsearch

Thanks

-- ali bouaziz
google-cloud-platform
kubernetes

1 Answer

4/17/2020

You should be able to use it directly and it should resolve fine:

curl $ES

If you use it inside your application it should also work.

Just consider that Kubernetes uses its internal DNS and the that "elasticsearch" name should only work inside the same namespace. In fact it will resolve to:

elasticsearch.<namespace>.svc.cluster.local.

If your elastic service is running in different namespace, make sure you use elastic.<target_namespace>.

-- paulopontesm
Source: StackOverflow