1.18.2.7. 部署策略以覆盖默认 registry(可选)


注: 本节中的步骤只在将发行版本镜像到您的镜像 registry 时才应用。

OpenShift Container Platform 具有一个默认的镜像 registry 值,用于指定它找到升级软件包的位置。在断开连接的环境中,您可以创建一个策略来替换该值,并将该值替换为您对发行版本镜像进行镜像的本地镜像 registry 的路径。

对于这些步骤,策略名为 ImageContentSourcePolicy。完成以下步骤以创建策略:

  1. 登录到 hub 集群的 OpenShift Container Platform 环境。
  2. 在 OpenShift Container Platform 导航中,选择 Administration > Custom Resource Definitions
  3. 选择 Instances 选项卡。
  4. 选择设置断开连接的 OLM 时创建的 ImageContentSourcePolicy 名称,以查看其内容。
  5. 选择 YAML 选项卡以 YAML 格式查看内容。
  6. 复制 ImageContentSourcePolicy 的整个内容。
  7. 在 Red Hat Advanced Cluster Management 控制台中选择 Governance > Create policy
  8. YAML 切换设置为 On 以查看策略的 YAML 版本。
  9. 删除 YAML 代码中的所有内容。
  10. 将以下 YAML 内容粘贴到窗口以创建自定义策略:

    apiVersion: policy.open-cluster-management.io/v1
    kind: Policy
    metadata:
      name: policy-pod
      namespace: default
      annotations:
        policy.open-cluster-management.io/standards:
        policy.open-cluster-management.io/categories:
        policy.open-cluster-management.io/controls:
    spec:
      disabled: false
      policy-templates:
        - objectDefinition:
            apiVersion: policy.open-cluster-management.io/v1
            kind: ConfigurationPolicy
            metadata:
              name: policy-pod-sample-nginx-pod
            spec:
              object-templates:
                - complianceType: musthave
                  objectDefinition:
                    apiVersion: v1
                    kind: Pod
                    metadata:
                      name: sample-nginx-pod
                      namespace: default
                    status:
                      phase: Running
              remediationAction: inform
              severity: low
      remediationAction: enforce
    ---
    apiVersion: policy.open-cluster-management.io/v1
    kind: PlacementBinding
    metadata:
      name: binding-policy-pod
      namespace: default
    placementRef:
      name: placement-policy-pod
      kind: PlacementRule
      apiGroup: apps.open-cluster-management.io
    subjects:
    - name: policy-pod
      kind: Policy
      apiGroup: policy.open-cluster-management.io
    ---
    apiVersion: apps.open-cluster-management.io/v1
    kind: PlacementRule
    metadata:
      name: placement-policy-pod
      namespace: default
    spec:
      clusterConditions:
      - status: "True"
        type: ManagedClusterConditionAvailable
      clusterSelector:
        matchExpressions:
          []  # selects all clusters if not specified
    Copy to Clipboard Toggle word wrap
  11. 将模板 objectDefinition 部分中的内容替换为类似以下内容的内容,以添加 ImageContentSourcePolicy 的设置:

    apiVersion: operator.openshift.io/v1alpha1
    kind: ImageContentSourcePolicy
    metadata:
      name: <your-local-mirror-name>
    spec:
      repositoryDigestMirrors:
      - mirrors:
        - <your-registry>
        source: registry.redhat.io
    Copy to Clipboard Toggle word wrap
    • your-local-mirror-name 替换为本地镜像存储库的名称。
    • your-registry 替换为本地镜像存储库的路径。

      提示: 您可以通过输入 oc adm release mirror 命令来查找到本地镜像的路径。

  12. 选择 Enforce if supported
  13. 选择 Create 来创建策略。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat