<p>I am writing a manifest for app deployment in Kubernetes v1.18.</p>

<p>I am hoping to have the hostpath directory created with POD name in it. 
Is this possible? It don't seem to work. </p>

<pre><code> - name: datastore
    hostPath:
      path: /opt/datastore/${spec.podName}
      type: DirectoryOrCreate
</code></pre>

<p>You could define an environment variable <code>POD_NAME</code> and refer to it </p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  containers:
  - name: container1
    env:
    - name: POD_NAME
      valueFrom:
        fieldRef:
          apiVersion: v1
          fieldPath: metadata.name
    image: busybox
    command: [ "sh", "-c", "while [ true ]; do echo 'Hello'; sleep 10; done | tee -a /logs/hello.txt" ]
    volumeMounts:
    - name: workdir1
      mountPath: /logs
      subPathExpr: $(POD_NAME)
  restartPolicy: Never
  volumes:
  - name: workdir1
    hostPath:
      path: /var/log/pods
</code></pre>
