Storage

How to use Azure File Shares for persistent storage

1. Create a storage class:
This storage class uses the azure csi provisioner. by default is has permissions within the aks resource groups. The csi driver can be configured to use an existing storage account or to create one automatically. the same thing applies to the file shares.

Retain File Shares: To retain the file share when the Persistant Volume Claim (PVC) is released, set reclaimPolicy to Retain

Storage type: Choose between Premium and Standard storage by changing the parameter skuName to Standard_LRS or Premium_LRS

Mount options: Set share permissions, The default value for fileMode and dirMode is 0777
Set uid and gid to pod user if you experience permission difficulties. defaults to 0

Note: If a mount option is invalid, the PV mount fails.

Example Storage Class:

Note: this is an example which you will need to edit in order to make it work in your environment. One storage class represents one storage account.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: cmaas-storage
provisioner: file.csi.azure.com
reclaimPolicy: Retain
#disableDeleteRetentionPolicy: "true"  # disable DeleteRetentionPolicy for storage account created by driver
volumeBindingMode: Immediate
allowVolumeExpansion: true
mountOptions: # Configure mount options
  - dir_mode=0777 #0640
  - file_mode=0777 #0640
  - uid=0
  - gid=0
  - mfsymlinks
  - cache=strict # https://linux.die.net/man/8/mount.cifs
  - nosharesock # reduce probability of reconnect races
parameters:
  skuName: Standard_LRS # Premium_LRS
  #  resourceGroup: EXISTING_RESOURCE_GROUP_NAME  # optional, only set this when storage account is not in the same resource group as agent node
  storageAccount: <storage-account-name>  # Set correct account name
  shareName: <share-name> # if the share not exists it will be created

2. Create an Persistent Volume Claim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-azurefile
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Gi
  storageClassName: cmaas-storage

3. Configure Deployment

kind: Pod
apiVersion: v1
metadata:
  name: nginx
spec:
  containers:
    - image: <azure_container_registry_Name>.azurecr.io/nginx:v1
      name: azure-files-pod-test
      ports:
        - containerPort: 80
          protocol: TCP
      volumeMounts:
        - name: azure
          mountPath: /usr/share/nginx/html
  volumes:
    - name: azure
      persistentVolumeClaim:
        claimName: pvc-azurefile

How to use Azure Disks for persistent storage

You can create a StorageClass for additional needs using kubectl. The following example uses Premium Managed Disks and specifies that the underlying Azure Disk should be retained when you delete the pod:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-premium-retain
provisioner: disk.csi.azure.com
parameters:
  skuName: Premium_LRS
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true

Persistent volumes are 1:1 mapped to claims.

The following example YAML manifest shows a persistent volume claim that uses the managed-premium StorageClass and requests a Disk 5Gi in size:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: azure-managed-disk
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: managed-premium-retain
  resources:
    requests:
      storage: 5Gi

The following example YAML manifest shows how the previous persistent volume claim can be used to mount a volume at * /mnt/azure*:

kind: Pod
apiVersion: v1
metadata:
  name: nginx
spec:
  containers:
    - image: <azure_container_registry_Name>.azurecr.io/nginx:v1
      name: azure-files-pod-test
      ports:
        - containerPort: 80
          protocol: TCP
      volumeMounts:
        - mountPath: "/mnt/azure"
          name: volume
  volumes:
    - name: volume
      persistentVolumeClaim:
        claimName: azure-managed-disk

Default Provisioner Reference

Use the kubectl get sc command to see the pre-created storage classes.

Builtin provisioners:

Provisioner Reason
managed-csi Uses Azure StandardSSD locally redundant storage (LRS) to create a Managed Disk. The reclaim policy ensures that the underlying Azure Disk is deleted when the persistent volume that used it is deleted. The storage class also configures the persistent volumes to be expandable, you just need to edit the persistent volume claim with the new size.
managed-csi-premium Uses Azure Premium locally redundant storage (LRS) to create a Managed Disk. The reclaim policy again ensures that the underlying Azure Disk is deleted when the persistent volume that used it is deleted. Similarly, this storage class allows for persistent volumes to be expanded.
azurefile-csi Uses Azure Standard storage to create an Azure File Share. The reclaim policy ensures that the underlying Azure File Share is deleted when the persistent volume that used it is deleted.
azurefile-csi-premium Uses Azure Premium storage to create an Azure File Share. The reclaim policy ensures that the underlying Azure File Share is deleted when the persistent volume that used it is deleted.
azureblob-nfs-premium Uses Azure Premium storage to create an Azure Blob storage container and connect using the NFS v3 protocol. The reclaim policy ensures that the underlying Azure Blob storage container is deleted when the persistent volume that used it is deleted.
azureblob-fuse-premium Uses Azure Premium storage to create an Azure Blob storage container and connect using BlobFuse. The reclaim policy ensures that the underlying Azure Blob storage container is deleted when the persistent volume that used it is deleted.

Storage Types

Sku Name
Premium_LRS
PremiumV2_LRS
Premium_ZRS
Standard_LRS
StandardSSD_LRS
StandardSSD_ZRS
UltraSSD_LRS

To get more details about every sku option see: more info.