<p>Below is my YAML for volume mounting:</p>
<pre><code>initContainers:

  - name: fix-permissions
    image: busybox
    command: [&quot;sh&quot;, &quot;-c&quot;, &quot;chown -R 1000:1000 /usr/share/elasticsearch/data&quot;]
    securityContext:
      privileged: true
    volumeMounts:
    - name: data
      mountPath: /usr/share/elasticsearch/data
  - name: increase-vm-max-map
    image: busybox
    command: [&quot;sysctl&quot;, &quot;-w&quot;, &quot;vm.max_map_count=262144&quot;]
    securityContext:
      privileged: true
  - name: increase-fd-ulimit
    image: busybox
    command: [&quot;sh&quot;, &quot;-c&quot;, &quot;ulimit -n 65536&quot;]
    securityContext:
      privileged: true
  volumes:
    - name: data
      hostPath: 
        path: /usr/share/elasticsearch/data
        type: DirectoryOrCreate
</code></pre>
<p>Even after changing type to DirectoryOrCreate, it shows the error:</p>
<blockquote>
<p>MountVolume.SetUp failed for volume &quot;data&quot; : hostPath type check failed: /usr/share/elasticsearch/data is not a directory</p>
</blockquote>
<p>How can I fix this ??</p>

ashique
<p>You can add a volumeMounts inside your container:</p>
<pre><code>containers:
  - name: increase-fd-ulimit
    volumeMounts:
      - name: data
        mountPath: /usr/share/elasticsearch/data
</code></pre>
<p>and add a volumeClaimTemplates inside your sts:</p>
<pre><code>spec: 
  volumeClaimTemplates:
    - kind: PersistentVolumeClaim
      apiVersion: v1
      metadata:
        name: data
        namespace: your_namespace
        annotations:
          volume.beta.kubernetes.io/storage-class: default
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 200Gi
        volumeMode: Filesystem
</code></pre>
