How do you get the Node IP from inside a Pod?

后端 未结 2 592
时光取名叫无心
时光取名叫无心 2021-01-02 00:49

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.

Is there a way to captu

相关标签:
2条回答
  • 2021-01-02 01:27

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

    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.

    so:

    containers:
    - env:
      - name: NODE_IP
        valueFrom:
          fieldRef:
             status.hostIP
    
    0 讨论(0)
  • 2021-01-02 01:44

    The accepted answer didn't work for me, it seems fieldPath is required now:

      env:
        - name: NODE_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
    
    0 讨论(0)
提交回复
热议问题