如何从 Pod 内部获取节点 IP? [英] How do you get the Node IP from inside a Pod?

查看:37
本文介绍了如何从 Pod 内部获取节点 IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 go 应用程序,该应用程序正在创建作为节点特定指标的普罗米修斯指标,我希望能够将节点 IP 添加为标签.

I am running a go app that is creating prometheus metrics that are node specific metrics and I want to be able to add the node IP as a label.

有没有办法从 Pod 内捕获节点 IP?

Is there a way to capture the Node IP from within the Pod?

推荐答案

有没有办法从 Pod 内捕获节点 IP?

Is there a way to capture the Node IP from within the Pod?

是的,使用 env: valueFrom: fieldRef: status.hostIP;整个(?)列表显示在 envVarSource 文档,我猜是因为 objectFieldSelector 可以出现在多个上下文中.

Yes, easily, using the env: valueFrom: fieldRef: status.hostIP; the whole(?) list is presented in the envVarSource docs, I guess because objectFieldSelector can appear in multiple contexts.

所以:

containers:
- env:
  - name: NODE_IP
    valueFrom:
      fieldRef:
         status.hostIP

这篇关于如何从 Pod 内部获取节点 IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆