9.2. 配置镜像 registry 设置
您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)来配置镜像 registry 设置。当对 registry 的更改应用到 image.config.openshift.io/cluster CR 时,Machine Config Operator (MCO) 执行以下顺序操作:
- 对节点进行 cordon 操作
- 通过重启 CRI-O 应用更改
取消记录节点
注意MCO 在检测到更改时不会重启节点。
流程
编辑
image.config.openshift.io/cluster自定义资源:$ oc edit image.config.openshift.io/cluster
以下是
image.config.openshift.io/clusterCR 示例: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:限制普通用户可从中导入镜像的容器镜像 registry。将此列表设置为您信任包含有效镜像且希望应用程序能够从中导入的 registry。有权从 API 创建镜像或ImageStreamMappings的用户不受此策略的影响。通常只有集群管理员具有适当权限。- 3
additionalTrustedCA:引用包含镜像流导入、Pod 镜像拉取、openshift-image-registrypullthrough 和构建期间受信任的额外证书颁发机构(CA)的配置映射。此配置映射的命名空间为openshift-config。ConfigMap 的格式是使用 registry 主机名作为键,使用 PEM 证书作为值,用于每个要信任的额外 registry CA。- 4
registrySources:包含用于决定容器运行时在访问构建和 pod 的镜像时是否允许或阻止个别 registry 的配置。可以设置allowedRegistries参数或blockedRegistries参数,但不能同时设置这两个参数。您还可以定义是否允许访问允许使用镜像短名称的不安全的 registry。本例使用allowedRegistries参数,该参数定义允许使用的 registry。不安全 registryinsecure.com也被允许。registrySources参数不包含内部集群 registry 的配置。
注意当定义
allowedRegistries参数时,除非明确列出,否则所有 registry (包括 registry.redhat.io 和 quay.io registry 和默认的 OpenShift 镜像 registry)都会被阻断。如果使用参数,为了避免 pod 失败,您必须将registry.redhat.io和quay.ioregistry 以及internalRegistryHostname添加到allowedRegistries列表中,因为环境中有效负载镜像需要它们。不要将registry.redhat.io和quay.ioregistry 添加到blockedRegistries列表中。使用
allowedRegistries、blockedRegistries或insecureRegistries参数时,您可以在 registry 中指定单独的存储库。例如:reg1.io/myrepo/myapp:latest。应避免使用不安全的外部 registry,以减少可能的安全性风险。
要检查是否应用了更改,请列出您的节点:
$ oc get nodes
输出示例
NAME STATUS ROLES AGE VERSION ip-10-0-137-182.us-east-2.compute.internal Ready,SchedulingDisabled worker 65m v1.26.0 ip-10-0-139-120.us-east-2.compute.internal Ready,SchedulingDisabled control-plane 74m v1.26.0 ip-10-0-176-102.us-east-2.compute.internal Ready control-plane 75m v1.26.0 ip-10-0-188-96.us-east-2.compute.internal Ready worker 65m v1.26.0 ip-10-0-200-59.us-east-2.compute.internal Ready worker 63m v1.26.0 ip-10-0-223-123.us-east-2.compute.internal Ready control-plane 73m v1.26.0
9.2.1. 添加特定的 registry
您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)在 registry 中添加允许进行镜像拉取(pull)和推送(push)操作的 registry 列表(可选)。OpenShift Container Platform 会将对此 CR 的更改应用到集群中的所有节点。
在拉取或推送镜像时,容器运行时会搜索 image.config.openshift.io/cluster CR 的 registrySources 参数中列出的 registry。如果您在 allowedRegistries 参数下创建了 registry 列表,则容器运行时仅搜索这些 registry。不在列表中的 registry 会被阻断。
当定义 allowedRegistries 参数时,除非明确列出,否则所有 registry (包括 registry.redhat.io 和 quay.io registry 和默认的 OpenShift 镜像 registry)都会被阻断。如果使用参数,为了避免 pod 失败,您必须将 registry.redhat.io 和 quay.io registry 以及 internalRegistryHostname 添加到 allowedRegistries 列表中,因为环境中有效负载镜像需要它们。对于断开连接的集群,还应添加镜像的 registry。
流程
编辑
image.config.openshift.io/clusterCR:$ oc edit image.config.openshift.io/cluster
以下是一个带有允许列表的
image.config.openshift.io/clusterCR 示例: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注意可以设置
allowedRegistries参数或blockedRegistries参数,但不能同时设置这两个参数。Machine Config Operator(MCO)会监控
image.config.openshift.io/cluster资源以了解对 registry 的任何更改。当 MCO 检测到更改时,它会排空节点,应用更改,并对节点进行 uncordon 处理。节点返回Ready状态后,允许的 registry 列表用于更新每个节点上的/host/etc/containers/policy.json文件中的镜像签名策略。要检查 registry 是否已添加到策略文件中,请在节点上使用以下命令:
$ cat /host/etc/containers/policy.json
以下策略表示,仅允许来自 example.com、quay.io 和 registry.redhat.io registry 中的镜像拉取和推送镜像:
例 9.1. 镜像签名策略文件示例
{ "default":[ { "type":"reject" } ], "transports":{ "atomic":{ "example.com":[ { "type":"insecureAcceptAnything" } ], "image-registry.openshift-image-registry.svc:5000":[ { "type":"insecureAcceptAnything" } ], "insecure.com":[ { "type":"insecureAcceptAnything" } ], "quay.io":[ { "type":"insecureAcceptAnything" } ], "reg4.io/myrepo/myapp:latest":[ { "type":"insecureAcceptAnything" } ], "registry.redhat.io":[ { "type":"insecureAcceptAnything" } ] }, "docker":{ "example.com":[ { "type":"insecureAcceptAnything" } ], "image-registry.openshift-image-registry.svc:5000":[ { "type":"insecureAcceptAnything" } ], "insecure.com":[ { "type":"insecureAcceptAnything" } ], "quay.io":[ { "type":"insecureAcceptAnything" } ], "reg4.io/myrepo/myapp:latest":[ { "type":"insecureAcceptAnything" } ], "registry.redhat.io":[ { "type":"insecureAcceptAnything" } ] }, "docker-daemon":{ "":[ { "type":"insecureAcceptAnything" } ] } } }
如果您的集群使用 registrySources.insecureRegistries 参数,请确保将任何不安全的 registry 包含在允许的列表中。
例如:
spec:
registrySources:
insecureRegistries:
- insecure.com
allowedRegistries:
- example.com
- quay.io
- registry.redhat.io
- insecure.com
- image-registry.openshift-image-registry.svc:50009.2.2. 阻塞特定的 registry
您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)来阻止任何 registry 以及 registry 中的单独存储库。OpenShift Container Platform 会将对此 CR 的更改应用到集群中的所有节点。
在拉取或推送镜像时,容器运行时会搜索 image.config.openshift.io/cluster CR 的 registrySources 参数中列出的 registry。如果您在 blockedRegistries 参数下创建了 registry 列表,则容器运行时不会搜索这些 registry。允许所有其他 registry。
为防止 pod 失败,请不要将 registry.redhat.io 和 quay.io registry 添加到 blockedRegistries 列表中,因为环境中有效负载镜像需要它们。
流程
编辑
image.config.openshift.io/clusterCR:$ oc edit image.config.openshift.io/cluster
以下是一个带有块列表的
image.config.openshift.io/clusterCR 示例: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注意可以设置
blockedRegistriesregistry 或allowedRegistriesregistry,但不能同时设置这两个 registry。Machine Config Operator(MCO)会监控
image.config.openshift.io/cluster资源以了解对 registry 的任何更改。当 MCO 检测到更改时,它会排空节点,应用更改,并对节点进行 uncordon 处理。节点返回Ready状态后,在每个节点上的/etc/containers/registries.conf文件中会显示对被阻断的 registry 的更改。要检查 registry 是否已添加到策略文件中,请在节点上使用以下命令:
$ cat /host/etc/containers/registries.conf
以下示例显示,在进行镜像拉取和推送时,不使用
untrusted.com:输出示例
unqualified-search-registries = ["registry.access.redhat.com", "docker.io"] [[registry]] prefix = "" location = "untrusted.com" blocked = true
9.2.2.1. 阻塞一个 payload registry
在镜像配置中,您可以使用 ImageContentSourcePolicy (ICSP) 对象在断开连接的环境中阻断上游 payload registry。以下示例步骤演示了如何阻止 quay.io/openshift-payload payload registry。
流程
使用
ImageContentSourcePolicy(ICSP) 对象创建镜像配置,以便将 payload 镜像到您的实例中 registry。以下示例 ICSP 文件对 payloadinternal-mirror.io/openshift-payload进行了镜像:apiVersion: operator.openshift.io/v1alpha1 kind: ImageContentSourcePolicy metadata: name: my-icsp spec: repositoryDigestMirrors: - mirrors: - internal-mirror.io/openshift-payload source: quay.io/openshift-payload对象部署到节点上后,通过检查
/etc/containers/registries.conf文件来验证镜像配置是否已设置:输出示例
[[registry]] prefix = "" location = "quay.io/openshift-payload" mirror-by-digest-only = true [[registry.mirror]] location = "internal-mirror.io/openshift-payload"
使用以下命令来编辑
image.config.openshift.io自定义资源文件:$ oc edit image.config.openshift.io cluster
要阻断 payload registry,请在
image.config.openshift.io自定义资源文件中添加以下配置:spec: registrySource: blockedRegistries: - quay.io/openshift-payload
验证
通过检查节点上的
/etc/containers/registries.conf文件,验证上游 payload registry 是否被阻止。输出示例
[[registry]] prefix = "" location = "quay.io/openshift-payload" blocked = true mirror-by-digest-only = true [[registry.mirror]] location = "internal-mirror.io/openshift-payload"
9.2.3. 允许不安全的 registry
您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)来添加不安全的 registry 及 registry 中的特定存储库(可选)。OpenShift Container Platform 会将对此 CR 的更改应用到集群中的所有节点。
没有使用有效 SSL 证书或不需要 HTTPS 连接的 registry 被视为是不安全的 registry。
应避免使用不安全的外部 registry,以减少可能的安全性风险。
流程
编辑
image.config.openshift.io/clusterCR:$ oc edit image.config.openshift.io/cluster
以下是一个带有不安全 registry 列表的
image.config.openshift.io/clusterCR 示例: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注意当定义
allowedRegistries参数时,除非明确列出,否则所有 registry (包括 registry.redhat.io 和 quay.io registry 和默认的 OpenShift 镜像 registry)都会被阻断。如果使用参数,为了避免 pod 失败,将所有 registry(包括registry.redhat.io和quay.ioregistry)和internalRegistryHostname添加到allowedRegistries列表中,因为环境中有效负载镜像需要它们。对于断开连接的集群,还应添加镜像的 registry。Machine Config Operator(MCO)会监控
image.config.openshift.io/clusterCR 是否有对 registry 的更改,然后在检测到更改时排空并取消记录节点。节点返回Ready状态后,改为在每个节点的/etc/containers/registries.conf文件中列出的不安全和受阻 registry。要检查 registry 是否已添加到策略文件中,请在节点上使用以下命令:
$ cat /host/etc/containers/registries.conf
以下示例表示来自
insecure.comregistry 的镜像是不安全的,并允许进行镜像拉取和推送。输出示例
unqualified-search-registries = ["registry.access.redhat.com", "docker.io"] [[registry]] prefix = "" location = "insecure.com" insecure = true
9.2.4. 添加允许镜像短名称的 registry
您可以通过编辑 image.config.openshift.io/cluster 自定义资源(CR)来添加 registry 来搜索镜像短名称。OpenShift Container Platform 会将对此 CR 的更改应用到集群中的所有节点。
镜像简短名称允许您搜索镜像,而无需在 pull spec 中包含完全限定域名。例如: 您可以使用 rhel7/etcd 而不是 registry.access.redhat.com/rhe7/etcd。
在无法使用完整路径的情况下,您可以使用简短名称。例如,如果您的集群引用了 DNS 频繁变化的多个内部 registry,则需要更新 pull spec 中的完全限定域名并进行每次更改。在这种情况下,使用镜像简短名称可能很有用。
在拉取或推送镜像时,容器运行时会搜索 image.config.openshift.io/cluster CR 的 registrySources 参数中列出的 registry。如果您在 containerRuntimeSearchRegistries 参数下创建了 registry 列表,则容器运行时会搜索这些 registry。
强烈建议不要将镜像短名称与公共 registry 搭配使用,因为如果公共 registry 需要身份验证,则镜像可能无法部署。将完全限定镜像名称与公共 registry 搭配使用。
红帽内部或私有 registry 通常支持使用镜像短名称。
如果您在 containerRuntimeSearchRegistries 参数下列出公共 registry,您的凭证会暴露在列表中的所有 registry 中,从而会使网络和 registry 受到攻击。
如果每个公共 registry 需要不同的凭证,且集群不会在全局 pull secret 中列出公共 registry,则无法在 containerRuntimeSearchRegistries 参数下列出多个公共 registry。
对于需要身份验证的公共 registry,只有在 registry 具有其凭证存储在全局 pull secret 中时,才能使用镜像短名称。
Machine Config Operator(MCO)会监控 image.config.openshift.io/cluster 资源以了解对 registry 的任何更改。当 MCO 检测到更改时,它会排空节点,应用更改,并对节点进行 uncordon 处理。节点返回 Ready 状态后,如果添加了 containerRuntimeSearchRegistries 参数,MCO 会在每个带有列出 registry 的节点的 /etc/containers/registries.conf.d 目录中创建一个文件。该文件覆盖 /host/etc/containers/registries.conf 文件中的非全限定搜索 registry 的默认列表。没有办法回退到非全限定搜索 registry 的默认列表。
containerRuntimeSearchRegistries 参数只适用于 Podman 和 CRI-O 容器引擎。列表中的 registry 只能用于 pod 规格,不能用于构建和镜像流。
流程
编辑
image.config.openshift.io/cluster自定义资源:$ oc edit image.config.openshift.io/cluster
以下是
image.config.openshift.io/clusterCR 示例: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注意当定义
allowedRegistries参数时,除非明确列出,否则所有 registry (包括registry.redhat.io和quay.ioregistry 和默认的 OpenShift 镜像 registry)都会被阻断。如果使用此参数,为了避免 pod 失败,请将所有 registry(包括registry.redhat.io和quay.ioregistry)和internalRegistryHostname添加到allowedRegistries列表中,因为环境中有效负载镜像需要它们。对于断开连接的集群,还应添加镜像的 registry。要检查是否已添加 registry,当节点返回到
Ready状态时,请在节点上使用以下命令:$ cat /host/etc/containers/registries.conf.d/01-image-searchRegistries.conf
输出示例
unqualified-search-registries = ['reg1.io', 'reg2.io', 'reg3.io']
9.2.5. 为镜像 registry 访问配置额外的信任存储
Image.config.openshift.io/cluster 自定资源可包含对配置映射的引用,该配置映射包含要在镜像 registry 访问期间被信任的额外证书颁发机构。
先决条件
- 证书颁发机构(CA)必须经过 PEM 编码。
流程
您可以在openshift-config命名空间中创建配置映射,并在 image.config.openshift.io 子定义资源中的 AdditionalTrustedCA 中使用其名称,以提供与外部 registry 联系时可以被信任的额外CA。
对于每个要信任的额外 registry CA,配置映射键是带有要信任此 CA 的端口的 registry 的主机名,而 PEM 证书内容是要信任的每个额外 registry CA。
镜像 registry 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 带有端口,如
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
9.2.6. 配置镜像 registry 存储库镜像
通过设置容器 registry 存储库镜像,您可以执行以下任务:
- 配置 OpenShift Container Platform 集群,以便重定向从源镜像 registry 上的存储库拉取(pull)镜像的请求,并通过已镜像 (mirror) 的镜像 registry 上的存储库来解决该请求。
- 为每个目标存储库识别多个已镜像 (mirror)的存储库,以确保如果一个镜像停止运作,仍可使用其他镜像。
OpenShift Container Platform 中的存储库镜像包括以下属性:
- 镜像拉取(pull)可应对 registry 停机的问题。
- 在断开连接的环境中的集群可以从关键位置(如 quay.io)拉取镜像,并让公司防火墙后面的 registry 提供请求的镜像。
- 发出镜像拉取(pull)请求时尝试特定 registry 顺序,通常最后才会尝试持久性 registry。
-
您所输入的镜像信息会添加到 OpenShift Container Platform 集群中每个节点上的
/etc/containers/registries.conf文件中。 - 当节点从源存储库中请求镜像时,它会依次尝试每个已镜像的存储库,直到找到所请求的内容。如果所有镜像均失败,集群则会尝试源存储库。如果成功,则镜像拉取至节点中。
可通过以下方式设置存储库镜像:
在 OpenShift Container Platform 安装中:
通过拉取(pull) OpenShift Container Platform 所需的容器镜像,然后将这些镜像放至公司防火墙后,即可将 OpenShift Container Platform 安装到受限网络中的数据中心。
安装 OpenShift Container Platform 后:
如果您没有在 OpenShift Container Platform 安装过程中配置镜像,您可以在安装后使用以下自定义资源 (CR) 对象之一:
-
ImageDigestMirrorSet.此 CR 允许您使用摘要规格从镜像 registry 中拉取镜像。 -
ImageTagMirrorSet.此 CR 允许您使用镜像标签从已镜像的 registry 中拉取镜像。
重要使用
ImageContentSourcePolicy(ICSP)对象配置存储库镜像是一个已弃用的功能。弃用的功能仍然包含在 OpenShift Container Platform 中,并将继续被支持。但是,这个功能会在以后的发行版本中被删除,且不建议在新的部署中使用。如果您有用于创建ImageContentSourcePolicy对象的 YAML 文件,您可以使用oc adm migrate icsp命令将这些文件转换为ImageDigestMirrorSetYAML 文件。如需更多信息,请参阅以下部分"协调 ImageContentSourcePolicy (ICSP)文件以进行镜像 registry 存储库镜像"。-
这两个自定义资源对象都标识以下信息:
- 您希望镜像 (mirror) 的容器镜像存储库的源。
- 您希望为其提供从源存储库请求的内容的每个镜像存储库的单独条目。
如果您的集群使用 ImageDigestMirrorSet 或 ImageTagMirrorSet 对象来配置存储库镜像,则只能将全局 pull secret 用于镜像 registry。您不能在项目中添加 pull secret。
以下流程创建安装后镜像配置,您可以在其中创建 ImageDigestMirrorSet 对象。
先决条件
-
确保可以使用具有
cluster-admin角色的用户访问集群。 确保集群中没有
ImageContentSourcePolicy对象。例如,您可以使用以下命令:$ oc get ImageContentSourcePolicy
输出示例
No resources found
流程
通过以下方法配置已镜像的存储库:
- 按照 Red Hat Quay 存储库镜像中所述,使用 Red Hat Quay 来设置已镜像的存储库。使用 Red Hat Quay 有助于您将镜像从一个存储库复制到另一存储库,并可随着时间的推移重复自动同步这些存储库。
使用
skopeo等工具手动将镜像从源目录复制到已镜像的存储库。例如:在 Red Hat Enterprise Linux(RHEL 7 或 RHEL 8)系统上安装 skopeo RPM 软件包后,使用
skopeo命令,如下例所示:$ skopeo copy \ docker://registry.access.redhat.com/ubi9/ubi-minimal:latest@sha256:5cf... \ docker://example.io/example/ubi-minimal
在本例中,您有一个名为
example.io的容器镜像 registry,其中包含一个名为example的镜像存储库,您要将ubi9/ubi-minimal镜像从registry.access.redhat.com复制到其中。创建该 registry 后,您可将 OpenShift Container Platform 集群配置为将源存储库的请求重定向到已镜像的存储库。
- 登录您的 OpenShift Container Platform 集群。
根据需要,创建一个
ImageDigestMirrorSet或ImageTagMirrorSetCR,将源和镜像(mirror)替换为您自己的 registry、存储库对和镜像: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.redhat.io/openshift4 8 mirrorSourcePolicy: AllowContactingSource - mirrors: - mirror.example.com source: registry.redhat.io 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
- 根据 pull 类型指示对象类型:
-
ImageDigestMirrorSet:提取摘要引用镜像。 -
ImageTagMirrorSet:提取标签引用镜像。
-
- 3
- 表示镜像拉取方法的类型,请执行以下任一方法:
-
imageDigestMirrors:用于ImageDigestMirrorSetCR。 -
imageTagMirrors:用于ImageTagMirrorSetCR。
-
- 4
- 指明镜像 registry 和存储库的名称。
- 5
- 可选:指定每个目标仓库的二级镜像存储库。如果一个镜像停机,则目标仓库可以使用另一个镜像。
- 6
- 指明 registry 和存储库源,这是在镜像拉取规格中引用的存储库。
- 7
- 可选:如果镜像拉取失败,则指示回退策略:
-
AllowContactingSource:允许继续尝试从源存储库拉取镜像。这是默认值。 -
NeverContactSource: 防止继续尝试从源存储库拉取镜像。
-
- 8
- 可选:指示 registry 中的命名空间,它允许您使用该命名空间中的任何镜像。如果您使用 registry 域作为源,则对象将应用到 registry 中的所有存储库。
- 9
- 可选:指示一个 registry,它允许您使用该 registry 中的任何镜像。如果指定了 registry 名称,对象将应用到源 registry 中的所有存储库到镜像 registry。
- 10
- 从 mirror
mirror.example.net/image@sha256:..拉取镜像registry.example.com/example/myimage@sha256:…。 - 11
- 从 mirror
mirror.example.net/image@sha256:…的源 registry 命名空间中拉取镜像registry.example.com/example/image@sha256:…。 - 12
- 从 mirror registry
example.net/registry-example-com/myimage@sha256:…中拉取镜像registry.example.com/myimage@sha256。ImageContentSourcePolicy资源会应用到源 registry 中的所有仓库到到 mirror registrymirror.example.net/registry-example-com。
创建新对象:
$ oc create -f registryrepomirror.yaml
创建对象后,Machine Config Operator (MCO) 会限制节点,因为新的设置被部署到每个节点。MCO 只为
ImageTagMirrorSet对象重启节点。MCO 不会为ImageDigestMirrorSet对象重启节点。当节点被取消封锁时,集群开始使用已镜像的存储库向源存储库发出请求。要检查是否应用了镜像的配置设置,请在其中一个节点上执行以下操作。
列出您的节点:
$ oc get node
输出示例
NAME STATUS ROLES AGE VERSION ip-10-0-137-44.ec2.internal Ready worker 7m v1.26.0 ip-10-0-138-148.ec2.internal Ready master 11m v1.26.0 ip-10-0-139-122.ec2.internal Ready master 11m v1.26.0 ip-10-0-147-35.ec2.internal Ready worker 7m v1.26.0 ip-10-0-153-12.ec2.internal Ready worker 7m v1.26.0 ip-10-0-154-10.ec2.internal Ready master 11m v1.26.0
启动调试过程以访问节点:
$ 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`
将您的根目录改为
/host:sh-4.2# chroot /host
检查
/etc/containers/registries.conf文件,确保已完成更改:sh-4.2# cat /etc/containers/registries.conf
以下输出代表了一个
registry.conf文件,其中应用了ImageDigestMirrorSet对象和一个ImageTagMirrorSet对象。最后的两个条目分别标记为digest-only和tag-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.redhat.io" [[registry.mirror]] location = "mirror.example.com" pull-from-mirror = "digest-only" [[registry]] prefix = "" location = "registry.redhat.io/openshift4" [[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
从源拉取镜像到节点,并检查是否通过 mirror 解析。
sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi9/ubi-minimal@sha256:5cf...
存储库镜像故障排除
如果存储库镜像流程未按规定工作,请使用以下有关存储库镜像如何工作的信息协助排查问题。
- 首个工作镜像用于提供拉取(pull)的镜像。
- 只有在无其他镜像工作时,才会使用主 registry。
-
从系统上下文,
Insecure标志用作回退。 -
最近更改了
/etc/containers/registries.conf文件的格式。现在它是第 2 版,采用 TOML 格式。 -
您不能将同一存储库添加到
ImageDigestMirrorSet和ImageTagMirrorSet对象中。
其他资源
- 如需有关全局 pull secret 的更多信息,请参阅更新全局集群 pull secret。
9.2.7. 为镜像 registry 存储库镜像转换 ImageContentSourcePolicy (ICSP) 文件
使用 ImageContentSourcePolicy (ICSP)对象配置存储库镜像是一个已弃用的功能。此功能仍然包含在 OpenShift Container Platform 中,并将继续被支持。但是,这个功能会在以后的发行版本中被删除,且不建议在新的部署中使用。
ICSP 对象被 ImageDigestMirrorSet 和 ImageTagMirrorSet 对象替代,以配置存储库镜像。如果您有用于创建 ImageContentSourcePolicy 对象的 YAML 文件,您可以使用 oc adm migrate icsp 命令将这些文件转换为 ImageDigestMirrorSet YAML 文件。命令将 API 更新至当前版本,将 kind 值更改为 ImageDigestMirrorSet,并将 spec.repositoryDigestMirrors 更改为 spec.imageDigestMirrors。文件的其余部分不会改变。
有关 ImageDigestMirrorSet 或 ImageTagMirrorSet 对象的更多信息,请参阅上一节中的"配置镜像 registry 存储库镜像"。
先决条件
-
确保可以使用具有
cluster-admin角色的用户访问集群。 -
确保集群中具有
ImageContentSourcePolicy对象。
流程
使用以下命令,将一个或多个
ImageContentSourcePolicyYAML 文件转换为ImageDigestMirrorSetYAML 文件:$ oc adm migrate icsp <file_name>.yaml <file_name>.yaml <file_name>.yaml --dest-dir <path_to_the_directory>
其中:
<file_name>-
指定源
ImageContentSourcePolicyYAML 的名称。您可以列出多个文件名。 --dest-dir-
可选:指定输出
ImageDigestMirrorSetYAML 的目录。如果未设置,则会将该文件写入当前目录中。
例如,以下命令可将
icsp.yaml和icsp-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
运行以下命令来创建 CR 对象:
$ oc create -f <path_to_the_directory>/<file-name>.yaml
其中:
<path_to_the_directory>-
如果使用
--dest-dir标志,请指定目录的路径。 <file_name>-
指定
ImageDigestMirrorSetYAML 的名称。