Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

kubernetes

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!

like image 488
Behram Mistree Avatar asked Dec 05 '25 18:12

Behram Mistree


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.

like image 109
coderanger Avatar answered Dec 08 '25 14:12

coderanger