kubernete的kubelet在哪里创建服务环境变量?

时间:2021-01-28 23:14:13

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.

我正在创建一个kubernetes集群,其中有几个服务。我知道基于https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services.md我有两个选项。

  1. use the environment variables set by the kubelet.

    使用kubelet设置的环境变量。

  2. use skydns

    使用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?

在添加另一个依赖项之前,我想先使用环境变量。但是,我不确定每个服务的环境变量在哪里。在kubelet上做env或sudo env的时候我还没找到。它们是否在某个容器和/或pod中?如果是这样的话,我是否需要将其他的pod链接到那个来获取服务的环境变量?

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.

我在容器中有几个NodeJS服务,所以我想知道,在我整理好环境变量之后,与每个服务进行对话是否需要这个来获得ip: process.env(“SERVICE_X_PUBLIC_IPV4”)。

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

这并不重要,但有关系,这是如何在多个节点上工作的?

1 个解决方案

#1


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.

例如,如果您创建一个pod foo,然后再创建一个服务bar,那么pod的容器将不会有任何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

如果您创建服务条,然后创建pod foo,那么pod的容器应该具有如下环境变量: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.

您可以通过将终端连接到您的一个容器来测试这一点,如这里所述。

#1


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.

例如,如果您创建一个pod foo,然后再创建一个服务bar,那么pod的容器将不会有任何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

如果您创建服务条,然后创建pod foo,那么pod的容器应该具有如下环境变量: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.

您可以通过将终端连接到您的一个容器来测试这一点,如这里所述。