3.2. 部署集群应用程序迁移(CAM)工具

您可以在 OpenShift Container Platform 4.3 目标集群和 4.2 源集群中安装 Cluster Application Migration Operator。默认情况下,Cluster Application Migration Operator 会在目标集群上安装 CAM 工具:

注意

可选: 您可以配置 Cluster Application Migration Operator,以便在 OpenShift Container Platform 3 集群或远程集群中安装 CAM 工具。

在受限环境中,您可以从本地镜像 registry 安装 Cluster Application Migration Operator。

在集群中安装 Cluster Application Migration Operator 后,您可以启动 CAM 工具。

3.2.1. 安装 Cluster Application Migration Operator

您可以使用操作生命周期管理器(OLM)在 OpenShift Container Platform 4.3 目标集群和 OpenShift Container Platform 4.1 源集群上安装 Cluster Application Migration Operator。

3.2.1.1. 在 OpenShift Container Platform 4.3 目标集群上安装 Cluster Application Migration Operator

您可以使用 Operator Lifecycle Manager(OLM)在 OpenShift Container Platform 4.3 目标集群上安装 Cluster Application Migration Operator。

默认情况下,Cluster Application Migration Operator 会在目标集群上安装 CAM 工具:

流程

  1. 在 OpenShift Container Platform Web 控制台中,点击 OperatorsOperatorHub
  2. 使用 Filter by keyword 项(在这里是 Migration)找到 Cluster Application Migration Operator
  3. 选择 Cluster Application Migration Operator 并点 Install
  4. Create Operator Subscription 页面中,选择 openshift-migration 命名空间,并指定批准策略。
  5. Subscribe.

    Installed Operators 页中,Cluster Application Migration Operator 会出现在 openshift-migration 项目中,其状态为 InstallSucceeded

  6. Provided APIs 下,点 View 12 more…​
  7. Create NewMigrationController
  8. 点击 Create
  9. WorkloadsPod 来验证 Controller Manager 、Migration UI 、Restic 和 Velero Pod 是否正在运行。

3.2.1.2. 在 OpenShift Container Platform 4.2 源集群上安装 Cluster Application Migration Operator

您可以使用 OLM 在 OpenShift Container Platform 4 源集群上安装 Cluster Application Migration Operator。

流程

  1. 在 OpenShift Container Platform Web 控制台中,点击 OperatorsOperatorHub
  2. 使用 Filter by keyword 项(在这里是 Migration)找到 Cluster Application Migration Operator
  3. 选择 Cluster Application Migration Operator 并点 Install
  4. Create Operator Subscription 页面中,选择 openshift-migration 命名空间,并指定批准策略。
  5. Subscribe.

    Installed Operators 页中,Cluster Application Migration Operator 会出现在 openshift-migration 项目中,其状态为 InstallSucceeded

  6. Provided APIs 下,点 View 12 more…​
  7. Create NewMigrationController
  8. spec 小节中更新 migration_controller 和 migration_ui 参数:

    spec:
      ...
      migration_controller: false
      migration_ui: false
      ...
  9. 点击 Create
  10. WorkloadsPod 来验证 Restic 和 Velero Pod 是否正在运行。

3.2.2. 在受限环境中安装 Cluster Application Migration Operator

您可以为 OpenShift Container Platform 4 构建自定义 Operator 目录镜像,将其推送到本地镜像 registry,并将 OLM 配置为从本地 registry 安装 Operator。

3.2.2.1. 构建 Operator 目录镜像

集群管理员可以构建自定义 Operator 目录镜像,供 Operator Lifecycle Manager (OLM) 使用,并将镜像推送到支持 Docker v2-2 的容器镜像 registry。对于受限网络中的集群,此 registry 可以是集群有网络访问权限的 registry,如在受限网络安装过程中创建的镜像 registry。

重要

OpenShift Container Platform 集群的内部 registry 不能用作目标 registry,因为它不支持没有标签的推送,而在镜像(mirrir)过程中需要这个功能。

在这一示例中,流程假定在使用镜像 registry 时可访问您的网络以及互联网。

先决条件

  • 具有无限网络访问权限的 Linux 工作站
  • oc 版本 4.3.5+
  • podman 1.4.4+ 版
  • 访问支持 Docker v2-2 的镜像(mirror)registry
  • 如果您正在使用私有 registry,请将 REG_CREDS 环境变量设置为到 registry 凭证的文件路径。例如,对于 podman CLI:

    $ REG_CREDS=${XDG_RUNTIME_DIR}/containers/auth.json
  • 如果您正在使用 quay.io 帐户可访问的私有命名空间,您必须设置 Quay 身份验证令牌。使用您的 quay.io 凭证对登录 API 发出请求,从而设置用于 --auth-token 标志的 AUTH_TOKEN 环境变量:

    $ AUTH_TOKEN=$(curl -sH "Content-Type: application/json" \
        -XPOST https://quay.io/cnr/api/v1/users/login -d '
        {
            "user": {
                "username": "'"<quay_username>"'",
                "password": "'"<quay_password>"'"
            }
        }' | jq -r '.token')

流程

  1. 在没有网络访问限制的工作站中,与目标镜像(mirror) registry 进行身份验证:

    $ podman login <registry_host_name>

    还可使用 registry.redhat.io 验证,以便在构建期间拉取基础镜像:

    $ podman login registry.redhat.io
  2. 根据 quay.io 中的 redhat-operators 目录构建目录镜像,进行标记并将其推送到您的镜像 registry:

    $ oc adm catalog build \
        --appregistry-org redhat-operators \1
        --from=registry.redhat.io/openshift4/ose-operator-registry:v4.3 \2
        --filter-by-os="linux/amd64" \3
        --to=<registry_host_name>:<port>/olm/redhat-operators:v1 \4
        [-a ${REG_CREDS}] \5
        [--insecure] \6
        [--auth-token "${AUTH_TOKEN}"] 7
    
    INFO[0013] loading Bundles                               dir=/var/folders/st/9cskxqs53ll3wdn434vw4cd80000gn/T/300666084/manifests-829192605
    ...
    Pushed sha256:f73d42950021f9240389f99ddc5b0c7f1b533c054ba344654ff1edaf6bf827e3 to example_registry:5000/olm/redhat-operators:v1
    1
    从 App Registry 实例中拉取的机构(命名空间)。
    2
    使用与目标 OpenShift Container Platform 集群主版本和次版本匹配的标签,将 --from 设置为 ose-operator-registry 基础镜像。
    3
    --filter-by-os 设置为用于基本镜像的操作系统和架构,该镜像必须与目标 OpenShift Container Platform 集群匹配。有效值是 linux/amd64linux/ppc64lelinux/s390x
    4
    为您的目录镜像命名并包含标签,例如: v1
    5
    可选:如果需要,指定 registry 凭证文件的位置。
    6
    可选:如果您不想为目标 registry 配置信任,请添加 --insecure 标志。
    7
    可选:如果使用其他不公开的应用程序 registry 目录,则需要指定 Quay 身份验证令牌。

    有时红帽目录中会意外引入无效的清单;当发生这种情况时,您可能会看到一些错误:

    ...
    INFO[0014] directory                                     dir=/var/folders/st/9cskxqs53ll3wdn434vw4cd80000gn/T/300666084/manifests-829192605 file=4.2 load=package
    W1114 19:42:37.876180   34665 builder.go:141] error building database: error loading package into db: fuse-camel-k-operator.v7.5.0 specifies replacement that couldn't be found
    Uploading ... 244.9kB/s

    这些错误通常不是致命的,如果所提及 Operator 软件包不包含您计划安装的 Operator 或其依赖项,则可以忽略它们。

3.2.2.2. 针对受限网络配置 OperatorHub

集群管理员可以使用自定义 Operator 目录镜像将 OLM 和 OperatorHub 配置为在受限网络环境中使用本地内容。本例中的流程使用之前构建并推送到受支持的 registry 的自定义 redhat-operators 目录镜像。

先决条件

  • 具有无限网络访问权限的 Linux 工作站
  • 推送到受支持的 registry 的自定义 Operator 目录镜像
  • oc 版本 4.3.5+
  • podman 1.4.4+ 版
  • 访问支持 Docker v2-2 的镜像(mirror)registry
  • 如果您正在使用私有 registry,请将 REG_CREDS 环境变量设置为到 registry 凭证的文件路径。例如,对于 podman CLI:

    $ REG_CREDS=${XDG_RUNTIME_DIR}/containers/auth.json

流程

  1. 通过在 spec 中添加 disableAllDefaultSources: true 来禁用默认 OperatorSource:

    $ oc patch OperatorHub cluster --type json \
        -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'

    该操作将禁用在 OpenShift Container Platform 安装期间默认配置的默认 OperatorSource。

  2. oc adm catalog mirror 命令提取自定义 Operator catalog 镜像的内容,以生成镜像(mirror)所需的清单:您可以选择:

    • 允许该命令的默认行为在生成清单后自动将所有镜像内容镜像到您的镜像 registry 中,或者
    • 添加 --manifests-only 标志来只生成镜像所需的清单,但并不实际将镜像内容镜像到 registry。这对检查哪些要镜像(mirror)非常有用。如果您只需要部分内容的话,可以对映射列表做出任何修改。然后,您可以使用该文件与 oc image mirror 命令一起,在以后的步骤中镜像修改的镜像列表。

    在没有网络访问限制的工作站中,运行以下命令:

    $ oc adm catalog mirror \
        <registry_host_name>:<port>/olm/redhat-operators:v1 \1
        <registry_host_name>:<port> \
        [-a ${REG_CREDS}] \2
        [--insecure] \3
        [--filter-by-os="<os>/<arch>"] \4
        [--manifests-only] 5
    1
    指定 Operator 目录镜像。
    2
    可选:如果需要,指定 registry 凭证文件的位置。
    3
    可选:如果您不想为目标 registry 配置信任,请添加 --insecure 标志。
    4
    可选: 因为目录可能会引用支持多个架构和操作系统的镜像,您可以根据架构和操作系统进行过滤来只对匹配的镜像进行镜像(mirror)。有效值是 linux/amd64linux/ppc64lelinux/s390x
    5
    可选:只生成镜像所需的清单,但并不实际将镜像内容镜像到 registry。

    输出示例

    using database path mapping: /:/tmp/190214037
    wrote database to /tmp/190214037
    using database at: /tmp/190214037/bundles.db 1
    ...

    1
    命令生成的临时数据库。

    在运行命令后,会在当前目录中生成 <image_name>-manifests/ 目录以及以下文件:

    • 用来定义 ImageContentSourcePolicy 对象的 imageContentSourcePolicy.yaml,它可以将节点配置为在 Operator 清单中存储的镜像(image)引用和镜像 (mirror) 的 registry 间进行转换。
    • mapping.txt 文件,在其中包含所有源镜像,并将它们映射到目标 registry。此文件与 oc image mirror 命令兼容,可用于进一步自定义镜像(mirror)配置。
  3. 如果您在上一步中使用 --manifests-only 标志,并只想镜像部分内容:

    1. mapping.txt 文件中的镜像列表改为您的规格。如果您不确定要镜像的镜像子集的名称和版本,请使用以下步骤查找:

      1. oc adm catalog mirror 命令生成的临时数据库运行 sqlite3 工具,以检索与一般搜索查询匹配的镜像列表。输出以后如何编辑 mapping.txt 文件的帮助信息。

        例如,要检索与字符串 clusterlogging.4.3 类似的镜像列表:

        $ echo "select * from related_image \
            where operatorbundle_name like 'clusterlogging.4.3%';" \
            | sqlite3 -line /tmp/190214037/bundles.db 1
        1
        请参阅 oc adm catalog mirror 命令的输出结果来查找数据库文件的路径。

        输出示例

        image = registry.redhat.io/openshift4/ose-logging-kibana5@sha256:aa4a8b2a00836d0e28aa6497ad90a3c116f135f382d8211e3c55f34fb36dfe61
        operatorbundle_name = clusterlogging.4.3.33-202008111029.p0
        
        image = registry.redhat.io/openshift4/ose-oauth-proxy@sha256:6b4db07f6e6c962fc96473d86c44532c93b146bbefe311d0c348117bf759c506
        operatorbundle_name = clusterlogging.4.3.33-202008111029.p0
        ...

      2. 使用上一步的结果来编辑 mapping.txt 文件,使其只包含您要镜像的镜像子集。

        例如,您可以使用前面示例输出中的 image 值来找出您的 mapping.txt 文件中存在以下匹配行:

        mapping.txt 中的匹配镜像映射

        registry.redhat.io/openshift4/ose-logging-kibana5@sha256:aa4a8b2a00836d0e28aa6497ad90a3c116f135f382d8211e3c55f34fb36dfe61=<registry_host_name>:<port>/openshift4-ose-logging-kibana5:a767c8f0
        registry.redhat.io/openshift4/ose-oauth-proxy@sha256:6b4db07f6e6c962fc96473d86c44532c93b146bbefe311d0c348117bf759c506=<registry_host_name>:<port>/openshift4-ose-oauth-proxy:3754ea2b

        在这个示例中,如果您只想镜像这些 image,可以在 mapping.txt 文件中删除所有其他条目,仅保留上述两行。

    2. 在您的没有网络访问限制的工作站中,使用您修改的 mapping.txt 文件,使用 oc image mirror 命令将镜像镜像到 registry:

      $ oc image mirror \
          [-a ${REG_CREDS}] \
          -f ./redhat-operators-manifests/mapping.txt
  4. 应用 ImageContentSourcePolicy:

    $ oc apply -f ./redhat-operators-manifests/imageContentSourcePolicy.yaml
  5. 创建一个 CatalogSource 对象来引用您的目录镜像。

    1. 按照您的规格修改以下内容,并将它保存为 catalogsource.yaml 文件:

      apiVersion: operators.coreos.com/v1alpha1
      kind: CatalogSource
      metadata:
        name: my-operator-catalog
        namespace: openshift-marketplace
      spec:
        sourceType: grpc
        image: <registry_host_name>:<port>/olm/redhat-operators:v1 1
        displayName: My Operator Catalog
        publisher: grpc
      1
      指定您的自定义 Operator 目录镜像。
    2. 使用该文件创建 CatalogSource 对象:

      $ oc create -f catalogsource.yaml
  6. 确定成功创建以下资源。

    1. 检查 Pod:

      $ oc get pods -n openshift-marketplace

      输出示例

      NAME                                    READY   STATUS    RESTARTS  AGE
      my-operator-catalog-6njx6               1/1     Running   0         28s
      marketplace-operator-d9f549946-96sgr    1/1     Running   0         26h

    2. 检查 CatalogSource:

      $ oc get catalogsource -n openshift-marketplace

      输出示例

      NAME                  DISPLAY               TYPE PUBLISHER  AGE
      my-operator-catalog   My Operator Catalog   grpc            5s

    3. 检查 PackageManifest:

      $ oc get packagemanifest -n openshift-marketplace

      输出示例

      NAME    CATALOG              AGE
      etcd    My Operator Catalog  34s

现在,您可在受限网络 OpenShift Container Platform 集群的 web 控制台中,通过 OperatorHub 安装 Operator。

3.2.2.3. 在一个受限的环境中的 OpenShift Container Platform 4.3 目标集群上安装 Cluster Application Migration Operator

您可以使用 Operator Lifecycle Manager(OLM)在 OpenShift Container Platform 4.3 目标集群上安装 Cluster Application Migration Operator。

默认情况下,Cluster Application Migration Operator 会在目标集群上安装 CAM 工具:

先决条件

  • 已创建自定义 Operator 目录并将其推送到 registry 的镜像。
  • 已将 OLM 配置为从 registry 镜像来安装 Cluster Application Migration Operator。

流程

  1. 在 OpenShift Container Platform Web 控制台中,点击 OperatorsOperatorHub
  2. 使用 Filter by keyword 项(在这里是 Migration)找到 Cluster Application Migration Operator
  3. 选择 Cluster Application Migration Operator 并点 Install
  4. Create Operator Subscription 页面中,选择 openshift-migration 命名空间,并指定批准策略。
  5. Subscribe.

    Installed Operators 页中,Cluster Application Migration Operator 会出现在 openshift-migration 项目中,其状态为 InstallSucceeded

  6. Provided APIs 下,点 View 12 more…​
  7. Create NewMigrationController
  8. 点击 Create
  9. WorkloadsPod 来验证 Controller Manager 、Migration UI 、Restic 和 Velero Pod 是否正在运行。

3.2.2.4. 在一个受限的环境中的 OpenShift Container Platform 4.2 源集群上安装 Cluster Application Migration Operator

您可以使用 OLM 在 OpenShift Container Platform 4 源集群上安装 Cluster Application Migration Operator。

先决条件

  • 已创建自定义 Operator 目录并将其推送到 registry 的镜像。
  • 已将 OLM 配置为从 registry 镜像来安装 Cluster Application Migration Operator。

流程

  1. 在 OpenShift Container Platform Web 控制台中,点击 OperatorsOperatorHub
  2. 使用 Filter by keyword 项(在这里是 Migration)找到 Cluster Application Migration Operator
  3. 选择 Cluster Application Migration Operator 并点 Install
  4. Create Operator Subscription 页面中,选择 openshift-migration 命名空间,并指定批准策略。
  5. Subscribe.

    Installed Operators 页中,Cluster Application Migration Operator 会出现在 openshift-migration 项目中,其状态为 InstallSucceeded

  6. Provided APIs 下,点 View 12 more…​
  7. Create NewMigrationController
  8. 点击 Create

3.2.3. 启动 CAM web 控制台

您可以在浏览器中启动 CAM web 控制台。

流程

  1. 登录到已安装 CAM 工具的 OpenShift Container Platform 集群。
  2. 运行以下命令来获取 CAM web 控制台 URL:

    $ oc get -n openshift-migration route/migration -o go-template='https://{{ .spec.host }}'

    输出类似于以下: https://migration-openshift-migration.apps.cluster.openshift.com

  3. 启动浏览器并进入 CAM web 控制台。

    注意

    如果在安装 Cluster Application Migration Operator 后尝试立即访问 CAM web 控制台,则该控制台可能无法加载,因为 Operator 仍然在配置集群。等待几分钟后重试。

  4. 如果您使用自签名的 CA 证书,则会提示您接受源集群 API 服务器的 CA 证书。网页会引导您接受剩余证书的过程。
  5. 使用 OpenShift Container Platform 的用户名密码进行登陆。