Mount Azure Files' folder into Kubernetes?

12/3/2018

As direct mount or persistent volume claim the Azure docs show how to mount an Azure Files storage account to a Kubernetes pod. This mounts the entire storage as the mounted path. How do I instead mount a folder within the Azure Files storage to Kubernetes?

On Azure Files, I have the following:

AzureFiles
|- folder1
   |- file1
|- folder2
   |- file2

When I mount the Azure Files storage account to Kubernetes (to /mnt/azure) I see this:

/mnt
|- azure
   |- folder1
      |- file1
   |- folder2
      |- file2

Instead I'd like to see this when I mount Azure Files' path folder1:

/mnt
|- azure
   |- file1

How do I change my Pod definition to specify this path:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - // ... snip ...
    volumeMounts:
      - name: azure
        mountPath: /mnt/azure
  volumes:
  - name: azure
    azureFile:
      secretName: azure-secret
      shareName: aksshare
      readOnly: false
      // TODO: how to specify path in aksshare
-- robrich
azure
azure-storage-files
kubernetes

2 Answers

12/7/2018

Edit

Search for several days, I figure out how to mount a sub-folder of the Azure File Share to the AKS pod. You can set the yaml file like this:

volumes:
  - name: azure
    azureFile:
      secretName: azure-secret
      shareName: share/subfolder
      readOnly: false

Just set the share name with the directory, take care, do not append / in the end. The screenshot of the result is here:

enter image description here

For more details, see Naming and Referencing Shares, Directories, Files, and Metadata.

-- Charles Xu
Source: StackOverflow

12/3/2018

I believe you can use subPath. So something like this:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - // ... snip ...
    volumeMounts:
      - name: azure
        mountPath: /mnt/azure
        subPath: folder1
  volumes:
  - name: azure
    azureFile:
      secretName: azure-secret
      shareName: aksshare
      readOnly: false
      // TODO: how to specify path in aksshare
-- Rico
Source: StackOverflow