<p>I have a deployment in Kubernetes. In this deployment, I can specify a persistent volume claim as follows:</p>
<pre><code>  volumes:
  - name: my-volume
    persistentVolumeClaim:
      claimName: my-claim
</code></pre>
<p>I have a disk (an Azure disk to be precise) with lots of preprocessed data, which I can expose in Kubernetes as PVC with name <code>my-claim</code>. In the next step I link it to the deployment as shown above. The problem with this approach is, that I cannot scale the deployment to more than one pod.</p>
<p>How can I scale this setup? I tried to duplicate the disk and create it as second PVC with a different name. This worked, but now I don't see a way to tell the Kubernetes deployment, that each pod should mount one of these two PVCs.</p>
<p>I hope there is an option to mark both PVCs with a common label and then link my deployment to this label instead of the PVC name. Is something like this out there or is my approach completely wrong?</p>
<p>Thanks!</p>

Stephan
<blockquote>
<p>I have a disk (an Azure disk to be precise) with lots of preprocessed data, which I can expose in Kubernetes as PVC with name my-claim. In the next step I link it to the deployment as shown above. The problem with this approach is, that I cannot scale the deployment to more than one pod.</p>
</blockquote>
<p>Here, you use a <code>PersistentVolumeClaim</code> with <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">Access Mode</a> <code>ReadWriteOnce</code> (that's the only option for Azure Disks, see access mode link)</p>
<blockquote>
<p>How can I scale this setup? I tried to duplicate the disk and create it as second PVC with a different name. This worked, but now I don't see a way to tell the Kubernetes deployment, that each pod should mount one of these two PVCs.</p>
</blockquote>
<p>Here, it sounds like you want a volume with <em>access mode</em> <code>ReadOnlyMany</code> - so you need to consider a storage system that support this <em>access mode</em>.</p>
<blockquote>
<p>I tried to duplicate the disk and create it as second PVC with a different name. This worked, but now I don't see a way to tell the Kubernetes deployment, that each pod should mount one of these two PVCs.</p>
</blockquote>
<p>This does not work for a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deployment</a> because the <code>template</code> for each pod is identical. But you can do this with <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">StatefulSet</a>, declaring your PVC with <code>volumeClaimTemplates</code> - then the PVC for each pod has in <strong>unique, well known identity</strong>.</p>
<p>Example part of <code>StatefulSet</code>:</p>
<pre><code>  volumeClaimTemplates:
  - metadata:
      name: my-pvc
    spec:
      accessModes: [ &quot;ReadWriteOnce&quot; ]
      storageClassName: &quot;my-storage-class&quot;
      resources:
        requests:
          storage: 1Gi
</code></pre>
<p>Then if you have two replicas of you StatefulSet, they will you a PVC named <code>my-pvc-0</code> and <code>my-pvc-1</code> where the number is called &quot;ordinal&quot;. The <code>volumeClaimTemplate</code> only creates a new PVC if it does not exists, so if you have created PVCs with the correct names - the existing will be used.</p>
<h2>Alternative Storage Solutions</h2>
<p>An alternative storage solution to Azure Disk is Azure Files. Azure Files support <em>access mode</em> <code>ReadWriteOnce</code>, <code>ReadOnlyMany</code> and <code>ReadWriteMany</code>. See <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-dynamic-pv" rel="nofollow noreferrer">Dynamically create and use a persistent volume with Azure Files in Azure Kubernetes Service (AKS)</a>.</p>
<p>There may also be other storage alternatives that better fit your application.</p>
