How can I mount a hostpath into a statefulset?

1k views Asked by At

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)?

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...

How can I accomplish this with a statefulset?

1

There are 1 answers

0
Jonas On

Instead of a HostPath Volume, you should use a Local Persistent Volume for this kind of use cases.

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.

Consider using local static provisioner for this, it has instructions for Baremetal environments.