<p>I created a StatefulSet for running my NodeJS with 3 replicas and want to attach to a gce disk that can become a data storage for user to upload files.</p>
<p>My project naming: carx; Server name: car-server</p>
<p><strong>However I got an error while creating the second pod.</strong></p>
<pre><code>kubectl describe pod car-server-statefulset-1
</code></pre>
<blockquote>
<p>AttachVolume.Attach failed for volume &quot;my-app-data&quot; : googleapi: Error
400: RESOURCE_IN_USE_BY_ANOTHER_RESOURCE - The disk resource
'projects/.../disks/carx-disk' is already being used by
'projects/.../instances/gke-cluster-...-2dw1'</p>
</blockquote>
<hr />
<p><strong>car-server-statefulset.yml</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: car-server-service
  labels:
    app: car-server
spec:
  ports:
  - port: 8080
    name: car-server
  clusterIP: None
  selector:
    app: car-server
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: car-server-statefulset
spec:
  serviceName: &quot;car-server-service&quot;
  replicas: 3
  template:
    metadata:
      labels:
        app: car-server
    spec:
      containers:
        - name: car-server
          image: myimage:latest
          ports:
            - containerPort: 8080
              name: nodejs-port
          volumeMounts:
          - name: my-app-data
            mountPath: /usr/src/app/mydata
      volumes:
      - name: my-app-data
        persistentVolumeClaim:
          claimName: example-local-claim
  selector:
    matchLabels:
      app: car-server
</code></pre>
<hr />
<p><strong>pvc.yml</strong></p>
<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: example-local-claim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
  storageClassName: standard
</code></pre>
<hr />
<p><strong>pv.yml</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-app-data
  labels:
    app: my-app
spec:
  capacity:
    storage: 60Gi
  storageClassName: standard
  accessModes:
    - ReadWriteMany
  gcePersistentDisk:
    pdName: carx-disk
    fsType: ext4
</code></pre>

<p>The <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">Access Mode</a> field is treated as a <em>request</em>, but it is not sure that you get what you requests. In your case, <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">GCEPersistentDisk</a> only support <code>ReadWriteOnce</code> or <code>ReadOnlyMany</code>.</p>
<p>Your PV is now mounted as <code>ReadWriteOnce</code> but can only be mounted on <strong>one</strong> node at the same time. So the other replicas will fail to mount the volume.</p>
<p>When using <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">StatefulSet</a>, it is common that each replica use its own volume, use the <code>volumeClaimTemplate:</code> part of the <code>StatefulSet</code> manifest for that.</p>
<p>Example:</p>
<pre><code>  volumeClaimTemplates:
  - metadata:
      name: example-claim
    spec:
      accessModes: [ &quot;ReadWriteOnce&quot; ]
      storageClassName: &quot;standard&quot;
      resources:
        requests:
          storage: 5Gi
</code></pre>
<p>In case that you only can use a single volume, you may consider to run the <code>StatefulSet</code> with only one replica, e.g. <code>replicas: 1</code>.</p>
<p>If you want disk-replication, you can use a <em>StorageClass</em> for <em>regional disks</em> that are replicated to another AZ as well. See <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/regional-pd" rel="nofollow noreferrer">Regional Persistent Disk</a>, but it still have the same <em>access modes</em>.</p>
