<p>I have a Statefulset with 3 instances on Azure Kubernetes 1.16, where I try to use Azure File storage to create a single file share for the 3 instances.</p>
<p>I use <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-dynamic-pv" rel="nofollow noreferrer">Azure Files dynamic</a> where all is declarative i.e. storage account, secrets, pvc's and pv's are created automatically.</p>
<p>Manifest with VolumeClaimTemplate</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: xxx
spec:
  replicas: 3
  ...
  volumeClaimTemplates:
  - metadata:
      name: xxx-data-shared
    spec:
      accessModes: [ ReadWriteMany ]
      storageClassName: azfile-zrs-sc
      resources:
        requests:
            storage: 1Gi
</code></pre>
<p>The StorageClass:</p>
<pre><code>kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: azfile-zrs-sc
provisioner: kubernetes.io/azure-file
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=0
  - gid=0
  - mfsymlinks
  - cache=strict
parameters:
  resourceGroup: xxx
  skuName: Standard_ZRS
  shareName: data
</code></pre>
<p>Instead of one share, I end up with 3 pv's each referring to a separate created Azure Storage Account each with a share <code>data</code>.</p>
<p><strong>Question</strong>: Can I use the Azure Files dynamic, with additional configuration in the manifest to get a single file share? Or will I have to do Static?</p>

Christian Holm Jørgensen
<p>Turns out that <code>volumeClaimTemplates</code> is not the right place (<a href="https://stackoverflow.com/questions/49729461/add-persistent-volume-in-kubernetes-statefulset">reference</a>).</p>
<p>Instead use <code>persistentVolumeClaim</code>.</p>
<p>For Azure File Storage this becomes:</p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-shared-claim
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: azfile-zrs-sc
  resources:
    requests:
      storage: 1Gi  
</code></pre>
<p>And refer to it in the manifest:</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: xxx
spec:
  replicas: 3
  ...
  template: 
    spec:
      containers:
      ...
        volumeMounts:
        - name: data-shared
          mountPath: /data
      volumes:
        - name: data-shared
          persistentVolumeClaim:
            claimName: data-shared-claim
</code></pre>
