<p>I am trying to deploy a Elasticsearch cluster<code>(replicas: 3)</code> using Statefulset in kubernetes and need to store the Elasticsearch data in a Persistent Volume (PV). Since each Elasticsearch instance has its own data folder, I need to have separate data folder for each replica in the PV. I am trying to use <code>volumeClaimTemplates</code> and <code>mountPath: /usr/share/elasticsearch/data</code> but this is resulting in an error: <code>pod has unbound immediate PersistentVolumeClaims</code> in the second pod. Hence how can I achieve this using Statefulset?  </p>

<p>Thanks in advance.</p>

<p>There is no information how you are trying to install elastic-search however:
As an example please follow:</p>

<ul>
<li><a href="https://medium.com/@zhimin.wen/persistent-volume-claim-for-statefulset-8050e396cc51" rel="nofollow noreferrer">this tutorial</a>,  </li>
<li><a href="https://github.com/elastic/helm-charts/tree/master/elasticsearch" rel="nofollow noreferrer">helm-charts</a>,</li>
</ul>

<p>As per documentation for StatefulSet - <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations" rel="nofollow noreferrer">limitations</a>:</p>

<blockquote>
  <p>The storage for a given Pod must either be provisioned by a PersistentVolume Provisioner based on the requested storage class, or pre-provisioned by an admin.</p>
</blockquote>

<p>This looks like your example, problem with dynamic storage provisioning.  </p>

<p>Please verify storage class, if pv and pvc were created and bind together and  <code>storage class</code> in <code>volumeClaimTemplates</code>:</p>

<pre><code>    volumeMounts:
      - name: "elasticsearch-master"
        mountPath: /usr/share/elasticsearch/data
 volumeClaimTemplates:
  - metadata:
      name: elasticsearch-master
    spec:
      accessModes:
      - ReadWriteOnce
      storageClassName: name #please refer to this settings to see if you are using default storage class. In other case you should spceify this parameter manually
      resources:
        requests:
          storage: 30Gi
</code></pre>

<p>Hope this help.</p>
