kubernetes 在Azure AKS中使用Azure文件共享

lxkprmvk  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(135)

我在Azure AKS中有几个Linux容器,我需要访问一些资源文件(.NET 6)。我想使用Azure File Share作为存储这些资源的共享路径,每周都会或多或少地发生变化。这是个好方法吗?
我无法让它工作,我已经尝试了这两种方法:

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

字符串
第一次尝试给我错误:* 装入卷时出错...:参数无效 *
第二次尝试给我错误:* 装入卷时出错...:未找到插件“azure_file””*
我该怎么做?感谢所有人。

i7uq4tfw

i7uq4tfw1#

假设您使用的K8s大于1.21:
按以下方式创建StorageClass:

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

字符串
然后,持久卷声明:

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


最后,使用在你的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

相关问题