'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?



Solution 1:[1]

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 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vit