kubernetes: Cannot access fieldRef for `spec.nodeName` or `status.podIP` through downwardAPI volume interface

Is this a BUG REPORT or FEATURE REQUEST?:

/kind bug

What happened:

Applying this Pod configuration:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-files
spec:
  containers:
    - name: dapi-files
      image: superorbital/toolbox:latest
      command: ["sh", "-c"]
      args:
      - while true; do grep -H "" /etc/podinfo/*; sleep 5; done;
      volumeMounts:
        - name: podinfo
          mountPath: /etc/podinfo
          readOnly: true
  volumes:
    - name: podinfo
      downwardAPI:
        items:
          - path: "nodename"
            fieldRef:
              fieldPath: spec.nodeName
          - path: "address"
            fieldRef:
              fieldPath: status.podIP

Resulted in this error:

$ kubectl apply -f dapi-files.yaml
The Pod "dapi-files" is invalid:
* spec.volumes[0].downwardAPI.fieldRef.fieldPath: Unsupported value: "spec.nodeName": supported values: "metadata.annotations", "metadata.labels", "metadata.name", "metadata.namespace", "metadata.uid"
* spec.volumes[0].downwardAPI.fieldRef.fieldPath: Unsupported value: "status.podIP": supported values: "metadata.annotations", "metadata.labels", "metadata.name", "metadata.namespace", "metadata.uid"
* spec.containers[0].volumeMounts[0].name: Not found: "podinfo"

What you expected to happen:

I expected the Pod to run, with the nodename available in /etc/podinfo/nodename and the IP address available in /etc/podinfo/address.

How to reproduce it (as minimally and precisely as possible):

The above is about as minimal a reproduction as I can come up with.

Anything else we need to know?:

The documentation for the file based downwardAPI implies I should be able to access these values (emphasis added):

The following information is available to containers through environment variables and downwardAPI volumes:

Information available via fieldRef:

  • spec.nodeName - the node’s name
  • status.hostIP - the node’s IP
  • metadata.name - the pod’s name
  • metadata.namespace - the pod’s namespace
  • status.podIP - the pod’s IP address
  • spec.serviceAccountName - the pod’s service account name
  • metadata.uid - the pod’s UID
  • metadata.labels['<KEY>'] - the value of the pod’s label <KEY> (for example, metadata.labels['mylabel']); available in Kubernetes 1.9+
  • metadata.annotations['<KEY>'] - the value of the pod’s annotation <KEY> (for example, metadata.annotations['myannotation']); available in Kubernetes 1.9+

However, kubectl explain seems to agree that those fieldRefs aren’t allowed:

$ kubectl explain pod.spec.volumes.downwardAPI.items.fieldRef
RESOURCE: fieldRef <Object>

DESCRIPTION:
     Required: Selects a field of the pod: only annotations, labels, name and
     namespace are supported.

     ObjectFieldSelector selects an APIVersioned field of an object.

FIELDS:
   apiVersion	<string>
     Version of the schema the FieldPath is written in terms of, defaults to
     "v1".

   fieldPath	<string> -required-
     Path of the field to select in the specified API version.

Maybe this is a documentation issue?

Environment:

  • Kubernetes version (use kubectl version):
    Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"darwin/amd64"}
    Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.2-gke.1", GitCommit:"75d2af854b1df023c7ce10a8795b85d3dd1f8d37", GitTreeState:"clean", BuildDate:"2018-05-10T17:23:18Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}
    
  • Cloud provider or hardware configuration: GKE running 1.10
  • OS (e.g. from /etc/os-release): Container-Optimized OS
  • Kernel (e.g. uname -a): Linux gke-lab-default-pool-74632492-rnkr 4.4.111+
  • Install tools:
  • Others:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 37 (11 by maintainers)

Most upvoted comments

I can confirm that it is not yet possible to access the fields:   - status.podIP   - status.hostIP   - spec.nodeName

tested on AKS running 1.14.6

/remove-lifecycle stale

I still see this issue, with below mentioned version.

[root@k8master ~]# kubectl version -o yaml
clientVersion:
  buildDate: "2018-12-13T10:39:04Z"
  compiler: gc
  gitCommit: eec55b9ba98609a46fee712359c7b5b365bdd920
  gitTreeState: clean
  gitVersion: v1.13.1
  goVersion: go1.11.2
  major: "1"
  minor: "13"
  platform: linux/amd64
serverVersion:
  buildDate: "2018-12-13T10:31:33Z"
  compiler: gc
  gitCommit: eec55b9ba98609a46fee712359c7b5b365bdd920
  gitTreeState: clean
  gitVersion: v1.13.1
  goVersion: go1.11.2
  major: "1"
  minor: "13"
  platform: linux/amd64

[root@k8master ~]# cat test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: kubernetes-downwardapi-volume-example
  labels:
    zone: us-est-coast
    cluster: test-cluster1
    rack: rack-22
  annotations:
    build: two
    builder: john-doe
spec:
  containers:
    - name: client-container
      image: k8s.gcr.io/busybox
      command: ["sh", "-c"]
      args:
      - while true; do
          if [[ -e /etc/podinfo/labels ]]; then
            echo -en '\n\n'; cat /etc/podinfo/labels; fi;
          if [[ -e /etc/podinfo/annotations ]]; then
            echo -en '\n\n'; cat /etc/podinfo/annotations; fi;
          sleep 5;
        done;
      volumeMounts:
        - name: podinfo
          mountPath: /etc/podinfo
          readOnly: false
  volumes:
    - name: podinfo
      downwardAPI:
        items:
          - path: "nodename"
            fieldRef:
              fieldPath: spec.nodeName
          - path: "address"
            fieldRef:
              fieldPath: status.podIP
[root@k8master ~]# kubectl create -f test.yaml
The Pod "kubernetes-downwardapi-volume-example" is invalid:
* spec.volumes[0].downwardAPI.fieldRef.fieldPath: Unsupported value: "spec.nodeName": supported values: "metadata.annotations", "metadata.labels", "metadata.name", "metadata.namespace", "metadata.uid"
* spec.volumes[0].downwardAPI.fieldRef.fieldPath: Unsupported value: "status.podIP": supported values: "metadata.annotations", "metadata.labels", "metadata.name", "metadata.namespace", "metadata.uid"
* spec.containers[0].volumeMounts[0].name: Not found: "podinfo"
[root@k8master ~]#