<p>I am trying to set configurable host paths in kubernetes, but I am facing issues. I created a config map, which has the path and then I'm trying to replace the placeholder with the config map value. Here is my configuration:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: php
  namespace: app
spec:
  template:
    spec:
      containers:
      - name: php
        env:
        - name: PHP_FOLDER
          valueFrom:
            configMapKeyRef:
              name: local-paths
              key: CODE_PATH
      volumes:
      - name: src-code
        hostPath:
          path: PHP_FOLDER
          type: Directory
</code></pre>

<p>I also tried </p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: php
  namespace: app
spec:
  template:
    spec:
      containers:
      - name: php
        env:
        - name: PHP_FOLDER
          valueFrom:
            configMapKeyRef:
              name: local-paths
              key: CODE_PATH
      volumes:
      - name: src-code
        hostPath:
          path: $(PHP_FOLDER)
          type: Directory 
</code></pre>

<p>I either get Error: <code>Error response from daemon: 
create $(PHP_FOLDER): "$(PHP_FOLDER)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path</code> or <code>MountVolume.SetUp failed for volume "src-code" : hostPath type check failed: PHP_FOLDER is not a directory</code></p>

norbit
<p>You just can't use environment values in yaml files directly. What you did actually a lot worse. ConfigMaps or secrets are created in runtime which means they won't be available until container starts running. However yaml parsing happens before pod or deployment even created. I think you should practice timeline more until you are using kubernetes in production or even testing.</p>

<p>In this case best practice would be to use bash script to change yaml file just before deploying and automatize it.</p>
