1

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

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

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

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

4

1 回答 1

2

是的,你可以,而且能力是 GA。

Azure 共享磁盘可以挂载为 ReadWriteMany,这意味着您可以将其挂载到多个节点和 Pod。它需要Azure 磁盘 CSI 驱动程序,需要注意的是目前仅支持原始块卷,因此应用程序负责管理共享磁盘上的写入、读取、锁定、缓存、挂载和防护的控制,即暴露为原始块设备。这意味着您将原始块设备(磁盘)作为 avolumeDevice而不是volumeMount.

文档示例主要指向如何创建一个存储类来动态配置静态 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 是相同的。参考上面的部署。

于 2021-05-19T20:56:54.437 回答