9.8. 镜像镜像目录的范围,以减少集群节点重启的频率

您可以在存储库级别或更广泛的 registry 级别限定镜像目录。一个范围广泛的 ImageContentSourcePolicy 资源可减少节点在响应资源更改时需要重启的次数。

要强化 ImageContentSourcePolicy 资源中镜像目录的范围,请执行以下步骤。

先决条件

  • 安装 OpenShift Container Platform CLI oc
  • 以具有 cluster-admin 权限的用户身份登录。
  • 配置镜像镜像目录,以便在断开连接的集群中使用。

流程

  1. 运行以下命令,为 <local_registry><pull_spec><pull_secret_file> 指定值:

    $ oc adm catalog mirror <local_registry>/<pull_spec> <local_registry> -a <pull_secret_file> --icsp-scope=registry

    其中:

    <local_registry>
    您为断开连接的集群配置的本地 registry,如 local.registry:5000
    <pull_spec>
    断开连接的 registry 中配置的拉取规格,如 redhat/redhat-operator-index:v4.7
    <pull_secret_file>
    .json 文件格式的 registry.redhat.io pull secret。您可以从 Red Hat OpenShift Cluster Manager 下载 pull secret

    oc adm catalog mirror 命令创建 /redhat-operator-index-manifests 目录,并生成 imageContentSourcePolicy.yamlcatalogSource.yamlmapping.txt 文件。

  2. 将新的 ImageContentSourcePolicy 资源应用到集群:

    $ oc apply -f imageContentSourcePolicy.yaml

验证

  • 验证 oc apply 是否成功将更改应用到 ImageContentSourcePolicy:

    $ oc get ImageContentSourcePolicy -o yaml

    输出示例

    apiVersion: v1
    items:
    - apiVersion: operator.openshift.io/v1alpha1
      kind: ImageContentSourcePolicy
      metadata:
        annotations:
          kubectl.kubernetes.io/last-applied-configuration: |
            {"apiVersion":"operator.openshift.io/v1alpha1","kind":"ImageContentSourcePolicy","metadata":{"annotations":{},"name":"redhat-operator-index"},"spec":{"repositoryDigestMirrors":[{"mirrors":["local.registry:5000"],"source":"registry.redhat.io"}]}}
    ...

更新 ImageContentSourcePolicy 资源后,OpenShift Container Platform 会将新设置部署到每个节点,集群开始使用已镜像的存储库向源存储库发出请求。