How do I use a pod name in a volume mount?

Viewed 164

Is there a way to specify a hostPath volume so that it includes the pod's name? For example, something like the following:

  volumes:
    - name: vol-test
      hostPath:
        path: /basedir/$(POD_NAME)
        type: Directory

Simply using /basedir directly and then have the pod itself query for its name and create the directory doesn't satisfy my needs: I specifically want to map each of my containers' /tmp folders to specific volumes.

I know that something similar works with valueFrom for environment variables (see here), but so far I haven't been able to find anything similar for volumes.

Please let me know if anyone has any ideas. Thanks!

1 Answers

You set it as an env var first via valueFrom and then certain fields understand $(FOO) as an env var reference to be interpolated at runtime.

EDIT: And path is not one of those fields. But subPathExpr is.

Related