map a file inside a container running on kubernete to azure file share

6/8/2019

I wanted mapped two file from container to Azure file:

  1. /Logs/abc.xml ( abc.xml need to mount also logs have multiple files and folder that do need to mount ).
  2. /temp/folder/file.txt (file.txt need to mount its also have multiple file and folder )

Need to mount both of them to same file share.

I tried To use sub path but its creating the folder in the azure file but do not have file. I'm also getting error in kubernetes deployment.

error:- known: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type Back-off restarting failed container

volumeMounts:
- name: serverxml
  mountPath: /test/Server.xml
  subPath: Server.xml

volumes:
- name: serverxml
  azureFile:
    secretName: azure-fileshare-secret
    shareName: customer1-uat-config
    readOnly: false

where azure-fileshare-secret is having secretkey of storage.

Expected results: customer1-uat-config/test/server.log and customer1-uat-config/folder/file.txt

-- user3489346
azure
kubernetes

1 Answer

6/10/2019

For your issue, you should know one point that you cannot mount the files to the Azure file share. Files cannot mount to the storage. But you can mount the folders to folders of Azure file share. You can use one file share with multiple folders in it, and then mount the folders in your container to the folders in that file share.

The setting in the yaml file like this:

    volumeMounts:
      - name: test
        mountPath: /test
      - name: folder
        mountPath: /folder
  volumes:
  - name: test
    azureFile:
      secretName: azurefile-secret
      shareName: aksshare/test
      readOnly: false
  - name: folder
    azureFile:
      secretName: azurefile-secret
      shareName: aksshare/folder

And the screenshots of the result here:

enter image description here

enter image description here

-- Charles Xu
Source: StackOverflow