0

I have several Linux containers in Azure AKS and I need to access some resource files (.NET 6) I want to use Azure File Share as a shared path to store these resources, that will change more or less every week. Is it a good approach?

I'm not able to make it works, I've already tried these two approaches:

testcontainer:
image: ${DOCKER_REGISTRY-}testcontainer
container_name: ...
build:
  context: .
  dockerfile: src/project/Dockerfile
volumes:
  - myshare:/test

### First attempt ###
volumes:
  myshare:
    driver: local
    driver_opts:
      type: cifs
      o: "mfsymlinks,vers=3.0,username=storageAccountName,password=***,addr=storageAccountName.file.core.windows.net"
      device: "//storageAccountName.file.core.windows.net/shareName"

### Second attempt ###
volumes:
  myshare:
    driver: azure_file
    driver_opts:
      share_name: shareName
      storage_account_name: storageAccountName

The first attempt gives me error: Error while mounting volume...:invalid argument

The second attempt gives me error: Error while mounting volume...:plugin "azure_file" not found"

How can i do that? Thanks to all.

CSharpRocks
  • 6,791
  • 1
  • 21
  • 27

2 Answers2

0

Assuming you're using K8s greater than 1.21:

Create a StorageClass as the following:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: my-azurefile
provisioner: file.csi.azure.com # replace with "kubernetes.io/azure-file" if aks version is less than 1.21
allowVolumeExpansion: true
mountOptions:
 - dir_mode=0777
 - file_mode=0777
 - uid=0
 - gid=0
 - mfsymlinks
 - cache=strict
 - actimeo=30
parameters:
  skuName: Premium_LRS

Then, a persistent volume claim:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-azurefile
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: my-azurefile
  resources:
    requests:
      storage: 100Gi

Lastly, use is in your pod:

kind: Pod
apiVersion: v1
metadata:
  name: mypod
spec:
 containers:
 - name: mypod
    image: mcr.microsoft.com/oss/nginx/nginx:1.15.5-alpine
    resources:
      requests:
        cpu: 100m
        memory: 128Mi
      limits:
        cpu: 250m
        memory: 256Mi
    volumeMounts:
    - mountPath: "/mnt/azure"
      name: volume
  volumes:
    - name: volume
      persistentVolumeClaim:
        claimName: my-azurefile
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
0

Agree with Thiago Custodio. Just for the ReadWriteMany PVC you can also use the standard azurefile or azurefile-premium storageClass, e.g.:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-azurefile
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: azurefile
  resources:
    requests:
      storage: 100Gi
Vitaly
  • 36
  • 4