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

2/16/2022

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?

-- Shreyas Holla P
kubernetes
kubernetes-pod

2 Answers

2/16/2022

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 
-- Vit
Source: StackOverflow

2/16/2022
-- Edward Rosinzonsky
Source: StackOverflow