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

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

问题描述

我正在运行一个go应​​用,该应用正在创建作为节点特定指标的prometheus指标,并且希望能够将节点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天全站免登陆