本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 SMB CSI 驅動程式
請依照本節中的程序,安裝、設定或刪除在 Amazon S3 檔案閘道上使用 SMB 檔案共用,以便在 Kubernetes 叢集中儲存所需的 CSI 驅動程式。如需詳細資訊,請參閱 GitHub 上的開放原始碼 SMB CSI 驅動程式文件,網址為 https://github.com/kubernetes-csi/csi-driver-smb/blob/master/docs/install-csi-driver-master.md
注意
建立PersistentVolume物件或StorageClass物件時,您可以指定ReclaimPolicy參數,以判斷刪除物件時外部儲存體會發生什麼情況。SMB CSI 驅動程式支援 Retain和 Recycle選項,但目前不支援 Delete選項。
安裝驅動程式
安裝 Kubernetes SMB CSI 驅動程式:
-
從可存取
kubectl的命令列終端機中,為您的 Kubernetes 叢集執行下列命令:curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy/install-driver.sh | bash -s master --
-
等待上一個命令完成,然後使用下列命令來確保 CSI 驅動程式 Pod 正在執行:
kubectl -n kube-system get pod -o wide --watch -l app=csi-smb-controller
kubectl -n kube-system get pod -o wide --watch -l app=csi-smb-node
輸出格式應類似以下內容:
NAME READY STATUS RESTARTS AGE IP NODE csi-smb-controller-56bfddd689-dh5tk 4/4 Running 0 35s 10.240.0.19 k8s-agentpool-22533604-0 csi-smb-controller-56bfddd689-8pgr4 4/4 Running 0 35s 10.240.0.35 k8s-agentpool-22533604-1 csi-smb-node-cvgbs 3/3 Running 0 35s 10.240.0.35 k8s-agentpool-22533604-1 csi-smb-node-dr4s4 3/3 Running 0 35s 10.240.0.4 k8s-agentpool-22533604-0
建立 SMB StorageClass 物件
若要為您的 Kubernetes 叢集建立新的 SMB StorageClass 物件:
-
建立名為 的組態檔案
storageclass.yaml,其中包含類似下列範例的內容。針對顯示的ExampleValues替換您自己的部署特定資訊。--- apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name:ExampleStorageClassNameprovisioner: smb.csi.k8s.io parameters: source: "//gateway-dns-name-or-ip-address/example-share-name" # if csi.storage.k8s.io/provisioner-secret is provided, will create a sub directory # with PV name under source csi.storage.k8s.io/provisioner-secret-name: "examplesmbcreds" csi.storage.k8s.io/provisioner-secret-namespace: "examplenamespace" csi.storage.k8s.io/node-stage-secret-name: "examplesmbcreds" csi.storage.k8s.io/node-stage-secret-namespace: "examplenamespace" volumeBindingMode: Immediate reclaimPolicy: Retain mountOptions: - dir_mode=0777 - file_mode=0777 - uid=1001 - gid=1001 -
從可存取
kubectl和 的命令列終端機storageclass.yaml,執行下列命令:kubectl apply -f storageclass.yaml
注意
您也可以將上一個步驟的
.yaml組態文字提供給大多數第三方 Kubernetes 管理和容器化平台,以建立 StorageClass。 -
將 Kubernetes 叢集中的 Pod 設定為使用您建立的新 StorageClass。如需詳細資訊,請參閱 中的 Kubernetes 線上文件https://kubernetes.io/docs/concepts/storage/
。
建立 SMB PersistentVolume 和 PersistentVolumeClaim 物件
若要建立新的 SMB PersistentVolume 和 PersistentVolumeClaim 物件:
-
建立兩個組態檔案。一個名為
persistentvolume.yaml,另一個名為persistentvolumeclaim.yaml。 -
對於
persistentvolume.yaml,新增類似下列範例的內容。將您自己的部署特定資訊替換為所示的ExampleValues。--- apiVersion: v1 kind: PersistentVolume metadata: name:pv-smb-example-namenamespace:smb-example-namespace# PersistentVolume and PersistentVolumeClaim must use the same namespace parameter spec: capacity: storage: 100Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain mountOptions: - dir_mode=0777 - file_mode=0777 - vers=3.0 csi: driver: smb.csi.k8s.io readOnly: false volumeHandle:examplehandle# make sure it's a unique id in the cluster volumeAttributes: source: "//gateway-dns-name-or-ip-address/example-share-name" nodeStageSecretRef: name:example-smbcredsnamespace:smb-example-namespace -
對於
persistentvolumeclaim.yaml,新增類似下列範例的內容。將您自己的部署特定資訊替換為所示的ExampleValues。--- kind: PersistentVolumeClaim apiVersion: v1 metadata: name:examplename-pvc-smb-staticnamespace:smb-example-namespace# PersistentVolume and PersistentVolumeClaim must use the same namespace parameter spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi volumeName:pv-smb-example-name# make sure specfied volumeName matches the name of the PersistentVolume you created storageClassName: "" -
從可存取
kubectl和您建立的兩個.yaml檔案的命令列終端機,執行下列命令:kubectl apply -f persistentvolume.yaml
kubectl apply -f persistentvolumeclaim.yaml
注意
您也可以透過將上一個步驟的
.yaml組態文字提供給大多數第三方 Kubernetes 管理和容器化平台,來建立 PersistentVolume 和 PersistentVolumeClaim 物件。 -
將 Kubernetes 叢集中的 Pod 設定為使用您建立的新 PersistentVolumeClaim。如需詳細資訊,請參閱 中的 Kubernetes 線上文件https://kubernetes.io/docs/concepts/storage/
。
解除安裝驅動程式
若要解除安裝 Kubernetes SMB CSI 驅動程式:
-
從可存取
kubectl的命令列終端機中,為您的 Kubernetes 叢集執行下列命令:curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy/uninstall-driver.sh | bash -s --