Share via


在 Azure Arc 啟用的 AKS 中使用容器記憶體介面 (CSI) 檔案驅動程式

> 適用於:Azure Stack HCI 22H2 上的 AKS、Windows Server 上的 AKS、Azure Stack HCI 23H2 上的 AKS

本文說明如何使用容器記憶體介面 (CSI) 驅動程式,在 Azure Arc 所啟用的 AKS 中同時存取相同記憶體磁碟區的多個節點時,掛接伺服器消息塊 (SMB) 或 NFS 共用。

AKS Arc 中的 CSI 概觀

容器儲存體介面 (CSI) 是將任意區塊和檔案儲存系統公開給 Kubernetes 上容器化工作負載的標準。 透過使用 CSI,Arc 所啟用的 AKS 可以寫入、部署和逐一查看外掛程式,以公開新的儲存系統。 使用 CSI 也可以改善 Kubernetes 中現有的儲存系統,而不需要變更核心 Kubernetes 程式碼,然後等候其發行週期。

AKS Arc 所使用的磁碟和檔案 CSI 驅動程式與 CSI 規格相容驅動程式。

AKS Arc 上的 CSI 記憶體驅動程式支援可讓您使用:

  • 可用來建立 Kubernetes DataDisk 資源的 AKS Arc 磁碟。 這些磁碟會以 ReadWriteOnce 的形式掛接,因此僅適用於單一節點。 對於可同時由多個 Pod 存取的記憶體磁碟區,請使用 AKS Arc 檔案

  • 可用來將 SMB 或 NFS 共用掛接至 Pod 的 AKS Arc 檔案。 這些檔案會以 ReadWriteMany 的形式掛接,因此您可以在多個節點和 Pod 之間共用資料。 這些檔案也可以根據 PVC 規格 (永續性磁碟區宣告) 掛接為 ReadWriteOnce

使用 ReadWriteMany CSI 驅動程式使用檔案永續性磁碟區

如果多個節點需要同時存取 AKS Arc 中的相同儲存磁碟區,您可以使用 CSI 驅動程式將 SMB 或 NFS 共用掛接為 ReadWriteMany。 您必須事先布建 SMB 或 NFS 共用。

使用 SMB 驅動程式

  1. 請確定已部署SMB驅動程式。 當您使用 Azure 入口網站 或 az aksarc create 命令建立 Kubernetes 叢集時,預設會安裝 SMB CSI 驅動程式。 如果您使用 建立 Kubernetes 叢集 --disable-smb-driver,則必須使用 az aksarc update 命令在此叢集上啟用 SMB 驅動程式:

    az aksarc update -n $aksclustername -g $resource_group --enable-smb-driver
    
  1. 藉由執行下列命令,建立 Kubernetes 秘密來儲存存取 SMB 共用所需的認證:

    kubectl create secret generic smbcreds --from-literal username=$username --from-literal password=$password --from-literal domain=$domain
    
  2. 使用 kubectl 建立儲存類別,藉此以下列資訊清單來建立新的 SMB 儲存類別:

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: smb-csi
    provisioner: smb.csi.akshci.com
    parameters:
       source: \\smb-server\share
       csi.storage.k8s.io/node-stage-secret-name: "smbcreds"
       csi.storage.k8s.io/node-stage-secret-namespace: "default"
    reclaimPolicy: Retain  # only Retain is supported
    volumeBindingMode: Immediate
    mountOptions:
      - dir_mode=0777
      - file_mode=0777
      - uid=1001
      - gid=1001
    

使用 NFS 驅動程式

  1. 請確定已部署 NFS 驅動程式。 當您使用 Azure 入口網站 或 az aksarc create 命令建立 Kubernetes 叢集時,預設會安裝 NFS CSI 驅動程式。 如果您使用 建立 Kubernetes 叢集 --disable-nfs-driver,則必須使用 az aksarc update 命令,在此叢集上啟用 NFS 驅動程式:

    az aksarc update -n $aksclustername -g $resource_group --enable-nfs-driver
    
  1. 使用下列資訊清單來建立 NFS 儲存類別:

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: nfs-csi
    provisioner: nfs.csi.akshci.com
    parameters:
      server: nfs-server.default.svc.cluster.local # NFS server endpoint
      share: / # NFS share path
    reclaimPolicy: Retain
    volumeBindingMode: Immediate
    mountOptions:
      - hard
      - nfsvers=4.1
    

若要解除安裝 SMB 或 NFS 驅動程式

使用下列 Azure CLI 命令來卸載 SMB 或 NFS 驅動程式:

az aksarc update -n $aksclustername -g $resource_group --disable-smb-driver
az aksarc update -n $aksclustername -g $resource_group --disable-nfs-driver

後續步驟