【问题标题】:Is it possible to mount a shared Azure disk in Azure Kubernetes to multiple PODs/Nodes?是否可以将 Azure Kubernetes 中的共享 Azure 磁盘挂载到多个 POD/节点?
【发布时间】:2021-07-08 16:37:34
【问题描述】:

我想基于此将 Azure 共享磁盘挂载到多个部署/节点: https://docs.microsoft.com/en-us/azure/virtual-machines/disks-shared

所以,我在 Azure 门户中创建了一个共享磁盘,当尝试将其挂载到 Kubernetes 中的部署时出现错误:

“卷“azuredisk”的多附加错误卷已被 pod 使用...”

是否可以在 Kubernetes 中使用共享磁盘?如果有怎么办? 感谢您的提示。

【问题讨论】:

    标签: azure kubernetes azure-aks azure-disk


    【解决方案1】:

    Yes, you can,能力为GA。

    可以将 Azure 共享磁盘挂载为 ReadWriteMany,这意味着您可以将其挂载到多个节点和 Pod。它需要Azure Disk CSI driver,需要注意的是目前只支持原始块卷,因此应用程序负责管理共享磁盘上的写入、读取、锁定、缓存、挂载和隔离的控制,这些都是暴露的作为原始块设备。这意味着您将原始块设备(磁盘)作为volumeDevice 而不是volumeMount 挂载到pod 容器。

    The documentation examples 主要是指如何创建一个存储类来动态提供静态 Azure 共享磁盘,但我也静态创建了一个并将其挂载到不同节点上的多个 pod。

    动态预配共享 Azure 磁盘

    1. 创建存储类和 PVC
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: managed-csi
    provisioner: disk.csi.azure.com
    parameters:
      skuname: Premium_LRS  # Currently shared disk only available with premium SSD
      maxShares: "2"
      cachingMode: None  # ReadOnly cache is not available for premium SSD with maxShares>1
    reclaimPolicy: Delete
    ---
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: pvc-azuredisk
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 256Gi  # minimum size of shared disk is 256GB (P15)
      volumeMode: Block
      storageClassName: managed-csi
    
    1. 创建具有 2 个副本的部署并在 Spec 中指定 volumeDevices、devicePath
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: nginx
      name: deployment-azuredisk
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
          name: deployment-azuredisk
        spec:
          containers:
            - name: deployment-azuredisk
              image: mcr.microsoft.com/oss/nginx/nginx:1.17.3-alpine
              volumeDevices:
                - name: azuredisk
                  devicePath: /dev/sdx
          volumes:
            - name: azuredisk
              persistentVolumeClaim:
                claimName: pvc-azuredisk
    

    使用静态预配的 Azure 共享磁盘

    使用已通过 ARM、Azure 门户或 Azure CLI 预配的 Azure 共享磁盘。

    1. 定义一个引用 DiskURI 和 DiskName 的 PersistentVolume (PV):
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: azuredisk-shared-block
    spec:
      capacity:
        storage: "256Gi" # 256 is the minimum size allowed for shared disk
      volumeMode: Block # PV and PVC volumeMode must be 'Block'
      accessModes:
        - ReadWriteMany
      persistentVolumeReclaimPolicy: Retain
      azureDisk:
        kind: Managed
        diskURI: /subscriptions/<subscription>/resourcegroups/<group>/providers/Microsoft.Compute/disks/<disk-name>
        diskName: <disk-name>
        cachingMode: None # Caching mode must be 'None'
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: pvc-azuredisk-managed
    spec:
      resources:
        requests:
          storage: 256Gi
      volumeMode: Block
      accessModes:
        - ReadWriteMany
      volumeName: azuredisk-shared-block # The name of the PV (above)
    

    对于动态和静态配置的共享磁盘,安装此 PVC 是相同的。参考上面的部署。

    【讨论】:

    • @remopar 为什么要删除已接受的答案?
    猜你喜欢
    • 2021-03-28
    • 2016-04-25
    • 2022-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    相关资源
    最近更新 更多