<p>I am trying to build a es cluster using the <a href="https://artifacthub.io/packages/helm/elastic/elasticsearch" rel="nofollow noreferrer">helm chart</a> with the following es yaml: values:</p>
<pre><code>resources:
  requests:
    cpu: &quot;.1&quot;
    memory: &quot;2Gi&quot;
  limits:
    cpu: &quot;1&quot;
    memory: &quot;3.5Gi&quot;
volumeClaimTemplate:
  accessModes: [&quot;ReadWriteOnce&quot;]
  resources:
    requests:
      storage: 500Gi
esConfig:
  elasticsearch.yml: |
    path.data: /mnt/azure
</code></pre>
<p>The problem is that the pods are throwing the following error at the start</p>
<blockquote>
<p>&quot;Caused by: java.nio.file.AccessDeniedException: /mnt/azure&quot;</p>
</blockquote>
<p>I put the azure disk as default storage in order not to specify the storage class. I don't know if this is the best practice or should i create the storage and after that mount it to the pods</p>

Vlad
<p>You need to keep <code>init container</code> to change mounted directory ownership</p>
<p>You can update your path as per need, for you changes will be for <code>/mnt/azure</code></p>
<pre><code>initContainers:
          - command:
            - sh
            - -c
            - chown -R 1000:1000 /usr/share/elasticsearch/data
            - sysctl -w vm.max_map_count=262144
            - chmod 777 /usr/share/elasticsearch/data
            - chomod 777 /usr/share/elasticsearch/data/node
            - chmod g+rwx /usr/share/elasticsearch/data
            - chgrp 1000 /usr/share/elasticsearch/data
</code></pre>
<p>Example stateful sets file</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app : elasticsearch
    component: elasticsearch
    release: elasticsearch
  name: elasticsearch
spec:
  podManagementPolicy: Parallel
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app : elasticsearch
      component: elasticsearch
      release: elasticsearch
  serviceName: elasticsearch
  template:
    metadata:
      creationTimestamp: null
      labels:
        app : elasticsearch
        component: elasticsearch
        release: elasticsearch
    spec:
      containers:
      - env:
        - name: cluster.name
          value: &lt;SET THIS&gt;
        - name: discovery.type
          value: single-node
        - name: ES_JAVA_OPTS
          value: -Xms512m -Xmx512m
        - name: bootstrap.memory_lock
          value: &quot;false&quot;
        image: elasticsearch:6.5.0
        imagePullPolicy: IfNotPresent
        name: elasticsearch
        ports:
        - containerPort: 9200
          name: http
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        resources:
          limits:
            cpu: 250m
            memory: 1Gi
          requests:
            cpu: 150m
            memory: 512Mi
        securityContext:
          privileged: true
          runAsUser: 1000
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: elasticsearch-data
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - sh
        - -c
        - chown -R 1000:1000 /usr/share/elasticsearch/data
        - sysctl -w vm.max_map_count=262144
        - chmod 777 /usr/share/elasticsearch/data
        - chomod 777 /usr/share/elasticsearch/data/node
        - chmod g+rwx /usr/share/elasticsearch/data
        - chgrp 1000 /usr/share/elasticsearch/data
        image: busybox:1.29.2
        imagePullPolicy: IfNotPresent
        name: set-dir-owner
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: elasticsearch-data
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 10
  updateStrategy:
    type: OnDelete
  volumeClaimTemplates:
  - metadata:
      creationTimestamp: null
      name: elasticsearch-data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
</code></pre>
