1.18.2.7. 部署策略以覆盖默认 registry(可选)
注: 本节中的步骤只在将发行版本镜像到您的镜像 registry 时才应用。
OpenShift Container Platform 具有一个默认的镜像 registry 值,用于指定它找到升级软件包的位置。在断开连接的环境中,您可以创建一个策略来替换该值,并将该值替换为您对发行版本镜像进行镜像的本地镜像 registry 的路径。
对于这些步骤,策略名为 ImageContentSourcePolicy。完成以下步骤以创建策略:
- 登录到 hub 集群的 OpenShift Container Platform 环境。
- 在 OpenShift Container Platform 导航中,选择 Administration > Custom Resource Definitions。
- 选择 Instances 选项卡。
- 选择设置断开连接的 OLM 时创建的 ImageContentSourcePolicy 名称,以查看其内容。
-
选择 YAML 选项卡以
YAML格式查看内容。 - 复制 ImageContentSourcePolicy 的整个内容。
- 在 Red Hat Advanced Cluster Management 控制台中选择 Governance > Create policy。
-
将
YAML切换设置为 On 以查看策略的 YAML 版本。 -
删除
YAML代码中的所有内容。 将以下
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将模板
objectDefinition部分中的内容替换为类似以下内容的内容,以添加 ImageContentSourcePolicy 的设置:apiVersion: operator.openshift.io/v1alpha1 kind: ImageContentSourcePolicy metadata: name: <your-local-mirror-name> spec: repositoryDigestMirrors: - mirrors: - <your-registry> source: registry.redhat.io-
将
your-local-mirror-name替换为本地镜像存储库的名称。 将
your-registry替换为本地镜像存储库的路径。提示: 您可以通过输入
oc adm release mirror命令来查找到本地镜像的路径。
-
将
- 选择 Enforce if supported。
- 选择 Create 来创建策略。