Client-go: How to get current node name / hostname from pod

Created on 26 Feb 2019  路  3Comments  路  Source: kubernetes/client-go

Hello,

I'm looking from a way from client-go to get current node name or node hostname when the code is running in a pod in the cluster (via a rest.InClusterConfig()).
Is it possible ?

Most helpful comment

you can inject the node name or host IP into environment variables in a pod using the downward API

see https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables for more info

/close

All 3 comments

It seems that no such function is supplied by client-go. you can try :
$ curl -Gs http://localhost:10255/pods/ | grep -o '"nodeName":"[^"]*"' | head -n 1

you can inject the node name or host IP into environment variables in a pod using the downward API

see https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables for more info

/close

@liggitt: Closing this issue.

In response to this:

you can inject the node name or host IP into environment variables in a pod using the downward API

see https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables for more info

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inetkiller picture inetkiller  路  6Comments

mheese picture mheese  路  5Comments

aaron276h picture aaron276h  路  4Comments

strugglingyouth picture strugglingyouth  路  5Comments

h0tbird picture h0tbird  路  3Comments