11.4. 将基于 OLM 的 Operator 添加到断开连接的节点中
您可以通过将基于 OLM 的 Operator 嵌入到 Red Hat Enterprise Linux for Edge (RHEL for Edge)镜像中,在断开连接的环境中使用基于 OLM 的 Operator。
11.4.1. 关于将基于 OLM 的 Operator 添加到断开连接的节点中 复制链接链接已复制到粘贴板!
对于在断开连接的环境中安装的 Operator,Operator Lifecycle Manager (OLM)默认无法访问远程 registry 上托管的源,因为这些远程源需要足够的互联网连接。因此,您必须将远程 registry 镜像到高度可用的容器 registry。
在断开连接的环境中,需要执行以下步骤来使用基于 OLM 的 Operator:
- 将 OLM 包含在您的镜像 registry 的容器镜像列表中。
-
通过直接更新 CRI-O 配置将系统配置为使用您的镜像 registry。MicroShift 不支持
ImageContentSourcePolicy。 -
在节点中添加
CatalogSource对象,以便 OLM 目录 Operator 可以使用镜像 registry 上的本地目录。 - 确保 MicroShift 已安装在断开连接的容量中运行。
- 确保网络设置配置为在断开连接的模式下运行。
在断开连接的节点中启用 OLM 后,您可以继续使用互联网连接的工作站在发布较新版本的 Operator 时保持本地目录源更新。
11.4.1.1. 执行空运行 复制链接链接已复制到粘贴板!
您可以使用 oc-mirror 来执行空运行,而无需实际镜像(mirror)。空运行意味着您可以查看要镜像的镜像列表。您可以使用空运行早期捕获与镜像设置配置相关的任何错误,或使用生成的镜像列表与其他工具执行镜像。
先决条件
- 您可以访问互联网来获取所需的容器镜像。
-
已安装 OpenShift CLI(
oc)。 - 已安装 oc-mirror CLI 插件。
- 已创建镜像设置配置文件。
流程
使用
--dry-run标志运行oc mirror命令来执行空运行:$ oc-mirror --config <ImageSetConfig.yaml> docker://localhost:5000 --workspace file://<outm2m> --dry-run --v2其中:
ImageSetConfig.yaml- 指定您创建的镜像设置配置文件的名称。
docker://localhost:5000-
指定镜像 registry。使用--
dry-run 标志时,不会镜像到此 registry。 --workspace file:// <outm2m>- 插入工作区路径的地址。
--dry-run- dry run 标志会生成空运行工件,而不是实际的镜像设置文件。
--v2指定 oc mirror v2。
输出示例
2025/08/25 15:50:44 [INFO] : 👋 Hello, welcome to oc-mirror 2025/08/25 15:50:44 [INFO] : ⚙ setting up the environment for you... 2025/08/25 15:50:44 [INFO] : 🔀 workflow mode: mirrorToMirror 2025/08/25 15:50:44 [INFO] : 🕵 going to discover the necessary images... 2025/08/25 15:50:44 [INFO] : 🔍 collecting release images... 2025/08/25 15:50:44 [INFO] : 🔍 collecting operator images... ✓ (1m30s) Collecting catalog registry.redhat.io/redhat/redhat-operator-index:v4.20 2025/08/25 15:52:14 [INFO] : 🔍 collecting additional images... 2025/08/25 15:52:14 [INFO] : 📄 list of all images for mirroring in : wspace/working-dir/dry-run/mapping.txt 2025/08/25 15:52:14 [INFO] : mirror time : 1m30.399585837s 2025/08/25 15:52:14 [INFO] : 👋 Goodbye, thank you for using oc-mirror
运行以下命令,查看生成的
mapping.txt文件:$ cat wspace/working-dir/dry-run/mapping.txt输出示例
docker://registry.redhat.io/amq8/amq-broker-rhel9@sha256:47fd4ce2533496828aba37bd1f9715e2164d5c90bd0fc6b25e7e0786d723bf01=docker://mirror.com/amq8/amq-broker-rhel9:sha256-47fd4ce2533496828aba37bd1f9715e2164d5c90bd0fc6b25e7e0786d723bf01 docker://registry.redhat.io/amq8/amq-broker-init-rhel9@sha256:9cc48eecf1442ae04b8543fa5d4381a13bc2831390850828834d387006d1342b=docker://mirror.com/amq7/amq-broker-init-rhel9:sha256-9cc48eecf1442ae04b8543fa5d4381a13bc2831390850828834d387006d1342b docker://registry.redhat.io/amq8/amq-broker-rhel9@sha256:bb6fbd68475a7852b4d99eea6c4ab313f9267da7963162f0d75375d7063409e7=docker://mirror.com/amq8/amq-broker-rhel9:sha256-bb6fbd68475a7852b4d99eea6c4ab313f9267da7963162f0d75375d7063409e7 docker://registry.redhat.io/amq8/amq-broker-rhel9@sha256:d42d713da0ce6806fdc6492b6342586783e6865a82a8647d3c4288439b1751ee=docker://mirror.com/amq8/amq-broker-rhel9:sha256-d42d713da0ce6806fdc6492b6342586783e6865a82a8647d3c4288439b1751ee docker://registry.redhat.io/amq8/amq-broker-init-rhel9@sha256:ffffa9875f0379e9373f89f05eb06e5a193273bb04bc3aa5f85b044357b79098=docker://mirror.com/amq8/amq-broker-init-rhel9:sha256-ffffa9875f0379e9373f89f05eb06e5a193273bb04bc3aa5f85b044357b79098
11.4.1.2. 获取目录和 Operator 容器镜像引用 复制链接链接已复制到粘贴板!
使用 oc-mirror 插件执行空运行以查看您要镜像的镜像列表后,您必须获取所有容器镜像引用,然后格式化要添加到镜像构建器蓝图的输出。
对于为专有 Operator 创建的目录,您可以在不按照以下流程的情况下格式化镜像构建器蓝图的镜像引用。
先决条件
- 您有一个要使用的 Operator 的目录索引。
-
已安装
jqCLI 工具。 - 熟悉镜像构建器蓝图文件。
- 您有一个镜像构建器蓝图 TOML 文件。
流程
解析目录
index.json文件,以获取镜像构建器蓝图中包含的镜像引用。您可以使用未过滤的目录,也可以过滤掉无法镜像的镜像:运行以下命令,解析未过滤的目录
index.json文件以获取镜像引用:jq -r --slurp '.[] | select(.relatedImages != null) | "[[containers]]\nsource = \"" + .relatedImages[].image + "\"\n"' ./oc-mirror-workspace/src/catalogs/registry.redhat.io/redhat/redhat-operator-index/v4.20/index/index.json如果要过滤无法镜像的镜像,请运行以下命令来过滤并解析目录
index.json文件:$ jq -r --slurp '.[] | select(.relatedImages != null) | .relatedImages[] | select(.name | contains("ppc") or contains("s390x") | not) | "[[containers]]\\nsource = \\"" + .image + "\\"\\n"' ./oc-mirror-workspace/src/catalogs/registry.redhat.io/redhat/redhat-operator-index/v4.20/index/index.json注意此步骤使用 AMQ Broker Operator 作为示例。您可以在
jq命令中添加其他条件,以便根据您的用例的要求进行进一步过滤。image-reference 输出示例
[[containers]] source = "registry.redhat.io/amq8/amq-broker-init-rhel9@sha256:0b2126cfb6054fdf428c1f43b69e36e93a09a49ce15350e9273c98cc08c6598b" [[containers]] source = "registry.redhat.io/amq8/amq-broker-init-rhel9@sha256:0dde839c2dce7cb684094bf26523c8e16677de03149a0fff468b8c3f106e1f4f" ... ... [[containers]] source = "registry.redhat.io/amq8/amq-broker-rhel9@sha256:e8fa2a00e576ecb95561ffbdbf87b1c82d479c8791ab2c6ce741dd0d0b496d15" [[containers]] source = "registry.redhat.io/amq8/amq-broker-rhel9@sha256:ff6fefad518a6c997d4c5a6e475ba89640260167f0bc27715daf3cc30116fad1" … EOF重要对于镜像和断开连接的用例,请确保从目录
index.json文件过滤的所有源都是摘要。如果有任何源使用标签而不是摘要,Operator 安装会失败。标签需要互联网连接。
运行以下命令,查看
imageset-config.yaml以获取CatalogSource自定义资源(CR)的目录镜像引用:$ cat imageset-config.yaml输出示例
kind: ImageSetConfiguration apiVersion: mirror.openshift.io/v2alpha1 mirror: operators: - catalog: registry.redhat.io/redhat/redhat-operator-index:v4.201 packages: - name: amq-broker-rhel9 channels: - name: 7.13.x- 1
- 使用以下
jq命令的mirror.catalog目录镜像引用中的值来获取镜像摘要。在本例中,< registry.redhat.io/redhat/redhat-operator-index:v4.20 >。
运行以下命令,获取目录索引镜像的 SHA:
$ skopeo inspect docker://<registry.redhat.io/redhat/redhat-operator-index:v{product-version}> | jq .Digest1 - 1
- 使用
jq命令的mirror.catalog目录镜像引用中的值来获取镜像摘要。在本例中,< registry.redhat.io/redhat/redhat-operator-index:v4.20 >。
输出示例
"sha256:7a76c0880a839035eb6e896d54ebd63668bb37b82040692141ba39ab4c539bc6"要准备好将镜像引用添加到镜像构建器蓝图文件中,请使用以下示例格式化目录镜像引用:
[[containers]] source = "registry.redhat.io/redhat/redhat-operator-index@sha256:7a76c0880a839035eb6e896d54ebd63668bb37b82040692141ba39ab4c539bc6"将之前所有步骤中的镜像引用添加到镜像构建器蓝图中。
生成的镜像构建器蓝图示例片断
name = "microshift_blueprint" description = "MicroShift 4.20.1 on x86_64 platform" version = "0.0.1" modules = [] groups = [] [[packages]]1 name = "microshift" version = "4.20.1" ... ... [customizations.services]2 enabled = ["microshift"] [customizations.firewall] ports = ["22:tcp", "80:tcp", "443:tcp", "5353:udp", "6443:tcp", "30000-32767:tcp", "30000-32767:udp"] ... ... [[containers]]3 source = "quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:f41e79c17e8b41f1b0a5a32c3e2dd7cd15b8274554d3f1ba12b2598a347475f4" [[containers]] source = "quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:dbc65f1fba7d92b36cf7514cd130fe83a9bd211005ddb23a8dc479e0eea645fd" ... ... [[containers]]4 source = "registry.redhat.io/redhat/redhat-operator-index@sha256:7a76c0880a839035eb6e896d54ebd63668bb37b82040692141ba39ab4c539bc6" ... ... [[containers]] source = "registry.redhat.io/amq8/amq-broker-init-rhel9@sha256:0dde839c2dce7cb684094bf26523c8e16677de03149a0fff468b8c3f106e1f4f" ... ... [[containers]] source = "registry.redhat.io/amq8/amq-broker-rhel9@sha256:e8fa2a00e576ecb95561ffbdbf87b1c82d479c8791ab2c6ce741dd0d0b496d15" [[containers]] source = "registry.redhat.io/amq8/amq-broker-rhel9@sha256:ff6fefad518a6c997d4c5a6e475ba89640260167f0bc27715daf3cc30116fad1" … EOF
11.4.1.3. 在断开连接的部署 RHEL for Edge 镜像中应用目录和 Operator 复制链接链接已复制到粘贴板!
为断开连接的环境创建 RHEL for Edge 镜像并配置了 MicroShift 网络设置以进行断开连接的使用后,您可以配置命名空间并创建目录和 Operator 自定义资源(CR)以运行 Operator。
先决条件
- 您有一个 RHEL for Edge 镜像。
- 联网配置为断开连接使用。
- 您已完成了 oc-mirror 插件空运行过程。
流程
创建
CatalogSource自定义资源(CR),类似以下示例:my-catalog-source-cr.yaml文件示例apiVersion: operators.coreos.com/v1alpha1 kind: CatalogSource metadata: name: cs-redhat-operator-index namespace: openshift-marketplace1 spec: image: registry.example.com/redhat/redhat-operator-index:v4.17 sourceType: grpc displayName: publisher: updateStrategy: registryPoll: interval: 60m- 1
- 全局命名空间。将
metadata.namespace设置为openshift-marketplace可让目录在所有命名空间中运行。任何命名空间中的订阅可以引用在openshift-marketplace命名空间中创建的目录。
注意openshift-marketplace的默认 pod 安全准入定义是baseline,因此在该命名空间中创建的目录源自定义资源(CR)不需要设置spec.grpcPodConfig.securityContextConfig值。如果需要使用命名空间和 Operator,您可以设置legacy或restricted值。将目录索引提交的 SHA 添加到 Catalog Source (CR)中,如下例所示:
命名空间
spec.image配置示例apiVersion: operators.coreos.com/v1alpha1 kind: CatalogSource metadata: name: cs-redhat-operator-index namespace: openshift-marketplace spec: image: registry.example.com/redhat/redhat-operator-index@sha256:7a76c0880a839035eb6e896d54ebd63668bb37b82040692141ba39ab4c539bc61 sourceType: grpc displayName: publisher: updateStrategy: registryPoll: interval: 60m- 1
- 镜像提交的 SHA。使用添加到镜像构建器蓝图中的同一 SHA。
重要您必须在目录 CR 中使用 SHA 而不是标签,否则 pod 无法启动。
运行以下命令,将 oc-mirror 插件中的 YAML 文件空运行结果目录应用到节点:
$ oc apply -f ./oc-mirror-workspace/results-1708508014/catalogSource-cs-redhat-operator-index.yaml输出示例
catalogsource.operators.coreos.com/cs-redhat-operator-index created运行以下命令验证
CatalogSource资源是否已成功安装:$ oc get catalogsource --all-namespaces使用以下命令验证目录源是否正在运行:
$ oc get pods -n openshift-marketplace输出示例
NAME READY STATUS RESTARTS AGE cs-redhat-operator-index-4227b 2/2 Running 0 2m5s创建一个
SubscriptionCR,类似以下示例:my-subscription-cr.yaml文件示例apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: name: amq-broker namespace: openshift-operators spec: channel: 7.11.x name: amq-broker-rhel8 source: cs-redhat-operator-index sourceNamespace: openshift-marketplace运行以下命令来应用
SubscriptionCR:$ oc apply -f ./<my-subscription-cr.yaml>1 - 1
- 指定
SubscriptionCR 的名称,如my-subscription-cr.yaml。
输出示例
subscription.operators.coreos.com/amq-broker created