gpt4 book ai didi

azure - 是否可以将 Azure Kubernetes 中的共享 Azure 磁盘挂载到多个 POD/节点?

转载 作者:行者123 更新时间:2023-12-05 01:30:25 40 4
gpt4 key购买 nike

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

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

"Multi-Attach error for volume "azuredisk" Volume is already used by pod(s)..."

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

最佳答案

<强> Yes, you can ,能力已GA。

Azure 共享磁盘可以挂载为 ReadWriteMany,这意味着您可以将其挂载到多个节点和 Pod。它需要 Azure Disk CSI driver ,需要注意的是,目前仅支持原始 block 卷,因此应用程序负责管理共享磁盘上的写入、读取、锁定、缓存、安装和防护的控制,该磁盘作为原始 block 设备公开。这意味着您将原始 block 设备(磁盘)作为 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
  • 创建具有 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 的方式相同。引用上面的部署。

    关于azure - 是否可以将 Azure Kubernetes 中的共享 Azure 磁盘挂载到多个 POD/节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67078009/

    40 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com