<p>I am deploying Elasticsearch cluster to K8S on EKS with nodegroup. I claimed a EBS for the cluster's storage. When I launch the cluster, only one pod is running successfully but I got this error for other pods:</p>
<pre><code> Warning  FailedAttachVolume  3m33s                  attachdetach-controller  Multi-Attach error for volume &quot;pvc-4870bd46-2f1e-402a-acf7-005de83e4588&quot; Volume is already used by pod(s) es-0
  Warning  FailedMount         90s                    kubelet                  Unable to attach or mount volumes: unmounted volumes=[persistent-storage], unattached volumes=[es-config persistent-storage default-token-pqzkp]: timed out waiting for the condition
</code></pre>
<p>It means the storage is already in use. I understand that this volume is used by the first pod so other pods can't use it. But I don't know how to use different mount path for different pod when they are using the same EBS volume.</p>
<p>Below is the full spec for the cluster.</p>
<pre><code>
apiVersion: v1
kind: ConfigMap
metadata:
  name: es-config
data:
  elasticsearch.yml: |
    cluster.name: elk-cluster
    network.host: &quot;0.0.0.0&quot;
    bootstrap.memory_lock: false
    # discovery.zen.minimum_master_nodes: 2
    node.max_local_storage_nodes: 9
    discovery.seed_hosts:
      - es-0.es-entrypoint.default.svc.cluster.local
      - es-1.es-entrypoint.default.svc.cluster.local
      - es-2.es-entrypoint.default.svc.cluster.local
  ES_JAVA_OPTS: -Xms4g -Xmx8g
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es
  namespace: default
spec:
  serviceName: es-entrypoint
  replicas: 3
  selector:
    matchLabels:
      name: es
  template:
    metadata:
      labels:
        name: es
    spec:
      volumes:
        - name: es-config
          configMap:
            name: es-config
            items:
              - key: elasticsearch.yml
                path: elasticsearch.yml
        - name: persistent-storage
          persistentVolumeClaim:
            claimName: ebs-claim
      initContainers:
        - name: permissions-fix
          image: busybox
          volumeMounts:
            - name: persistent-storage
              mountPath: /usr/share/elasticsearch/data
          command: [ 'chown' ]
          args: [ '1000:1000', '/usr/share/elasticsearch/data' ]
      containers:
        - name: es
          image: elasticsearch:7.10.1
          resources:
            requests:
              cpu: 2
              memory: 8Gi
          ports:
            - name: http
              containerPort: 9200
            - containerPort: 9300
              name: inter-node
          volumeMounts:
            - name: es-config
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
              subPath: elasticsearch.yml
            - name: persistent-storage
              mountPath: /usr/share/elasticsearch/data
---
apiVersion: v1
kind: Service
metadata:
  name: es-entrypoint
spec:
  selector:
    name: es
  ports:
    - port: 9200
      targetPort: 9200
      protocol: TCP
  clusterIP: None

</code></pre>

Joey Yi Zhao
<p>You should be using <code>volumeClaimTemplates</code> with statefulset so that each pod gets its own volume. <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#components" rel="nofollow noreferrer">Details</a>:</p>
<pre><code>volumeClaimTemplates:
- metadata:
    name: es
  spec:
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 5Gi
    # storageClassName: &lt;omit to use default StorageClass or specify&gt;
</code></pre>
