Shared Azure File Storage with Statefulset on AKS

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.

I use Azure Files dynamic where all is declarative i.e. storage account, secrets, pvc's and pv's are created automatically.

Manifest with VolumeClaimTemplate

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

The StorageClass:

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

Instead of one share, I end up with 3 pv's each referring to a separate created Azure Storage Account each with a share data.

Question: 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?

Upvotes: 1

Views: 2038

Answers (1)

Turns out that volumeClaimTemplates is not the right place (reference).

Instead use persistentVolumeClaim.

For Azure File Storage this becomes:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-shared-claim
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: azfile-zrs-sc
  resources:
    requests:
      storage: 1Gi  

And refer to it in the manifest:

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

Upvotes: 3

Related Questions