6.2. 使用命令行创建 LocalVolumeSet 自定义资源

创建 LocalVolumeSet 自定义资源,根据您指定的条件自动将某些存储设备置备为持久性卷。在任何符合 nodeSelector 条件的节点中,会为符合 deviceInclusionSpec 条件的任何设备创建持久性卷。

先决条件

  • 对 OpenShift Container Platform 集群的管理访问权限。

流程

  1. local-volume-set.yaml 文件中定义 LocalVolumeSet 自定义资源。

    apiVersion: local.storage.openshift.io/v1alpha1
    kind: LocalVolumeSet
    metadata:
      name: localblock
    spec:
      nodeSelector:
        nodeSelectorTerms:
          - matchExpressions:
              - key: kubernetes.io/hostname
                operator: In
                values:
                  - worker1.example.com
                  - worker2.example.com
                  - worker3.example.com
      storageClassName: localblock
      volumeMode: Block
      maxDeviceCount: 10 # optional, limit devices provisioned per node
      deviceInclusionSpec:
        deviceTypes: # list of types to allow
          - disk
          - part # omit this to use only whole devices
        deviceMechanicalProperty:
          - NonRotational
        minSize: 100Gi # optional, minimum size of device to allow
        maxSize: 100Ti # optional, maximum size of device to allow
        models: # (optional) list of models to allow
          - SAMSUNG
          - Crucial_CT525MX3
        vendors: # (optional) list of device vendors to allow
          - ATA
          - ST2000LM

    以上定义从 worker1worker2worker3 节点选择特定类型的非轮转设备中的整个磁盘或分区,这些设备的大小为 100 GB 到 100 TB。localblock 存储类被创建,持久性卷是从发现的设备中置备的。

    重要

    minSize 选择一个适当的值,以确保没有选择系统分区。

  2. 创建 LocalVolumeSet

    $ oc create -f local-volume-set.yaml

验证步骤

  1. 使用以下命令跟踪与 deviceInclusionSpec 匹配设备的持久性卷置备。调配持久卷可能需要几分钟时间。

    $ oc describe localvolumeset localblock
    [...]
    Status:
      Conditions:
        Last Transition Time:          2020-11-17T05:03:32Z
        Message:                       DiskMaker: Available, LocalProvisioner: Available
        Status:                        True
        Type:                          DaemonSetsAvailable
        Last Transition Time:          2020-11-17T05:03:34Z
        Message:                       Operator reconciled successfully.
        Status:                        True
        Type:                          Available
      Observed Generation:             1
      Total Provisioned Device Count: 4
    Events:
    Type    Reason      Age          From                Message
    ----    ------      ----         ----                -------
    Normal  Discovered  2m30s (x4    localvolumeset-     ip-10-0-147-124.us-east-
            NewDevice   over 2m30s)  symlink-controller  2.compute.internal -
                                                         found possible matching
                                                         disk, waiting 1m to claim
    Normal  FoundMatch  89s (x4      localvolumeset-     ip-10-0-147-124.us-east-
            ingDisk     over 89s)    symlink-controller  2.compute.internal -
                                                         symlinking matching disk
  2. 验证调配的持久卷的状态。

    $ oc get pv
                         ACCESS   RECLAIM             STORAGE
    NAME       CAPACITY  MODES    POLICY   STATUS     CLASS       AGE
    local-pv-  500Gi     RWO      Delete   Available  localblock  7m48s
    3584969f
    local-pv-  500Gi     RWO      Delete   Available  localblock  7m48s
    3aee84fa
    local-pv-  500Gi     RWO      Delete   Available  localblock  7m48s
    644d09ac
    local-pv-  500Gi     RWO      Delete   Available  localblock  7m48s
    c73cee1