Shreyas Holla P
Shreyas Holla P

Reputation: 181

How to get the System HostName of kubernetes deployment inside pod?

In kubernetes we can use environment variable to pass hostIP using

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

So similarly how get hostName instead of HostIP?

Upvotes: 2

Views: 6192

Answers (2)

Vit
Vit

Reputation: 8411

That should be, as already answered, spec.nodeName.

What I also wanted to mention, there is a limited number of fields you can use. Check Capabilities of the Downward API.

Information available via fieldRef:
metadata.name 
metadata.namespace
metadata.uid 
metadata.labels['<KEY>']
metadata.annotations['<KEY>'] 

In addition, the following information is available through downwardAPI volume fieldRef:    
metadata.labels
metadata.annotations 

The following information is available through environment variables:    
status.podIP - the pod's IP address
spec.serviceAccountName 
spec.nodeName - the node's name, available since v1.4.0-alpha.3
status.hostIP - the node's IP, available since v1.7.0-alpha.1 

Upvotes: 2

Edward Rosinzonsky
Edward Rosinzonsky

Reputation: 94

env:
- name: MY_NODE_NAME
  valueFrom:
    fieldRef:
      fieldPath: spec.nodeName

See: https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api

Upvotes: 3

Related Questions