×

镜像控制器配置参数

image.config.openshift.io/cluster 资源保存有关如何处理镜像的集群范围信息。规范且唯一有效的名称是 cluster。它的 spec 提供以下配置参数。

诸如DisableScheduledImportMaxImagesBulkImportedPerRepositoryMaxScheduledImportsPerMinuteScheduledImageImportMinimumIntervalSecondsInternalRegistryHostname之类的参数不可配置。

参数 描述

allowedRegistriesForImport

限制普通用户可以从中导入镜像的容器镜像仓库。将此列表设置为您信任的包含有效镜像且希望应用程序能够从中导入镜像的仓库。拥有从API创建镜像或ImageStreamMappings权限的用户不受此策略的影响。通常只有集群管理员拥有相应的权限。

此列表的每个元素都包含由仓库域名指定的仓库位置。

domainName:指定仓库的域名。如果仓库使用非标准的80443端口,则应在域名中也包含端口。

insecure:不安全表示仓库是否安全或不安全。默认情况下,如果未另行指定,则假定仓库是安全的。

additionalTrustedCA

对包含在镜像流导入pod镜像拉取openshift-image-registry pullthrough和构建期间应信任的其他CA的配置映射的引用。

此配置映射的命名空间是openshift-config。配置映射的格式是使用仓库主机名作为键,并为每个要信任的其他仓库CA使用PEM编码的证书作为值。

externalRegistryHostnames

提供默认外部镜像仓库的主机名。只有当镜像仓库在外部公开时,才应设置外部主机名。第一个值用于镜像流中的publicDockerImageRepository字段。该值必须采用hostname[:port]格式。

registrySources

包含确定容器运行时在访问构建和pod的镜像时如何处理各个仓库的配置。例如,是否允许不安全访问。它不包含内部集群仓库的配置。

insecureRegistries:没有有效TLS证书或仅支持HTTP连接的仓库。要指定所有子域,请在域名前面添加星号(*)通配符字符。例如,*.example.com。您可以指定仓库中的单个仓库。例如:reg1.io/myrepo/myapp:latest

blockedRegistries:拒绝镜像拉取和推送操作的仓库。要指定所有子域,请在域名前面添加星号(*)通配符字符。例如,*.example.com。您可以指定仓库中的单个仓库。例如:reg1.io/myrepo/myapp:latest。所有其他仓库都是允许的。

allowedRegistries:允许镜像拉取和推送操作的仓库。要指定所有子域,请在域名前面添加星号(*)通配符字符。例如,*.example.com。您可以指定仓库中的单个仓库。例如:reg1.io/myrepo/myapp:latest。所有其他仓库都被阻止。

containerRuntimeSearchRegistries:允许使用镜像短名称进行镜像拉取和推送操作的仓库。所有其他仓库都被阻止。

可以设置blockedRegistriesallowedRegistries,但不能同时设置两者。

当定义allowedRegistries参数时,除非明确列出,否则所有仓库(包括registry.redhat.ioquay.io仓库以及默认的OpenShift镜像仓库)都被阻止。使用此参数时,为防止pod失败,请将所有仓库(包括registry.redhat.ioquay.io仓库以及internalRegistryHostname)添加到allowedRegistries列表中,因为它们是环境中有效负载镜像所需的。

image.config.openshift.io/cluster资源的status字段保存来自集群的观察值。

参数 描述

internalRegistryHostname

由镜像仓库操作符设置,该操作符控制internalRegistryHostname。它为默认的OpenShift镜像仓库设置主机名。该值必须采用hostname[:port]格式。为了向后兼容性,您仍然可以使用OPENSHIFT_DEFAULT_REGISTRY环境变量,但此设置会覆盖环境变量。

externalRegistryHostnames

由镜像仓库操作符设置,在镜像仓库在外部公开时提供镜像仓库的外部主机名。第一个值用于镜像流中的publicDockerImageRepository字段。该值必须采用hostname[:port]格式。

配置镜像仓库设置

您可以通过编辑image.config.openshift.io/cluster自定义资源 (CR) 来配置镜像仓库设置。当对仓库的更改应用于image.config.openshift.io/cluster CR 时,机器配置操作符 (MCO) 会执行以下顺序操作

  1. 隔离节点

  2. 通过重新启动CRI-O来应用更改

  3. 取消隔离节点

    当MCO检测到更改时,它不会重新启动节点。

步骤
  1. 编辑image.config.openshift.io/cluster自定义资源

    $ oc edit image.config.openshift.io/cluster

    以下是一个示例image.config.openshift.io/cluster CR

    apiVersion: config.openshift.io/v1
    kind: Image (1)
    metadata:
      annotations:
        release.openshift.io/create-only: "true"
      creationTimestamp: "2019-05-17T13:44:26Z"
      generation: 1
      name: cluster
      resourceVersion: "8302"
      selfLink: /apis/config.openshift.io/v1/images/cluster
      uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    spec:
      allowedRegistriesForImport: (2)
        - domainName: quay.io
          insecure: false
      additionalTrustedCA: (3)
        name: myconfigmap
      registrySources: (4)
        allowedRegistries:
        - example.com
        - quay.io
        - registry.redhat.io
        - image-registry.openshift-image-registry.svc:5000
        - reg1.io/myrepo/myapp:latest
        insecureRegistries:
        - insecure.com
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1 Image:保存有关如何处理镜像的集群范围信息。规范且唯一有效的名称是cluster
    2 allowedRegistriesForImport:限制普通用户可以从中导入容器镜像的镜像仓库。将此列表设置为您信任的包含有效镜像并希望应用程序能够从中导入镜像的仓库。拥有通过 API 创建镜像或ImageStreamMappings权限的用户不受此策略的影响。通常只有集群管理员才有相应的权限。
    3 additionalTrustedCA:指向一个 ConfigMap 的引用,该 ConfigMap 包含在镜像流导入、Pod 镜像拉取、openshift-image-registry 透传和构建期间受信任的额外证书颁发机构 (CA)。此 ConfigMap 的命名空间为openshift-config。ConfigMap 的格式是使用注册表主机名作为键,使用 PEM 证书作为值,用于每个需要信任的额外注册表 CA。
    4 registrySources:包含确定容器运行时在访问构建和 Pod 的镜像时允许或阻止各个注册表的配置。可以设置allowedRegistries参数或blockedRegistries参数,但不能同时设置两者。您还可以定义是否允许访问不安全的注册表或允许使用镜像短名称的注册表。此示例使用allowedRegistries参数,该参数定义允许使用的注册表。不安全的注册表insecure.com也被允许。registrySources参数不包含内部集群注册表的配置。

    定义allowedRegistries参数后,所有注册表(包括 registry.redhat.io 和 quay.io 注册表以及默认的 OpenShift 镜像注册表)都会被阻止,除非明确列出。如果您使用此参数,为了防止 Pod 失败,您必须将registry.redhat.ioquay.io注册表以及internalRegistryHostname添加到allowedRegistries列表中,因为它们是环境中有效负载镜像所需的。不要将registry.redhat.ioquay.io注册表添加到blockedRegistries列表中。

    使用allowedRegistriesblockedRegistriesinsecureRegistries参数时,可以在注册表中指定单个仓库。例如:reg1.io/myrepo/myapp:latest

    应避免使用不安全的外部注册表,以降低可能的安全风险。

  2. 要检查更改是否已应用,请列出您的节点。

    $ oc get nodes
    示例输出
    NAME                                         STATUS                     ROLES                  AGE   VERSION
    ip-10-0-137-182.us-east-2.compute.internal   Ready,SchedulingDisabled   worker                 65m   v1.30.3
    ip-10-0-139-120.us-east-2.compute.internal   Ready,SchedulingDisabled   control-plane          74m   v1.30.3
    ip-10-0-176-102.us-east-2.compute.internal   Ready                      control-plane          75m   v1.30.3
    ip-10-0-188-96.us-east-2.compute.internal    Ready                      worker                 65m   v1.30.3
    ip-10-0-200-59.us-east-2.compute.internal    Ready                      worker                 63m   v1.30.3
    ip-10-0-223-123.us-east-2.compute.internal   Ready                      control-plane          73m   v1.30.3

添加特定注册表

您可以添加允许进行镜像拉取和推送操作的注册表列表,以及可选的注册表中的单个仓库,方法是编辑image.config.openshift.io/cluster自定义资源 (CR)。AWS 上的 Red Hat OpenShift Service 会将对该 CR 的更改应用于集群中的所有节点。

拉取或推送镜像时,容器运行时会在image.config.openshift.io/cluster CR 中的registrySources参数下列出的注册表中搜索。如果您在allowedRegistries参数下创建了注册表列表,则容器运行时仅搜索这些注册表。列表中不存在的注册表将被阻止。

定义allowedRegistries参数后,所有注册表(包括registry.redhat.ioquay.io注册表以及默认的 OpenShift 镜像注册表)都会被阻止,除非明确列出。如果您使用此参数,为了防止 Pod 失败,请将registry.redhat.ioquay.io注册表以及internalRegistryHostname添加到allowedRegistries列表中,因为它们是环境中有效负载镜像所需的。对于断开连接的集群,还应添加镜像注册表。

步骤
  • 编辑image.config.openshift.io/cluster自定义资源

    $ oc edit image.config.openshift.io/cluster

    以下是包含允许列表的image.config.openshift.io/cluster CR 示例

    apiVersion: config.openshift.io/v1
    kind: Image
    metadata:
      annotations:
        release.openshift.io/create-only: "true"
      creationTimestamp: "2019-05-17T13:44:26Z"
      generation: 1
      name: cluster
      resourceVersion: "8302"
      selfLink: /apis/config.openshift.io/v1/images/cluster
      uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    spec:
      registrySources: (1)
        allowedRegistries: (2)
        - example.com
        - quay.io
        - registry.redhat.io
        - reg1.io/myrepo/myapp:latest
        - image-registry.openshift-image-registry.svc:5000
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1 包含确定容器运行时在访问构建和 Pod 的镜像时如何处理各个注册表的配置。它不包含内部集群注册表的配置。
    2 指定注册表(以及可选的该注册表中的仓库),用于镜像拉取和推送操作。所有其他注册表都将被阻止。

    可以设置allowedRegistries参数或blockedRegistries参数,但不能同时设置两者。

    机器配置操作员 (MCO) 会监视image.config.openshift.io/cluster资源中注册表的任何更改。当 MCO 检测到更改时,它会将节点 drain,应用更改,然后取消节点 cordon。节点返回到Ready状态后,将使用允许的注册表列表更新每个节点上的/etc/containers/policy.json文件中的镜像签名策略。

如果您的集群使用registrySources.insecureRegistries参数,请确保允许列表中包含任何不安全的注册表。

例如

spec:
  registrySources:
    insecureRegistries:
    - insecure.com
    allowedRegistries:
    - example.com
    - quay.io
    - registry.redhat.io
    - insecure.com
    - image-registry.openshift-image-registry.svc:5000

阻止特定注册表

您可以阻止任何注册表,以及可选的注册表中的单个仓库,方法是编辑image.config.openshift.io/cluster自定义资源 (CR)。AWS 上的 Red Hat OpenShift Service 会将对该 CR 的更改应用于集群中的所有节点。

拉取或推送镜像时,容器运行时会在image.config.openshift.io/cluster CR 中的registrySources参数下列出的注册表中搜索。如果您在blockedRegistries参数下创建了注册表列表,则容器运行时不会搜索这些注册表。所有其他注册表都将被允许。

为了防止 Pod 失败,请不要将registry.redhat.ioquay.io注册表添加到blockedRegistries列表中,因为它们是环境中有效负载镜像所需的。

步骤
  • 编辑image.config.openshift.io/cluster自定义资源

    $ oc edit image.config.openshift.io/cluster

    以下是包含阻止列表的image.config.openshift.io/cluster CR 示例

    apiVersion: config.openshift.io/v1
    kind: Image
    metadata:
      annotations:
        release.openshift.io/create-only: "true"
      creationTimestamp: "2019-05-17T13:44:26Z"
      generation: 1
      name: cluster
      resourceVersion: "8302"
      selfLink: /apis/config.openshift.io/v1/images/cluster
      uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    spec:
      registrySources: (1)
        blockedRegistries: (2)
        - untrusted.com
        - reg1.io/myrepo/myapp:latest
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1 包含确定容器运行时在访问构建和 Pod 的镜像时如何处理各个注册表的配置。它不包含内部集群注册表的配置。
    2 指定不应用于镜像拉取和推送操作的注册表(以及可选的该注册表中的仓库)。所有其他注册表都将被允许。

    可以设置blockedRegistries注册表或allowedRegistries注册表,但不能同时设置两者。

    机器配置操作员 (MCO) 会监视image.config.openshift.io/cluster资源中注册表的任何更改。当 MCO 检测到更改时,它会将节点 drain,应用更改,然后取消节点 cordon。节点返回到Ready状态后,对阻止注册表的更改将出现在每个节点上的/etc/containers/registries.conf文件中。

允许不安全的注册表

您可以添加不安全的注册表,以及可选的注册表中的单个仓库,方法是编辑image.config.openshift.io/cluster自定义资源 (CR)。AWS 上的 Red Hat OpenShift Service 会将对该 CR 的更改应用于集群中的所有节点。

不使用有效的 SSL 证书或不需要 HTTPS 连接的注册表被认为是不安全的。

应避免使用不安全的外部注册表,以降低可能的安全风险。

步骤
  • 编辑image.config.openshift.io/cluster自定义资源

    $ oc edit image.config.openshift.io/cluster

    以下是包含不安全注册表列表的image.config.openshift.io/cluster CR 示例

    apiVersion: config.openshift.io/v1
    kind: Image
    metadata:
      annotations:
        release.openshift.io/create-only: "true"
      creationTimestamp: "2019-05-17T13:44:26Z"
      generation: 1
      name: cluster
      resourceVersion: "8302"
      selfLink: /apis/config.openshift.io/v1/images/cluster
      uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    spec:
      registrySources: (1)
        insecureRegistries: (2)
        - insecure.com
        - reg4.io/myrepo/myapp:latest
        allowedRegistries:
        - example.com
        - quay.io
        - registry.redhat.io
        - insecure.com (3)
        - reg4.io/myrepo/myapp:latest
        - image-registry.openshift-image-registry.svc:5000
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1 包含确定容器运行时在访问构建和 Pod 的镜像时如何处理各个注册表的配置。它不包含内部集群注册表的配置。
    2 指定不安全的注册表。您可以指定该注册表中的仓库。
    3 确保允许列表中包含任何不安全的注册表。

    如果定义了allowedRegistries参数,则所有注册表(包括registry.redhat.io和quay.io注册表以及默认的OpenShift镜像注册表)都会被阻止,除非明确列出。如果您使用此参数,为了防止Pod失败,请将所有注册表(包括registry.redhat.ioquay.io注册表以及internalRegistryHostname)添加到allowedRegistries列表中,因为它们是环境中有效负载镜像所需的。对于断开连接的集群,还应添加镜像注册表。

    机器配置操作符 (MCO) 监视image.config.openshift.io/cluster CR 中注册表的任何更改,然后在检测到更改时会将节点 drain 并取消 cordon。节点恢复到Ready状态后,不安全和被阻止的注册表更改将显示在每个节点上的/etc/containers/registries.conf文件中。

添加允许镜像简短名称的注册表

您可以通过编辑image.config.openshift.io/cluster自定义资源 (CR) 来添加用于搜索镜像简短名称的注册表。AWS 上的 Red Hat OpenShift Service 会将此 CR 的更改应用于集群中的所有节点。

镜像简短名称使您可以搜索镜像,而无需在拉取规范中包含完全限定的域名。例如,您可以使用rhel7/etcd而不是registry.access.redhat.com/rhe7/etcd

在使用完整路径不切实际的情况下,您可能会使用简短名称。例如,如果您的集群引用多个内部注册表,并且其 DNS 频繁更改,则需要在每次更改时更新拉取规范中的完全限定域名。在这种情况下,使用镜像简短名称可能会有益。

拉取或推送镜像时,容器运行时会在image.config.openshift.io/cluster CR 的registrySources参数下列出的注册表中搜索。如果您在containerRuntimeSearchRegistries参数下创建了一个注册表列表,则在使用简短名称拉取镜像时,容器运行时会在这些注册表中搜索。

强烈建议不要将镜像简短名称与公共注册表一起使用,因为如果公共注册表需要身份验证,则镜像可能无法部署。请对公共注册表使用完全限定的镜像名称。

Red Hat 内部或私有注册表通常支持使用镜像简短名称。

如果您在containerRuntimeSearchRegistries参数下列出公共注册表(包括registry.redhat.iodocker.ioquay.io注册表),则会将您的凭据暴露给列表中的所有注册表,并且您面临网络和注册表攻击的风险。由于您只能拥有一个用于拉取镜像的拉取密钥(由全局拉取密钥定义),因此该密钥用于对列表中的每个注册表进行身份验证。因此,如果您在列表中包含公共注册表,则会引入安全风险。

如果每个公共注册表都需要不同的凭据,并且集群未在全局拉取密钥中列出公共注册表,则您不能在containerRuntimeSearchRegistries参数下列出多个公共注册表。

对于需要身份验证的公共注册表,只有在注册表的凭据存储在全局拉取密钥中时,才能使用镜像简短名称。

机器配置操作符 (MCO) 监视image.config.openshift.io/cluster资源中注册表的任何更改。当 MCO 检测到更改时,它会将节点 drain,应用更改,然后取消 cordon 节点。节点恢复到Ready状态后,如果添加了containerRuntimeSearchRegistries参数,则 MCO 会在每个节点上的/etc/containers/registries.conf.d目录中创建一个包含列出注册表的文件。该文件将覆盖/etc/containers/registries.conf文件中未限定搜索注册表的默认列表。无法回退到未限定搜索注册表的默认列表。

containerRuntimeSearchRegistries参数仅适用于 Podman 和 CRI-O 容器引擎。列表中的注册表只能在 Pod 规范中使用,不能在构建和镜像流中使用。

步骤
  • 编辑image.config.openshift.io/cluster自定义资源

    $ oc edit image.config.openshift.io/cluster

    以下是一个示例image.config.openshift.io/cluster CR

    apiVersion: config.openshift.io/v1
    kind: Image
    metadata:
      annotations:
        release.openshift.io/create-only: "true"
      creationTimestamp: "2019-05-17T13:44:26Z"
      generation: 1
      name: cluster
      resourceVersion: "8302"
      selfLink: /apis/config.openshift.io/v1/images/cluster
      uid: e34555da-78a9-11e9-b92b-06d6c7da38dc
    spec:
      allowedRegistriesForImport:
        - domainName: quay.io
          insecure: false
      additionalTrustedCA:
        name: myconfigmap
      registrySources:
        containerRuntimeSearchRegistries: (1)
        - reg1.io
        - reg2.io
        - reg3.io
        allowedRegistries: (2)
        - example.com
        - quay.io
        - registry.redhat.io
        - reg1.io
        - reg2.io
        - reg3.io
        - image-registry.openshift-image-registry.svc:5000
    ...
    status:
      internalRegistryHostname: image-registry.openshift-image-registry.svc:5000
    1 指定要与镜像简短名称一起使用的注册表。您应该只对内部或私有注册表使用镜像简短名称,以降低可能的安全风险。
    2 确保containerRuntimeSearchRegistries下列出的任何注册表都包含在allowedRegistries列表中。

    如果定义了allowedRegistries参数,则所有注册表(包括registry.redhat.ioquay.io注册表以及默认的OpenShift镜像注册表)都会被阻止,除非明确列出。如果您使用此参数,为了防止Pod失败,请将所有注册表(包括registry.redhat.ioquay.io注册表以及internalRegistryHostname)添加到allowedRegistries列表中,因为它们是环境中有效负载镜像所需的。对于断开连接的集群,还应添加镜像注册表。

配置用于镜像注册表访问的其他信任存储

image.config.openshift.io/cluster自定义资源可以包含对包含其他证书颁发机构的配置映射的引用,这些证书颁发机构在镜像注册表访问期间应受信任。

先决条件
  • 证书颁发机构 (CA) 必须是 PEM 编码的。

步骤

您可以在openshift-config命名空间中创建配置映射,并在image.config.openshift.io自定义资源中的AdditionalTrustedCA中使用其名称来提供联系外部注册表时应受信任的其他 CA。

配置映射键是具有端口的注册表的 hostname,为此 CA 应受信任,并且 PEM 证书内容是每个其他注册表 CA 的值。

镜像注册表 CA 配置映射示例
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-registry-ca
data:
  registry.example.com: |
    -----BEGIN CERTIFICATE-----
    ...
    -----END CERTIFICATE-----
  registry-with-port.example.com..5000: | (1)
    -----BEGIN CERTIFICATE-----
    ...
    -----END CERTIFICATE-----
1 如果注册表具有端口,例如registry-with-port.example.com:5000,则应将:替换为..

您可以按照以下步骤配置其他 CA。

  • 配置其他 CA

    $ oc create configmap registry-config --from-file=<external_registry_address>=ca.crt -n openshift-config
    $ oc edit image.config.openshift.io cluster
    spec:
      additionalTrustedCA:
        name: registry-config

了解镜像注册表仓库镜像

设置容器注册表仓库镜像使您可以执行以下任务

  • 配置您的 AWS 上的 Red Hat OpenShift Service 集群,以重定向请求以从源镜像注册表上的仓库拉取镜像,并使其由镜像镜像注册表上的仓库解析。

  • 为每个目标仓库标识多个镜像仓库,以确保如果一个镜像不可用,则可以使用另一个镜像。

AWS 上的 Red Hat OpenShift Service 中的仓库镜像包括以下属性

  • 镜像拉取能够应对注册表宕机。

  • 断开连接的环境中的集群可以从关键位置(例如 quay.io)拉取镜像,并且公司防火墙后面的注册表可以提供请求的镜像。

  • 发出镜像拉取请求时,会尝试特定顺序的注册表,永久注册表通常是最后尝试的一个。

  • 您输入的镜像信息将添加到 AWS 上的 Red Hat OpenShift Service 集群中每个节点上的/etc/containers/registries.conf文件中。

  • 当节点向源仓库请求镜像时,它会依次尝试每个镜像仓库,直到找到请求的内容。如果所有镜像都失败,集群会尝试源仓库。如果成功,则将镜像拉取到节点。

设置仓库镜像可以通过以下方式完成

  • 在 AWS 上的 Red Hat OpenShift Service 安装期间

    通过拉取 AWS 上的 Red Hat OpenShift Service 所需的容器镜像,然后将这些镜像置于公司防火墙之后,您可以将 AWS 上的 Red Hat OpenShift Service 安装到断开连接的环境中的数据中心。

  • 在 AWS 上的 Red Hat OpenShift Service 安装之后

    如果您在 AWS 上的 Red Hat OpenShift Service 安装期间未配置镜像,则可以在安装后使用以下任何自定义资源 (CR) 对象来进行配置

    • ImageDigestMirrorSet (IDMS)。此对象允许您通过使用摘要规范从镜像注册表拉取镜像。IDMS CR 使您可以设置回退策略,如果镜像拉取失败,则允许或停止继续尝试从源注册表拉取。

    • ImageTagMirrorSet (ITMS):此对象允许您使用镜像标签从镜像注册表拉取镜像。ITMS CR 使您可以设置回退策略,如果镜像拉取失败,则允许或停止继续尝试从源注册表拉取。

    • ImageContentSourcePolicy (ICSP):此对象允许您使用摘要规范从镜像注册表拉取镜像。如果镜像不起作用,ICSP CR 将始终回退到源注册表。

    使用ImageContentSourcePolicy (ICSP) 对象配置镜像存储库是一个已弃用的功能。已弃用的功能仍然包含在 Red Hat OpenShift Service on AWS 中,并继续受到支持;但是,它将在该产品的未来版本中删除,不建议用于新的部署。如果您有用于创建ImageContentSourcePolicy对象的现有 YAML 文件,可以使用oc adm migrate icsp命令将其转换为ImageDigestMirrorSet YAML 文件。有关更多信息,请参阅以下部分中的“转换用于镜像注册表存储库镜像的 ImageContentSourcePolicy (ICSP) 文件”。

每个自定义资源对象都标识以下信息:

  • 您要镜像的容器镜像存储库的源。

  • 您要为从源存储库请求的内容提供的每个镜像存储库的单独条目。

对于新的集群,您可以根据需要使用 IDMS、ITMS 和 ICSP CR 对象。但是,建议使用 IDMS 和 ITMS。

如果您升级了集群,任何现有的 ICSP 对象都保持稳定,并且支持 IDMS 和 ICSP 对象。使用 ICSP 对象的工作负载将继续按预期运行。但是,如果您想利用 IDMS CR 中引入的回退策略,您可以使用oc adm migrate icsp命令将当前工作负载迁移到 IDMS 对象,如后面的转换用于镜像注册表存储库镜像的 ImageContentSourcePolicy (ICSP) 文件部分所示。迁移到 IDMS 对象不需要重新启动集群。

如果您的集群使用ImageDigestMirrorSetImageTagMirrorSetImageContentSourcePolicy对象配置存储库镜像,则只能对镜像注册表使用全局拉取密钥。您无法向项目添加拉取密钥。

配置镜像注册表存储库镜像

您可以创建安装后镜像配置自定义资源 (CR) 以将镜像拉取请求从源镜像注册表重定向到镜像镜像注册表。

先决条件
  • 作为具有dedicated-admin角色的用户访问集群。

步骤
  1. 配置镜像存储库,方法如下:

    • 使用 Red Hat Quay 设置镜像存储库,如Red Hat Quay 存储库镜像中所述。使用 Red Hat Quay 允许您将镜像从一个存储库复制到另一个存储库,并随着时间的推移自动重复同步这些存储库。

    • 使用skopeo等工具手动将镜像从源存储库复制到镜像存储库。

      例如,在 Red Hat Enterprise Linux (RHEL) 7 或 RHEL 8 系统上安装 skopeo RPM 软件包后,请使用以下示例中所示的skopeo命令:

      $ skopeo copy --all \
      docker://registry.access.redhat.com/ubi9/ubi-minimal:latest@sha256:5cf... \
      docker://example.io/example/ubi-minimal

      在此示例中,您有一个名为example.io的容器镜像注册表,其中有一个名为example的镜像存储库,您要将ubi9/ubi-minimal镜像从registry.access.redhat.com复制到该存储库。创建镜像注册表后,您可以配置您的 Red Hat OpenShift Service on AWS 集群以将对源存储库的请求重定向到镜像存储库。

  2. 使用以下示例之一创建安装后镜像配置 CR:

    • 根据需要创建ImageDigestMirrorSetImageTagMirrorSet CR,将源和镜像替换为您自己的注册表和存储库对以及镜像。

      apiVersion: config.openshift.io/v1 (1)
      kind: ImageDigestMirrorSet (2)
      metadata:
        name: ubi9repo
      spec:
        imageDigestMirrors: (3)
        - mirrors:
          - example.io/example/ubi-minimal (4)
          - example.com/example/ubi-minimal (5)
          source: registry.access.redhat.com/ubi9/ubi-minimal (6)
          mirrorSourcePolicy: AllowContactingSource (7)
        - mirrors:
          - mirror.example.com/redhat
          source: registry.example.com/redhat (8)
          mirrorSourcePolicy: AllowContactingSource
        - mirrors:
          - mirror.example.com
          source: registry.example.com (9)
          mirrorSourcePolicy: AllowContactingSource
        - mirrors:
          - mirror.example.net/image
          source: registry.example.com/example/myimage (10)
          mirrorSourcePolicy: AllowContactingSource
        - mirrors:
          - mirror.example.net
          source: registry.example.com/example (11)
          mirrorSourcePolicy: AllowContactingSource
        - mirrors:
          - mirror.example.net/registry-example-com
          source: registry.example.com (12)
          mirrorSourcePolicy: AllowContactingSource
      1 指示要与此 CR 一起使用的 API。这必须是config.openshift.io/v1
      2 根据拉取类型指示对象的类型。
      • ImageDigestMirrorSet:拉取摘要引用镜像。

      • ImageTagMirrorSet:拉取标签引用镜像。

      3 指示镜像拉取方法的类型:
      • imageDigestMirrors:用于ImageDigestMirrorSet CR。

      • imageTagMirrors:用于ImageTagMirrorSet CR。

      4 指示镜像镜像注册表和存储库的名称。
      5 可选:为每个目标存储库指示辅助镜像存储库。如果一个镜像关闭,目标存储库可以使用辅助镜像。
      6 指示注册表和存储库源,即镜像拉取规范中引用的存储库。
      7 可选:如果镜像拉取失败,则指示回退策略。
      • AllowContactingSource:允许继续尝试从源存储库拉取镜像。这是默认设置。

      • NeverContactSource:阻止继续尝试从源存储库拉取镜像。

      8 可选:指示注册表内的命名空间,允许您使用该命名空间中的任何镜像。如果您使用注册表域作为源,则该对象将应用于该注册表中的所有存储库。
      9 可选:指示注册表,允许您使用该注册表中的任何镜像。如果您指定注册表名称,则该对象将应用于从源注册表到镜像注册表的所有存储库。
      10 从镜像mirror.example.net/image@sha256:..拉取镜像registry.example.com/example/myimage@sha256:…​
      11 从镜像mirror.example.net/image@sha256:…​拉取源注册表命名空间中的镜像registry.example.com/example/image@sha256:…​
      12 从镜像注册表example.net/registry-example-com/myimage@sha256:…​拉取镜像registry.example.com/myimage@sha256
    • 创建一个ImageContentSourcePolicy自定义资源,将源和镜像替换为您自己的注册表和存储库对以及镜像。

      apiVersion: operator.openshift.io/v1alpha1
      kind: ImageContentSourcePolicy
      metadata:
        name: mirror-ocp
      spec:
        repositoryDigestMirrors:
        - mirrors:
          - mirror.registry.com:443/ocp/release (1)
          source: quay.io/openshift-release-dev/ocp-release (2)
        - mirrors:
          - mirror.registry.com:443/ocp/release
          source: quay.io/openshift-release-dev/ocp-v4.0-art-dev
      1 指定镜像镜像注册表和存储库的名称。
      2 指定包含镜像内容的联机注册表和存储库。
  3. 创建新对象。

    $ oc create -f registryrepomirror.yaml

    创建对象后,机器配置操作员 (MCO) 仅会为ImageTagMirrorSet对象排空节点。MCO不会为ImageDigestMirrorSetImageContentSourcePolicy对象排空节点。

  4. 要检查是否应用了镜像配置设置,请在一个节点上执行以下操作。

    1. 列出您的节点。

      $ oc get node
      示例输出
      NAME                           STATUS                     ROLES    AGE  VERSION
      ip-10-0-137-44.ec2.internal    Ready                      worker   7m   v1.30.3
      ip-10-0-138-148.ec2.internal   Ready                      master   11m  v1.30.3
      ip-10-0-139-122.ec2.internal   Ready                      master   11m  v1.30.3
      ip-10-0-147-35.ec2.internal    Ready                      worker   7m   v1.30.3
      ip-10-0-153-12.ec2.internal    Ready                      worker   7m   v1.30.3
      ip-10-0-154-10.ec2.internal    Ready                      master   11m  v1.30.3
    2. 启动调试过程以访问节点。

      $ oc debug node/ip-10-0-147-35.ec2.internal
      示例输出
      Starting pod/ip-10-0-147-35ec2internal-debug ...
      To use host binaries, run `chroot /host`
    3. 将根目录更改为/host

      sh-4.2# chroot /host
    4. 检查/etc/containers/registries.conf文件,以确保进行了更改。

      sh-4.2# cat /etc/containers/registries.conf

      以下输出表示应用了安装后镜像配置 CR 的registries.conf文件。最后两个条目分别标记为digest-onlytag-only

      示例输出
      unqualified-search-registries = ["registry.access.redhat.com", "docker.io"]
      short-name-mode = ""
      
      [[registry]]
        prefix = ""
        location = "registry.access.redhat.com/ubi9/ubi-minimal" (1)
      
        [[registry.mirror]]
          location = "example.io/example/ubi-minimal" (2)
          pull-from-mirror = "digest-only" (3)
      
        [[registry.mirror]]
          location = "example.com/example/ubi-minimal"
          pull-from-mirror = "digest-only"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com"
      
        [[registry.mirror]]
          location = "mirror.example.net/registry-example-com"
          pull-from-mirror = "digest-only"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com/example"
      
        [[registry.mirror]]
          location = "mirror.example.net"
          pull-from-mirror = "digest-only"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com/example/myimage"
      
        [[registry.mirror]]
          location = "mirror.example.net/image"
          pull-from-mirror = "digest-only"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com"
      
        [[registry.mirror]]
          location = "mirror.example.com"
          pull-from-mirror = "digest-only"
      
      [[registry]]
        prefix = ""
        location = "registry.example.com/redhat"
      
        [[registry.mirror]]
          location = "mirror.example.com/redhat"
          pull-from-mirror = "digest-only"
      [[registry]]
        prefix = ""
        location = "registry.access.redhat.com/ubi9/ubi-minimal"
        blocked = true (4)
      
        [[registry.mirror]]
          location = "example.io/example/ubi-minimal-tag"
          pull-from-mirror = "tag-only" (5)
      
      1 指示在拉取规范中引用的存储库。
      2 指示该存储库的镜像。
      3 指示从镜像拉取镜像是摘要引用镜像。
      4 指示为此存储库设置了NeverContactSource参数。
      5 指示从镜像拉取镜像是标签引用镜像。
    5. 将镜像从源拉取到节点,并检查镜像是否已解析。

      sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi9/ubi-minimal@sha256:5cf...
存储库镜像故障排除

如果存储库镜像过程无法按描述工作,请使用以下关于存储库镜像工作方式的信息来帮助排除问题。

  • 第一个可用的镜像用于提供拉取的镜像。

  • 只有在其他镜像源都失效的情况下,才会使用主注册表。

  • 从系统上下文中,Insecure标志用作回退。

  • /etc/containers/registries.conf 文件的格式最近已更改。它现在是版本 2,采用 TOML 格式。

转换镜像注册表镜像的 ImageContentSourcePolicy (ICSP) 文件

使用ImageContentSourcePolicy (ICSP) 对象配置镜像仓库镜像是一个已弃用的功能。此功能仍在 Red Hat OpenShift Service on AWS 中包含并继续受支持;但是,它将在该产品的未来版本中删除,不建议在新的部署中使用。

ICSP 对象正在被ImageDigestMirrorSetImageTagMirrorSet 对象替换以配置镜像仓库镜像。如果您有用于创建ImageContentSourcePolicy 对象的现有 YAML 文件,则可以使用oc adm migrate icsp 命令将这些文件转换为ImageDigestMirrorSet YAML 文件。该命令将 API 更新到当前版本,将kind 值更改为ImageDigestMirrorSet,并将spec.repositoryDigestMirrors 更改为spec.imageDigestMirrors。文件的其余部分保持不变。

由于迁移不会更改registries.conf 文件,因此集群不需要重启。

有关ImageDigestMirrorSetImageTagMirrorSet 对象的更多信息,请参见上一节中的“配置镜像注册表镜像仓库”。

先决条件
  • 作为具有dedicated-admin角色的用户访问集群。

  • 确保您的集群上具有ImageContentSourcePolicy 对象。

步骤
  1. 使用以下命令将一个或多个ImageContentSourcePolicy YAML 文件转换为ImageDigestMirrorSet YAML 文件

    $ oc adm migrate icsp <file_name>.yaml <file_name>.yaml <file_name>.yaml --dest-dir <path_to_the_directory>

    其中

    <file_name>

    指定源ImageContentSourcePolicy YAML 的名称。您可以列出多个文件名。

    --dest-dir

    可选:指定输出ImageDigestMirrorSet YAML 的目录。如果未设置,则文件将写入当前目录。

    例如,以下命令转换icsp.yamlicsp-2.yaml 文件并将新的 YAML 文件保存到idms-files 目录。

    $ oc adm migrate icsp icsp.yaml icsp-2.yaml --dest-dir idms-files
    示例输出
    wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi8repo.5911620242173376087.yaml
    wrote ImageDigestMirrorSet to idms-files/imagedigestmirrorset_ubi9repo.6456931852378115011.yaml
  2. 运行以下命令创建 CR 对象

    $ oc create -f <path_to_the_directory>/<file-name>.yaml

    其中

    <path_to_the_directory>

    如果您使用了--dest-dir 标志,则指定目录的路径。

    <file_name>

    指定ImageDigestMirrorSet YAML 的名称。

  3. 在 IDMS 对象推出后删除 ICSP 对象。