How to use the POD_NAME combined with other value in a kubernetes configuration attribute

10/25/2017

I am trying to configure a persistent disk for Kafka in Kubernetes, I need to set the mount path to /kafka/POD_NAME/.

I can get the pod name as explained here from:

  env:
    - name: POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name

I am asking how to use this POD_NAME inside the mountPath value, something like: `/

-- bigOther
apache-kafka
google-kubernetes-engine
kubernetes

1 Answer

10/26/2017

The Downward API, as the name indicates, is used to expose extra kubernetes related information to the containers. What you want is for your yaml file definitions to have variable or dynamic values based on the runtime pods being launched. This is currently not possible.

You might want to try to do something with Helm templates which in a StatefulSet with a PVC would allow you to have predictable pod+volume names and maybe insert a dynamic mountpath, but I haven't tried this myself.

Further, if you're setting this up as recommended, which is in a StatefulSet, it is preferable that the inner spec template for the containers are exactly the same.

-- vascop
Source: StackOverflow