如何在Kubernetes中获取Workernode IP

发布于 2025-02-05 03:15:14 字数 243 浏览 5 评论 0原文

我有一个工人节点,在其中使用Multus CNI添加了一个名为ETH1的其他接口。 ETH0由Kubernetes提供。所以我有两个接口。每个接口都有外部IP和内部IP。在我的吊舱内,可以看到相同的ETH0和ETH1内部IP。我可以使用内置功能获取任何外部IP或内部IP内部IP内部的IN内部集装箱吗?是否有可能使用IP的IP 卷发或舵或kubernetes提供了对象?我希望将此IPs获取并用作容器的ENV变量。

如果有人帮助我,这真的很有帮助。提前致谢!

I have a worker node where I added an additional interface named eth1 using multus CNI. eth0 is provided by kubernetes. So I have two interfaces. Each interface has an external IP and internal IP. Inside my pod, same eth0 and eth1 internal IPs can be seen. Can I fetch any of external IP or internal IP inside containers using helm inbuilt functions ? Is there a possibility to fetch the IPs using
curl or helm or kubernetes provided objects? I am expecting this IPs to be fetched and used as container's env variables.

It would be really helpful if someone helps me on this. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情勿念 2025-02-12 03:15:15

您绝对无法从Helm那里获得此信息。 Helm不知道您的豆荚最终将被安排在哪里,或者他们将拥有哪些接口,即使这些节点仍然存在在Helm再次运行之前。

POD必须找到有关其节点的唯一真正的方法是向下api 。原则上,您可以使用它来找出 a 节点IP地址,

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

但是, envvarsource API类型注释,仅支持有限数量的POD字段。另请注意,将它们注入环境变量作为字符串,因此对列表类型值不支持。

IME直接接触到互联网是不寻常的。您通常会从外部连接到DMZ中的负载平衡器,再到kubernetes服务,再到吊舱。在这种情况下,POD将无法找到外部DNS名称,但是配置后也不太可能更改,因此您可以将其注入正常环境变量。

You definitely can't get this information from 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.

The only real way a pod has to find about about its node is the downward API. In principle you can use this to find out a node IP address

# 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. 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. You'd generally connect from the outside, to a load balancer in a DMZ, to a Kubernetes Service, to the 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文