

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 NFS CSI 驱动程序
<a name="use-nfs-csi"></a>

按照本节中的程序，在 Kubernetes 集群中安装、配置或删除在 Amazon S3 文件网关中使用 NFS 文件共享作为存储所需的 CSI 驱动程序。有关更多信息，请参阅上的开源 NFS CSI 驱动程序文档，网址 GitHub 为[https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/install-csi-driver-master.md](https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/install-csi-driver-master.md)。

## 安装驱动程序
<a name="install-nfs-csi"></a>

**要安装 Kubernetes NFS CSI 驱动程序，请执行以下操作：**

1. 在可以访问 Kubernetes 集群的 `kubectl` 的命令行终端中，运行以下命令：

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

1. 等待上一个命令完成，然后使用以下命令来确保 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
<a name="create-storageclass-nfs-csi"></a>

**要为您的 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
   ```

1. 在可以访问 `kubectl` 和 `storageclass.yaml` 的命令行终端中，运行以下命令：

   **kubectl apply -f storageclass.yaml**
**注意**  
您还可以 StorageClass 通过向大多数第三方 Kubernetes 管理和容器化平台提供上一步中的`.yaml`配置文本来创建。

1. 将 Kubernetes 集群中的容器配置为使用您创建的新 StorageClass对象。有关更多信息，请参阅 Kubernetes 在线文档，网址为 [https://kubernetes.io/docs/concepts/storage/](https://kubernetes.io/docs/concepts/storage/)。

## 创建 NFS PersistentVolume 和对象 PersistentVolumeClaim
<a name="create-persistentvolume-volumeclaim-nfs-csi"></a>

**要创建新的 NFS PersistentVolume 和 PersistentVolumeClaim 对象，请执行以下操作：**

1. 创建两个配置文件，分别名为 `persistentvolume.yaml` 和 `persistentvolumeclaim.yaml`。

1. 对于 `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}}
   ```

1. 对于 `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: ""
   ```

1. 在可以访问 `kubectl` 和两个 `.yaml` 文件的命令行终端中，运行以下命令：

   **kubectl apply -f persistentvolume.yaml**

   **kubectl apply -f persistentvolumeclaim.yaml**
**注意**  
您还可以通过向大多数第三方 Kubernetes 管理和容器化平台提供上一步中的`.yaml`配置文本来创建和 PersistentVolumeClaim对象。 PersistentVolume 

1. 将 Kubernetes 集群中的容器配置为使用您创建的新 PersistentVolumeClaim 对象。有关更多信息，请参阅 Kubernetes 在线文档，网址为 [https://kubernetes.io/docs/concepts/storage/](https://kubernetes.io/docs/concepts/storage/)。

## 卸载驱动程序
<a name="uninstall-nfs-csi"></a>

**要卸载 Kubernetes NFS CSI 驱动程序，请执行以下操作：**
+ 在可以访问 Kubernetes 集群的 `kubectl` 的命令行终端中，运行以下命令：

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