<p>I'm creating a kubernetes cluster, and in it I have several services. I know based on <a href="https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services.md#discovering-services" rel="nofollow">https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services.md#discovering-services</a> I have two options.</p>

<ol>
<li><p>use the environment variables set by the kubelet.</p></li>
<li><p>use skydns</p></li>
</ol>

<p>I want to try to use the environment variables first before I go adding another dependency into the mix.  However, I'm unsure where the environment variables are for each service. I haven't found them when doing <code>env</code> or <code>sudo env</code> on the kubelet.  Are they within a certain container and/or pod? If so do I have to link the other pods to that one to get its environment variables for services?</p>

<p>I have several NodeJS services in containers, so I'm wondering if talking to each service would require this to get the ip:
<code>process.env('SERVICE_X_PUBLIC_IPV4')</code> once I have the environment variable thing sorted out.</p>

<p>Not as important, but related, how does this all work across multiple nodes?</p>

<p>The environment variables for a given service are put in every container that is started after the service was created.</p>

<p>For example, if you create a pod <code>foo</code> and then later a service <code>bar</code>, the pod's containers won't have any environment variables for <code>bar</code>.</p>

<p>If you instead create service <code>bar</code> and then a pod <code>foo</code>, the pod's containers should have environment variables something like:
<code>
BAR_PORT=tcp://10.167.240.1:80
BAR_SERVICE_HOST=10.167.240.1
</code></p>

<p>You can test this out by attaching a terminal to one of your containers, as explained <a href="https://stackoverflow.com/a/26496854/1925481">here</a>.</p>
