使用 NFS CSI 驅動程式 - AWS Storage Gateway

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 NFS CSI 驅動程式

請依照本節中的程序,在 Amazon S3 檔案閘道上安裝、設定或刪除在 Kubernetes 叢集中儲存使用 NFS 檔案共用所需的 CSI 驅動程式。如需詳細資訊,請參閱 GitHub 上的開放原始碼 NFS CSI 驅動程式文件,網址為 https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/install-csi-driver-master.md

安裝驅動程式

安裝 Kubernetes NFS CSI 驅動程式:
  1. 從可存取 kubectl 的命令列終端機為您的 Kubernetes 叢集執行下列命令:

    curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/install-driver.sh | bash -s master --

  2. 等待上一個命令完成,然後使用下列命令來確保 CSI 驅動程式 Pod 正在執行:

    kubectl -n kube-system get pod -o wide -l app=csi-nfs-controller

    kubectl -n kube-system get pod -o wide -l app=csi-nfs-node

    輸出格式應類似以下內容:

    NAME READY STATUS RESTARTS AGE IP NODE csi-nfs-controller-56bfddd689-dh5tk 4/4 Running 0 35s 10.240.0.19 k8s-agentpool-22533604-0 csi-nfs-controller-56bfddd689-8pgr4 4/4 Running 0 35s 10.240.0.35 k8s-agentpool-22533604-1 csi-nfs-node-cvgbs 3/3 Running 0 35s 10.240.0.35 k8s-agentpool-22533604-1 csi-nfs-node-dr4s4 3/3 Running 0 35s 10.240.0.4 k8s-agentpool-22533604-0

建立 NFS StorageClass 物件

若要為您的 Kubernetes 叢集建立 NFS StorageClass 物件:
  1. 建立名為 的組態檔案storageclass.yaml,其中包含類似下列範例的內容。針對顯示的 ExampleValues 替換您自己的部署特定資訊。

    --- apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: example-nfs-classname namespace: example-namespace provisioner: nfs.csi.k8s.io parameters: server: gateway-dns-name-or-ip-address share: /example-share-name reclaimPolicy: Retain volumeBindingMode: Immediate mountOptions: - hard - nfsvers=4.1
  2. 從可存取 kubectl和 的命令列終端機storageclass.yaml,執行下列命令:

    kubectl apply -f storageclass.yaml

    注意

    您也可以將上一個步驟的.yaml組態文字提供給大多數第三方 Kubernetes 管理和容器化平台,以建立 StorageClass。

  3. 將 Kubernetes 叢集中的 Pod 設定為使用您建立的新 StorageClass 物件。如需詳細資訊,請參閱 中的 Kubernetes 線上文件https://kubernetes.io/docs/concepts/storage/

建立 NFS PersistentVolume 和 PersistentVolumeClaim 物件

若要建立新的 NFS PersistentVolume 和 PersistentVolumeClaim 物件:
  1. 建立兩個名為 persistentvolume.yaml和 的組態檔案persistentvolumeclaim.yaml

  2. 對於 persistentvolume.yaml,新增類似下列範例的內容。針對顯示的 ExampleValues 替換您自己的部署特定資訊。

    --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs-examplename spec: capacity: storage: 10Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain mountOptions: - hard - nolock - nfsvers=4.1 csi: driver: nfs.csi.k8s.io readOnly: false volumeHandle: unique-volumeid-example # make sure it's a unique id in the cluster volumeAttributes: server: gateway-dns-name-or-ip-address share: /example-share-name
  3. 對於 persistentvolumeclaim.yaml,新增類似下列範例的內容。針對顯示的 ExampleValues 替換您自己的部署特定資訊。

    --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: examplename-pvc-nfs-static spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi volumeName: pv-nfs-examplename # make sure specfied volumeName matches the name of the PersistentVolume you created storageClassName: ""
  4. 從可存取 kubectl和兩個.yaml檔案的命令列終端機,執行下列命令:

    kubectl apply -f persistentvolume.yaml

    kubectl apply -f persistentvolumeclaim.yaml

    注意

    您也可以透過將上一個步驟的.yaml組態文字提供給大多數第三方 Kubernetes 管理和容器化平台,來建立 PersistentVolume 和 PersistentVolumeClaim 物件。

  5. 將 Kubernetes 叢集中的 Pod 設定為使用您建立的新 PersistentVolumeClaim 物件。如需詳細資訊,請參閱 中的 Kubernetes 線上文件https://kubernetes.io/docs/concepts/storage/

解除安裝驅動程式

若要解除安裝 Kubernetes NFS CSI 驅動程式:
  • 從可存取 kubectl 的命令列終端機為您的 Kubernetes 叢集執行下列命令:

    curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/uninstall-driver.sh | bash -s master --