使用 vSphere 容器存储接口驱动程序

本文档介绍如何将 vSphere 容器存储接口 (CSI) 驱动程序与 Anthos Clusters on VMware 搭配使用。

概览

vSphere CSI 驱动程序自动部署到 Anthos clusters on VMware 中。如需了解使用其他 CSI 驱动程序,请参阅安装 CSI 驱动程序

vSphere 要求

如需使用 vSphere CSI 驱动程序,您必须具有:

卷扩展

  • 离线卷扩展要求 vCenter Server 和 ESXi 为版本 7.0 Update 1 或更高版本

  • 在线卷扩展要求 vCenter Server 和 ESXi 为版本 7.0 Update 2 或更高版本。

卷快照

卷快照要求 vCenter Server 和 ESXi 都是 7.0 Update 3 或更高版本。

Cns.Searchable

您的 vCenter 用户帐号必须具有根 vCenter 对象的 Cns.Searchable 权限。

如果您不确定您的帐户是否符合 CSI 前提条件,请先运行 gkectl diagnose cluster,然后再部署任何 CSI 工作负载。

验证是否已安装驱动程序

当您的用户集群中安装了 vSphere CSI 驱动程序时,系统会创建名为 standard-rwo 的 StorageClass。

列出 StorageClass 对象:

kubectl --kubeconfig CLUSTER_KUBECONFIG get storageclass

CLUSTER_KUBECONFIG 替换为集群 kubeconfig 文件的路径。

验证输出中出现 standard-rwo。例如:

standard                 kubernetes.io/vsphere-volume  Delete   Immediate     false      33m
standard-rwo (default)   csi.vsphere.vmware.com    Delete   Immediate     true       32m

验证 vSphere CSI 驱动程序已安装:

kubectl --kubeconfig CLUSTER_KUBECONFIG get csinode \
    -o="custom-columns=NAME:metadata.name,DRIVERS:spec.drivers[].name"

输出应表明该驱动程序在所有集群节点上都可用。例如:

NAME     DRIVERS
node-0   csi.vsphere.vmware.com
node-1   csi.vsphere.vmware.com
node-2   csi.vsphere.vmware.com

预配卷

如需使用 vSphere CSI 驱动程序预配卷,请将 PersistentVolumeClaimstorageClassName 字段设置为 standard-rwo

设置默认存储类别

如需将 standard-rwo 设为默认存储类别,请参阅默认存储类别

使用快照恢复卷

请参阅从快照恢复卷

创建其他 StorageClass

您可以使用 datastoreurlstoragepolicyname 参数在集群中创建其他 vSphere CSI StorageClasses。

以下示例使用 storagepolicyname 参数:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gold
parameters:
  csi.storage.k8s.io/fstype: ext4
  storagepolicyname: "Gold Policy"
provisioner: csi.vsphere.vmware.com

如需查找 datastoreurl 参数的正确值,请运行以下命令:

govc datastore.info DATASTORE_NAME

DATASTORE_NAME 替换为您的 vSphere 数据存储区的名称。

使用 datastoreurl 的输出中的 URL 值。输出示例如下所示:

Name:        DATASTORE_NAME
  Path:      /DATACENTER_NAME/datastore/DATASTORE_NAME
  Type:      VMFS
  URL:       ds:///vmfs/volumes/5d864fa0-7f2184d4-8eb4-3cfdfe0ce9a0/
  Capacity:  20479.8 GB
  Free:      10066.9 GB

卷清理

当您删除用户集群时,系统不会删除由 vSphere CSI 驱动程序预配的卷。在删除集群之前,您应该先删除所有 PVC 和 StatefulSet。要删除卷,请运行以下命令:

kubectl delete statefulsets,persistentvolumeclaims --namespace=MY_NAMESPACE --all

MY_NAMESPACE 替换为您的 Kubernetes 命名空间

如果您删除了用户集群而未删除其卷,则可以在 vSphere 界面中找到这些卷:

  1. 选择数据存储区。

  2. 导航到监控 > 云原生存储 > 容器卷

  3. 在每个卷的详细信息部分中,您可以看到 Kubernetes 集群名称。

停用 vSphere CSI 驱动程序

如需移除 vSphere CSI 支持,请在您的用户集群配置中添加以下内容:

# (Optional) Storage specification for the cluster storage:
# To disable the vSphere CSI driver, set this to true. The value is set to false by default and
# the vSphere CSI driver is enabled by default on vSphere version >= 6.7U3.
  vSphereCSIDisabled: true

后续步骤