Where does kubernete's kubelet create service environment variables?

681 views Asked by At

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

  1. use the environment variables set by the kubelet.

  2. use skydns

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 env or sudo env 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?

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

Not as important, but related, how does this all work across multiple nodes?

1

There are 1 answers

0
Alex Robinson On BEST ANSWER

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

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

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

You can test this out by attaching a terminal to one of your containers, as explained here.