容器存储接口 (CSI)

在 Kubernetes V1.10 中,容器存储接口 (CSI) 现在以 Beta 版形式提供。 随着提升为 Beta 版,缺省情况下 CSI 现在处于启用状态。 有关 Kubernetes 中的 CSI Beta 版实现的更多信息,请参阅 Kubernetes 的容器存储接口 (CSI) 以 Beta 版形式提供在新选项卡中打开

配置 CSI

大多数 CSI 插件要求在 API 服务器二进制文件和 Kubelet 二进制文件中设置 --allow-privileged=true 标志。 缺省情况下,IBM Cloud Private 中已启用此标志。 对于 IBM Cloud Private 环境,您可以在 Kubernetes Pod 中使用 CSI 卷,而不必设置任何额外的配置。

示例:在 IBM Cloud Private 中部署 CSI NFS 驱动程序

此样本部署中使用的样本文件获取自 Kubernetes GitHub 存储库。 请参阅 kubernetes-csi/drivers 在新选项卡中打开

  1. 安装 NFS。 有关设置 NFS 的更多信息,请参阅创建 NFS PersistentVolume 主题中的先决条件部分。
  2. 克隆 kubernetes-csi/drivers 在新选项卡中打开 存储库。

  3. 切换到 nfs 目录。

    cd drivers/pkg/nfs
    
  4. 创建部署。

     kubectl create -f ./deploy/kubernetes/
    

    输出类似于以下代码:

     service "csi-attacher-nfsplugin" created
     statefulset.apps "csi-attacher-nfsplugin" created
     serviceaccount "csi-attacher" created
     clusterrole.rbac.authorization.k8s.io "external-attacher-runner" created
     clusterrolebinding.rbac.authorization.k8s.io "csi-attacher-role" created
     daemonset.apps "csi-nodeplugin-nfsplugin" created
     serviceaccount "csi-nodeplugin" created
     clusterrole.rbac.authorization.k8s.io "csi-nodeplugin" created
     clusterrolebinding.rbac.authorization.k8s.io "csi-nodeplugin" created
    
  5. 使用所创建的 CSI 卷来部署 Pod。

    1. 找到 NFS 服务器。

       showmount -e
      

      输出类似于以下代码:

       Export list for nfsserver:
       /nfs *
      
    2. 编辑 examples/kubernetes/nginx.yaml 文件。 更新 servershare 参数,以使它们与您的系统设置相匹配。

       cat examples/kubernetes/nginx.yaml | grep csi -A 5
      

      输出类似于以下代码:

         csi:
           driver: csi-nfsplugin
           volumeHandle: data-id
           volumeAttributes:
             server: 10.10.25.7
             share: /nfs
       ---
      
    3. 使用 NFS 驱动程序创建 Pod。

       kubectl create -f examples/kubernetes/nginx.yaml
      

      输出类似于以下代码:

       persistentvolume "data-nfsplugin" created
       persistentvolumeclaim "data-nfsplugin" created
       pod "nginx" created
      
  6. 检查安装点。

    1. 访问 nginx 容器。

       kubectl exec -it nginx sh
      
    2. 切换到 /var/www 目录。

       cd /var/www
      
    3. 创建文件。

       touch test
      
    4. 列示安装点上的文件。

      ls
      

      输出类似于以下代码:

      test
      
  7. 检查 NFS 服务器。

    1. 查找该服务器。

      hostname
      

      输出类似于以下代码:

      nfsserver
      
    2. 列示该服务器上的文件。

      ls /nfs
      

      输出类似于以下代码:

      test