This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.7.2. 配置镜像设置
您可通过编辑 image.config.openshift.io/cluster 资源来配置镜像 registry 设置。Machine Config Operator (MCO) 会监控 image.config.openshift.io/cluster 以了解对 registry 的任何更改,并在检测到更改时重启节点。
流程
编辑
image.config.openshift.io/cluster自定义资源:oc edit image.config.openshift.io/cluster
$ oc edit image.config.openshift.io/clusterCopy to Clipboard Copied! Toggle word wrap Toggle overflow 以下是
image.config.openshift.io/cluster资源示例:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
Image:包含有关如何处理镜像的集群范围信息。规范且唯一有效的名称是cluster。- 2
allowedRegistriesForImport:限制普通用户可从中导入镜像的容器镜像 registry。将此列表设置为您信任包含有效镜像且希望应用程序能够从中导入的 registry。有权从 API 创建镜像或ImageStreamMappings的用户不受此策略的影响。通常只有集群管理员具有适当权限。- 3
additionalTrustedCA:引用包含ImageStream import、pod image pull、openshift-image-registry pullthrough和构建期间应受信任的额外 CA 的 ConfigMap。该 ConfigMap 的命名空间为openshift-config。ConfigMap 的格式是使用 registry 主机名作为键,使用 base64 编码证书作为值,用于每个要信任的额外 registry CA。- 4
registrySources:包含用于决定容器运行时在访问构建和 pod 的镜像时应如何处理个别 registry 的配置。例如,是否允许不安全的访问。它不包含内部集群 registry 的配置。- 5
insecureRegistries:无有效 TLS 证书或仅支持 HTTP 连接的 registry。- 6
blockedRegistries:列入镜像拉取(pull)和推送(push)操作黑名单。允许所有其他 registry。
7.2.1. 导入不安全的 registry 和阻止 registry 复制链接链接已复制到粘贴板!
您可通过编辑 image.config.openshift.io/cluster 自定义资源 (CR) 来添加不安全的 registry 或阻止任何 registry。OpenShift Container Platform 会将对此 CR 的更改应用到集群中的所有节点。
应避免不安全的外部 registry,如无有效 TLS 证书或仅支持 HTTP 连接的 registry。
流程
编辑
image.config.openshift.io/cluster自定义资源:oc edit image.config.openshift.io/cluster
$ oc edit image.config.openshift.io/clusterCopy to Clipboard Copied! Toggle word wrap Toggle overflow 以下是
image.config.openshift.io/cluster资源示例:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Machine Config Operator (MCO) 会监控
image.config.openshift.io/cluster以了解对 registry 的任何更改,并在检测到更改时重启节点。对 registry 的更改将出现在每个节点上的 /host/etc/containers/registries.conf 文件中。Copy to Clipboard Copied! Toggle word wrap Toggle overflow
7.2.2. 配置镜像 registry 存储库镜像 复制链接链接已复制到粘贴板!
通过设置容器 registry 存储库镜像,您可以:
- 配置 OpenShift Container Platform 集群,以便重定向从源镜像 registry 上的存储库拉取(pull)镜像的请求,并通过已镜像 (mirror) 的镜像 registry 上的存储库来解决该请求。
- 为每个目标存储库识别多个已镜像 (mirror)的存储库,以确保如果一个镜像停止运作,仍可使用其他镜像。
以下是 OpenShift Container Platform 中存储库镜像的一些属性:
- 镜像拉取(pull)可应对 registry 停机时间
- 受限网络中的集群可请求从关键位置(如 quay.io)拉取(pull)镜像,并让公司防火墙后的 registry 提供所请求的镜像。
- 发出镜像拉取(pull)请求时尝试特定 registry 顺序,通常最后才会尝试持久性 registry。
-
您所输入的镜像信息会添加到 OpenShift Container Platform 集群中每个节点上的
/etc/containers/registries.conf文件中。 - 当节点从源存储库中请求镜像时,它会依次尝试每个已镜像的存储库,直到找到所请求的内容。如果所有镜像均失败,集群则会尝试源存储库。如果成功,镜像则会被拉取(pull)至节点中。
可通过以下方式设置存储库镜像:
- 安装 OpenShift Container Platform 时:通过拉取(pull) OpenShift Container Platform 所需的容器镜像,然后将这些镜像放至公司防火墙后,即可将 OpenShift Container Platform 安装到受限网络中的数据中心。详情请参阅镜像 OpenShift Container Platform 的镜像存储库。
-
安装 OpenShift Container Platform 后:即使没有在 OpenShift Container Platform 安装期间配置镜像 (mirror),之后您仍可使用
ImageContentSourcePolicy对象进行配置。
以下流程提供安装后镜像配置,您可在此处创建 ImageContentSourcePolicy 对象来识别:
- 您希望镜像 (mirror) 的容器镜像存储库的源
- 您希望为其提供从源存储库请求的内容的每个镜像存储库的单独条目。
先决条件
-
使用具有
cluster-admin角色的用户访问集群。
流程
配置已镜像的存储库。为此,您可以:
- 按照 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/ubi8/ubi-minimal@sha256:c505667389712dc337986e29ffcb65116879ef27629dc3ce6e1b17727c06e78f \ docker://example.io/ubi8/ubi-minimal
$ skopeo copy \ docker://registry.access.redhat.com/ubi8/ubi-minimal@sha256:c505667389712dc337986e29ffcb65116879ef27629dc3ce6e1b17727c06e78f \ docker://example.io/ubi8/ubi-minimalCopy to Clipboard Copied! Toggle word wrap Toggle overflow 在本例中,您有一个名为
example.io的容器镜像 registry,其中包含一个名为example的镜像存储库,您希望将ubi8/ubi-minimal镜像从registry.access.redhat.com复制到此镜像存储库。创建该 registry 后,您可将 OpenShift Container Platform 集群配置为将源存储库的请求重定向到已镜像的存储库。
- 登录您的 OpenShift Container Platform 集群。
创建
ImageContentSourcePolicy文件(如:registryrepomirror.yaml),将源和镜像 (mirror) 替换为您自己的 registry、存储库对和镜像中的源和镜像:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建新的
ImageContentSourcePolicy:oc create -f registryrepomirror.yaml
$ oc create -f registryrepomirror.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow 创建
ImageContentSourcePolicy之后,新的设置会部署到每个节点,随即使用已镜像的存储库向源存储库发起请求。要检查已镜像的配置是否正常工作,请转至其中一个节点。例如:
列出您的节点:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 您可以发现,在应用更改时每个 worker 节点上的调度都会被禁用。
检查
/etc/containers/registries.conf文件,确保已完成更改:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将镜像从源拉取(pull)到节点,并检查是否真正通过镜像解析。
podman pull --log-level=debug registry.access.redhat.com/ubi8/ubi-minimal
sh-4.2# podman pull --log-level=debug registry.access.redhat.com/ubi8/ubi-minimalCopy to Clipboard Copied! Toggle word wrap Toggle overflow
存储库镜像故障排除
如果存储库镜像流程未按规定工作,请使用以下有关存储库镜像如何工作的信息协助排查问题。
- 首个工作镜像用于提供拉取(pull)的镜像。
- 只有在无其他镜像工作时,才会使用主 registry。
-
从系统上下文,
Insecure标志用作回退。 -
最近更改了
/etc/containers/registries文件的格式。现在是第 2 版,采用 TOML 格式。*