简体   繁体   English

如何在kubernetes中获取workernode的接口IP

[英]How to fetch interface IP of workernode in kubernetes

I have a worker node where I added an additional interface named eth1 using multus CNI.我有一个工作节点,我在其中使用 multus CNI 添加了一个名为 eth1 的附加接口。 eth0 is provided by kubernetes. eth0 由 kubernetes 提供。 So I have two interfaces.所以我有两个接口。 Each interface has an external IP (10.94. . ) and internal IP(10.32. . ).每个接口都有一个外部 IP(10.94 ... )和内部 IP(10.32 ... )。 Inside my pod, same eth0 and eth1 internal IPs can be seen.在我的 pod 内,可以看到相同的 eth0 和 eth1 内部 IP。 Can I fetch any of external IP or internal IP inside containers using helm inbuilt functions ?我可以使用 helm 内置函数获取容器内的任何外部 IP 或内部 IP 吗? Is there a possibility to fetch the IPs using curl or helm or kubernetes provided objects?是否有可能使用 curl 或 helm 或 kubernetes 提供的对象来获取 IP? I am expecting this IPs to be fetched and used as container's env variables.我期待这些 IP 被获取并用作容器的环境变量。

It would be really helpful if someone helps me on this.如果有人在这方面帮助我,那将非常有帮助。 Thanks in advance!提前致谢!

You definitely can't get this information from Helm.您绝对无法从 Helm 获得这些信息。 Helm doesn't know where your pods will eventually be scheduled, or what interfaces they'll have, or even if those nodes will still exist before Helm runs again. Helm 不知道您的 pod 最终将被安排在哪里,或者它们将具有哪些接口,或者即使在 Helm 再次运行之前这些节点仍然存在。

The only real way a pod has to find about about its node is the downward API . pod 必须找到关于其节点的唯一真正方法是向下 API In principle you can use this to find out a node IP address原则上,您可以使用它来找出节点IP 地址

# templates/deployment.yaml
env:
  - name: NODE_NAME
    valueFrom:
      fieldRef:
        fieldPath: spec.nodeName
  - name: NODE_IP
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP

However, the documentation for the EnvVarSource API type notes that only a limited number of pod fields are supported.但是, EnvVarSource API 类型的文档指出,仅支持有限数量的 pod 字段。 Also note that these are injected into environment variables as strings, so there's no support for list-type values.另请注意,这些是作为字符串注入环境变量的,因此不支持列表类型的值。

IME it's unusual for nodes to be directly exposed to the Internet. IME 节点直接暴露在互联网上是不寻常的。 You'd generally connect from the outside, to a load balancer in a DMZ, to a Kubernetes Service, to the pod.您通常会从外部连接到 DMZ 中的负载均衡器、Kubernetes 服务和 pod。 In this case a pod would have no way of finding out the external DNS name, but it'd also be unlikely to change once configured, so you could inject it as a normal environment variable.在这种情况下,一个 pod 将无法找到外部 DNS 名称,但它也不太可能在配置后更改,因此您可以将其作为普通环境变量注入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM