Kubernetes - can we use the same mounted volume (file share) for both Cluster Nodes - Windows and Linux?

3/16/2021

I initially had only app on Linux node and used mounted volume for it (Azure Storage Account and File Share), and everything works perfectly.

Extracted definition from YAML:

    volumeMounts:
      - name: test-volume
        mountPath: /opt/arena/
  volumes:
  - name: test-volume
    azureFile:
      secretName: test-secret
      shareName: test-share

Now for my second app (same app but deployed on Windows container) I need to use the same storage account and file share. Only I will mount windows path.

....
    volumeMounts:
      - name: test-volume
        mountPath: "C:\\arena"
    ........ 
  volumes:
    - name: test-volume
      azureFile:
        secretName: test-secret
        shareName: test-share

When mounted for linux I am getting immediately my log directory with file "ads.log"

log
|__ads.log

But the same directory "log" and the same file "ads.log" exists on the Windows container as well.

I would like to use the same storage account and file share on Azure in order not to increase costs. But how I can achieve that both Linux and Windows containers are mounted into volumes but also in the same time to differentiate which log is from which container???

Also additional question since I didn't yet do the windows mounting: is the mountPath: "C:\\arena" correct way of defining this? Because in some examples on web some plugins are mentioned for windows etc.

Thanks

-- AndreyS
azure
azure-aks
kubernetes

1 Answer

3/17/2021

First, the mount format for windows is right. So you don't need to worry about it. Second, to differentiate the log folder which is for Linux container and which is for windows container from the same file share, you can mount the subfolders of the file share.

File Share:

aksshare
│── linux
│── windows

screenshot:

enter image description here

Then the mount the file share like this:

  .....
  volumeMounts:
    - name: azure
      mountPath: /mnt/azure
volumes:
  - name: azure
    azureFile:
      shareName: aksshare/linux
      secretName: azure-secret

This way will mount the two subfolders of the file share to the different containers and won't affect each other.

-- Charles Xu
Source: StackOverflow