Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
93 lines (77 sloc) 4.6 KB

Set azure file mountOptions

  • azure file mountOptions feature is available from v1.8.5, for lower k8s version, could use instead, which is only supported in PersistentVolume.
  • For dynamic provision, mountOptions should be set in storage class, while for static provision(use existing file share), mountOptions should be set in PersistentVolume

Set mountOptions in Dynamic Provisioning

download storageclass-azurefile-mountoptions.yaml file and modify mountOptions values

vi storageclass-azurefile-mountoptions.yaml
kubectl create -f storageclass-azurefile-mountoptions.yaml

Set mountOptions in Static Provisioning

static provisioning means user must create an azure file before using azure file mount feature.


  • create an azure file share in Azure storage account in the same resource group with k8s cluster
  • get azurestorageaccountname, azurestorageaccountkey and shareName of that azure file

1. create a secret for azure file

  • Use kubectl create secret to create azure-secret
kubectl create secret generic azure-secret --from-literal azurestorageaccountname=NAME --from-literal azurestorageaccountkey="KEY" --type=Opaque

2. create an azure file persistent volume(pv)

  • for k8s version >= v1.8.5
kubectl create -f
  • for k8s version < v1.8.5 (including 1.7.x)
kubectl create -f

Note: vers,dir_mode,file_mode could not be specified in pv-azurefile-mountoptions-1.7.yaml since there is already default values as in vers=3.0,dir_mode=0777,file_mode=0777

3. create an azure file persistent volume claim(pvc)

kubectl create -f

  • watch the status of pv until its Status changed from Pending to Bound
watch kubectl describe pvc pvc-azurefile

4. create a pod with azure file pvc

kubectl create -f

  • watch the status of pod until its Status changed from Pending to Running
watch kubectl describe po nginx-azurefile

Or Use A combined configuration of step#2 to #4:

kubectl create -f

5. enter the pod container to do validation

kubectl exec -it nginx-azurefile -- bash

root@nginx-azurefile:/# df -h
Filesystem                                 Size  Used Avail Use% Mounted on
overlay                                     30G  4.1G   26G  14% /
tmpfs                                      6.9G     0  6.9G   0% /dev
tmpfs                                      6.9G     0  6.9G   0% /sys/fs/cgroup
//  5.0G   64K  5.0G   1% /mnt/azurefile
/dev/sda1                                   30G  4.1G   26G  14% /etc/hosts
shm                                         64M     0   64M   0% /dev/shm
tmpfs                                      6.9G   12K  6.9G   1% /run/secrets/

root@nginx-azurefile:/mnt/azurefile# ls -lt
total 1
-rwx-w-r-- 1 1000 1000 1015 Nov 27 06:09 outfile
drwx-wx--x 2 1000 1000    0 Nov 27 06:09 a
    runAsUser: XXX
    fsGroup: XXX
version fileMode, dirMode value
v1.6.x, v1.7.x 0777
v1.8.0-v1.8.5 0700
v1.8.6 or above 0755
v1.9.0 0700
v1.9.1 or above 0755