Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

4.13. 配置 OpenShift Container Registry

可使用安装程序部署集成的 OpenShift Container Registry

4.13.1. 配置 registry 存储

如果没有使用 registry 存储选项,默认的 OpenShift Container Registry 为临时存储。当 pod 不再存在时会丢失所有数据。

重要

测试显示,使用 RHEL NFS 服务器作为容器镜像 registry 的存储后端会出现问题。这包括 OpenShift Container Registry 和 Quay。因此,不建议使用 RHEL NFS 服务器来备份核心服务使用的 PV。

市场上的其他 NFS 实现可能没有这些问题。如需了解更多与此问题相关的信息,请联络相关的 NFS 厂商。

在使用高级安装程序时启用 registry 存储有几个选项:

选项 A:NFS 主机组

当设置以下变量时,会在集群安装过程中在 [nfs]主机组中的主机上创建一个 NFS 卷(路径为 <nfs_directory>/<volume_name>)例如,使用这些选项的卷路径是 /exports/registry:

[OSEv3:vars]

# nfs_directory must conform to DNS-1123 subdomain must consist of lower case
# alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character

openshift_hosted_registry_storage_kind=nfs
openshift_hosted_registry_storage_access_modes=['ReadWriteMany']
openshift_hosted_registry_storage_nfs_directory=/exports
openshift_hosted_registry_storage_nfs_options='*(rw,root_squash)'
openshift_hosted_registry_storage_volume_name=registry
openshift_hosted_registry_storage_volume_size=10Gi
选项 B:外部 NFS 主机

要使用外部 NFS 卷,必须在存储主机上有 <nfs_directory>/<volume_name> 路径。使用以下选项的远程卷路径为 nfs.example.com:/exports/registry

[OSEv3:vars]

# nfs_directory must conform to DNS-1123 subdomain must consist of lower case
# alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character

openshift_hosted_registry_storage_kind=nfs
openshift_hosted_registry_storage_access_modes=['ReadWriteMany']
openshift_hosted_registry_storage_host=nfs.example.com
openshift_hosted_registry_storage_nfs_directory=/exports
openshift_hosted_registry_storage_volume_name=registry
openshift_hosted_registry_storage_volume_size=10Gi
升级或安装带有 NFS 的 OpenShift Container Platform
选项 C:OpenStack Platform

OpenStack 存储配置必须已经存在。

[OSEv3:vars]

openshift_hosted_registry_storage_kind=openstack
openshift_hosted_registry_storage_access_modes=['ReadWriteOnce']
openshift_hosted_registry_storage_openstack_filesystem=ext4
openshift_hosted_registry_storage_openstack_volumeID=3a650b4f-c8c5-4e0a-8ca5-eaee11f16c57
openshift_hosted_registry_storage_volume_size=10Gi
选项 D::WS 或者其它 S3 存储解决方案

简单的存储解决方案(S3)存储桶必须已经存在。

[OSEv3:vars]

#openshift_hosted_registry_storage_kind=object
#openshift_hosted_registry_storage_provider=s3
#openshift_hosted_registry_storage_s3_accesskey=access_key_id
#openshift_hosted_registry_storage_s3_secretkey=secret_access_key
#openshift_hosted_registry_storage_s3_bucket=bucket_name
#openshift_hosted_registry_storage_s3_region=bucket_region
#openshift_hosted_registry_storage_s3_chunksize=26214400
#openshift_hosted_registry_storage_s3_rootdirectory=/registry
#openshift_hosted_registry_pullthrough=true
#openshift_hosted_registry_acceptschema2=true
#openshift_hosted_registry_enforcequota=true

如果您使用不同的 S3 服务,如 Minio 或 ExoScale,还要添加 region 端点参数:

openshift_hosted_registry_storage_s3_regionendpoint=https://myendpoint.example.com/
选项 E:聚合模式

配置聚合模式 类似,可将 Red Hat Gluster Storage 配置为在初始安装集群期间为 OpenShift Container Registry 提供存储,以便为 registry 提供冗余可靠的存储。

重要

如需具体主机的准备和先决条件,请参阅 聚合模式考虑

  1. 在清单文件的 [OSEv3:vars] 部分中设置以下变量,并根据您的配置需要调整它们:

    [OSEv3:vars]
    ...
    openshift_hosted_registry_storage_kind=glusterfs 1
    openshift_hosted_registry_storage_volume_size=5Gi
    openshift_hosted_registry_selector='node-role.kubernetes.io/infra=true'
    1
    建议在基础架构节点上运行集成的 OpenShift Container Registry。基础架构节点是专用于运行管理员部署的应用程序的节点,用于为 OpenShift Container Platform 集群提供服务。
  2. [OSEv3: Child] 部分添加 glusterfs_registry 来启用 [glusterfs_registry] 组:

    [OSEv3:children]
    masters
    nodes
    glusterfs_registry
  3. 添加 [glusterfs_registry] 部分,其中包含托管 GlusterFS 存储的每个存储节点的条目。对于每个节点,将 glusterfs_devices 设置为作为 GlusterFS 集群一部分完全管理的原始块设备列表。必须至少列出一个设备。每个设备都必须是空的,没有分区或 LVM PV。以以下形式指定变量:

    <hostname_or_ip> glusterfs_devices='[ "</path/to/device1/>", "</path/to/device2>", ... ]'

    例如:

    [glusterfs_registry]
    node11.example.com glusterfs_devices='[ "/dev/xvdc", "/dev/xvdd" ]'
    node12.example.com glusterfs_devices='[ "/dev/xvdc", "/dev/xvdd" ]'
    node13.example.com glusterfs_devices='[ "/dev/xvdc", "/dev/xvdd" ]'
  4. [glusterfs_registry] 下列出的主机添加到 [nodes] 组中:

    [nodes]
    ...
    node11.example.com openshift_node_group_name="node-config-infra"
    node12.example.com openshift_node_group_name="node-config-infra"
    node13.example.com openshift_node_group_name="node-config-infra"
选项 F: Google Compute Engine(GCE)上的 Google Cloud Storage(GCS)存储桶

GCS 存储桶必须已经存在。

[OSEv3:vars]

openshift_hosted_registry_storage_provider=gcs
openshift_hosted_registry_storage_gcs_bucket=bucket01
openshift_hosted_registry_storage_gcs_keyfile=test.key
openshift_hosted_registry_storage_gcs_rootdirectory=/registry
选项 G:使用 vSphere Cloud Provider(VCP)的 vSphere 卷

vSphere Cloud Provider 必须通过 OpenShift Container Platform 节点访问的数据存储进行配置。

在为 registry 使用 vSphere 卷时,您必须将存储访问模式设置为 ReadWriteOnce,并将副本数设置为 1:

[OSEv3:vars]

openshift_hosted_registry_storage_kind=vsphere
openshift_hosted_registry_storage_access_modes=['ReadWriteOnce']
openshift_hosted_registry_storage_annotations=['volume.beta.kubernetes.io/storage-provisioner: kubernetes.io/vsphere-volume']
openshift_hosted_registry_replicas=1