3

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?

Christian Grabowski
  • 2,782
  • 3
  • 32
  • 57
  • Have you tried execing into one of the containers? That's where I'd expect the variables to be set, given that that's where they'll be used by applications. (I would personally recommend using the DNS option, but that's a different matter.) – Jon Skeet Jun 17 '15 at 21:20

1 Answers1

3

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.

Community
  • 1
  • 1
Alex Robinson
  • 12,633
  • 2
  • 38
  • 55