4.9. 使用 iSCSI 的持久性存储

您可以使用 iSCSI为 OpenShift Container Platform 集群提供持久性存储。我们假设您对 Kubernetes 和 iSCSI 有一定的了解。

Kubernetes 持久性卷框架允许管理员提供带有持久性存储的集群,并使用户可以在不了解底层存储架构的情况下请求这些资源。

重要

存储的高可用性功能由底层存储供应商实现。

重要

当您在 Amazon Web Services 上使用 iSCSI 时,必须更新默认的安全策略,使其包含 iSCSI 端口中节点间的 TCP 流量。默认情况下,它们是端口 8603260

重要

用户必须通过安装 iscsi-initiator-utils 软件包并在 /etc/iscsi/initiatorname.iscsi 中配置启动器名称,确保所有 OpenShift Container Platform 节点上已配置了 iSCSI 启动器。iscsi-initiator-utils 软件包已在使用 Red Hat Enterprise Linux CoreOS (RHCOS) 的部署中安装。

如需更多信息,请参阅管理存储设备

4.9.1. 置备

在将存储作为卷挂载到 OpenShift Container Platform 之前,请确认它已存在于底层的基础架构中。iSCSI 需要的是 iSCSI 目标门户,一个有效的 iSCSI 限定名称 (IQN) ,一个有效的 LUN 号码,文件系统类型,以及 persistenceVolume API。

PersistentVolume 对象定义

apiVersion: v1
kind: PersistentVolume
metadata:
  name: iscsi-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  iscsi:
     targetPortal: 10.16.154.81:3260
     iqn: iqn.2014-12.example.server:storage.target00
     lun: 0
     fsType: 'ext4'

4.9.2. 强制磁盘配额

使用 LUN 分区强制磁盘配额和大小限制。每个 LUN 都是一个持久性卷。kubernetes 为持久性卷强制使用唯一的名称。

以这种方式强制配额可让最终用户以特定数量(如 10Gi)请求持久性存储,并与相等或更大容量的对应卷匹配。

4.9.3. iSCSI 卷安全

用户使用 PersistentVolumeClaim 对象请求存储。这个声明只在用户的命名空间中有效,且只能被在同一命名空间中的 pod 调用。尝试使用其他命名空间中的持久性卷声明会导致 pod 失败。

每个 iSCSI LUN 都需要可以被集群中的所有节点访问。

4.9.3.1. Challenge Handshake Authentication Protocol (CHAP) 配置

另外,OpenShift Container Platform 可以使用 CHAP 在 iSCSI 目标中验证自己:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: iscsi-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  iscsi:
    targetPortal: 10.0.0.1:3260
    iqn: iqn.2016-04.test.com:storage.target00
    lun: 0
    fsType: ext4
    chapAuthDiscovery: true 1
    chapAuthSession: true 2
    secretRef:
      name: chap-secret 3
1
启用 iSCSI 发现的 CHAP 验证。
2
启用 iSCSI 会话的 CHAP 验证。
3
使用用户名 + 密码指定 Secrets 对象的名称。该 Secret 对象必须在所有可使用引用卷的命名空间中可用。

4.9.4. iSCSI 多路径

对于基于 iSCSI 的存储,您可以使用相同的 IQN 为多个目标入口 IP 地址配置多路径。通过多路径,当路径中的一个或者多个组件失败时,仍可保证对持久性卷的访问。

要在 pod 规格中指定多路径,请使用 portals 字段。例如:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: iscsi-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  iscsi:
    targetPortal: 10.0.0.1:3260
    portals: ['10.0.2.16:3260', '10.0.2.17:3260', '10.0.2.18:3260'] 1
    iqn: iqn.2016-04.test.com:storage.target00
    lun: 0
    fsType: ext4
    readOnly: false
1
使用 portals 字段添加额外的目标门户。

4.9.5. iSCSI 自定义 initiator IQN

如果 iSCSI 目标仅限于特定的 IQN,则配置自定义 initiator iSCSI 限定名称 (IQN) ,但不会保证 iSCSI PV 附加到的节点具有这些 IQN。

使用 initiatorName 字段指定一个自定义 initiator IQN。

apiVersion: v1
kind: PersistentVolume
metadata:
  name: iscsi-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  iscsi:
    targetPortal: 10.0.0.1:3260
    portals: ['10.0.2.16:3260', '10.0.2.17:3260', '10.0.2.18:3260']
    iqn: iqn.2016-04.test.com:storage.target00
    lun: 0
    initiatorName: iqn.2016-04.test.com:custom.iqn 1
    fsType: ext4
    readOnly: false
1
指定 initiator 的名称。