<p>As <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-volume" rel="nofollow noreferrer">direct mount</a> or <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-dynamic-pv" rel="nofollow noreferrer">persistent volume claim</a> 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?</p>

<p>On Azure Files, I have the following:</p>

<pre><code>AzureFiles
|- folder1
   |- file1
|- folder2
   |- file2
</code></pre>

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

<pre><code>/mnt
|- azure
   |- folder1
      |- file1
   |- folder2
      |- file2
</code></pre>

<p>Instead I'd like to see this when I mount Azure Files' path <code>folder1</code>:</p>

<pre><code>/mnt
|- azure
   |- file1
</code></pre>

<p>How do I change my <a href="https://learn.microsoft.com/en-us/azure/aks/azure-files-volume#mount-the-file-share-as-a-volume" rel="nofollow noreferrer">Pod definition</a> to specify this path:</p>

<pre><code>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
</code></pre>

robrich
<p><strong>Edit</strong></p>

<p>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: </p>

<pre><code>volumes:
  - name: azure
    azureFile:
      secretName: azure-secret
      shareName: share/subfolder
      readOnly: false
</code></pre>

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

<p><a href="https://i.stack.imgur.com/7aaoO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7aaoO.png" alt="enter image description here"></a></p>

<p>For more details, see <a href="https://learn.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-shares--directories--files--and-metadata#directory-and-file-names%3Chttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Frest%2Fapi%2Fstorageservices%2Fnaming-and-referencing-shares--directories--files--and-metadata%23directory-and-file-names&amp;data=02%7C01%7C%7C851c8a59e3b64c291a5508d65ea91a95%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636800477728798195&amp;sdata=v3XdE1qMeZFVcD1qYCoeGyDjmXo4GvwsChdMIws8XA4%3D&amp;reserved=0%3E" rel="noreferrer">Naming and Referencing Shares, Directories, Files, and Metadata</a>.</p>
