Is it possible to disable service discovery with environment variables in kubernetes?

7/26/2017

As we know, kubernetes supports 2 primary modes of finding a Service - environment variables and DNS, could we disable the first way and only choose the DNS way?

-- zulv
kubernetes

2 Answers

11/12/2018

As shown in this PR, this feature will land with Kubernetes 1.13. From the PR (as Docs are not available yet) I expect it to be the field enableServiceLinks in the pod spec with true as default.

Edit: As it has been a while and the PR finally landed. The enableServiceLinks was added as optional Boolean to the Kubernetes PodSpec.

For the record: using DNS to discover service endpoints is the recommended approach and the docker link behavior, from where the environment variables originate, is long deprecated

-- Ohmen
Source: StackOverflow

10/9/2017

Per kubernetes v1.8 source, it's impossible to disable services discovery with environment variables.

Only service meet either condition is exposed by envVars.

  • service in the same namespace as the pod;
  • kubernetes service in the default namespace;

Even though, these environment variables can be overwritten by env and envFrom defined in pod template.

I'm wondering what's your scenario, maybe we can figure out some workaround.

-- silverfox
Source: StackOverflow