<p>How can I mount a hostPath into each pod in a statefulset when I don't know the names of the nodes in advance (so can't pre-create a PV on each node)?</p>
<p>I want to set up an elasticsearch cluster on a number of nodes, mounting each elasticsearch data directory onto the SSD of the host node...</p>
<p>How can I accomplish this with a statefulset?</p>

GDev
<p>Instead of a <em>HostPath Volume</em>, you should use a <a href="https://kubernetes.io/blog/2019/04/04/kubernetes-1.14-local-persistent-volumes-ga/" rel="nofollow noreferrer">Local Persistent Volume</a> for this kind of use cases.</p>
<blockquote>
<p>The biggest difference is that the Kubernetes scheduler understands which node a Local Persistent Volume belongs to. With HostPath volumes, a pod referencing a HostPath volume may be moved by the scheduler to a different node resulting in data loss. But with Local Persistent Volumes, the Kubernetes scheduler ensures that a pod using a Local Persistent Volume is always scheduled to the same node.</p>
</blockquote>
<p>Consider using <a href="https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner" rel="nofollow noreferrer">local static provisioner</a> for this, it has instructions for <a href="https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner/blob/master/docs/getting-started.md#option-3-baremetal-environments" rel="nofollow noreferrer">Baremetal environments</a>.</p>
