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

部署集群应用程序迁移 (CAM) 工具需要在 OpenShift Container Platform 3 源OpenShift Container Platform 4.2 目标集群上安装 CAM Operator。 并在OpenShift Container Platform 3 源集群中配置跨原始资源共享。

Cluster Application Migration Operator 默认在目标集群上安装 CAM 工具(CAM web 控制台和迁移控制器)。您可以 在 OpenShift Container Platform 3 和远程集群中安装 CAM 工具

1.5.1. 在 OpenShift Container Platform 3 源集群上安装 Cluster Application Migration Operator

您可以手动在 OpenShift Container Platform 3 源集群上安装 Cluster Application Migration Operator,因为 OpenShift Container Platform 3 不支持 Operator Lifecycle Manager。

先决条件

  • 必须安装 podman
  • 您的 OpenShift Container Platform 3 集群需要被配置为从 registry.redhat.io 拉取镜像。

    为了拉取镜像,您需要创建一个 imagestreamsecret,并把它复制到集群中的每个节点。

流程

  1. 使用您的红帽客户门户网站账户登陆到 registry.redhat.io:

    $ sudo podman login registry.redhat.io
    注意

    如果系统是为无根 Podman 容器配置的,则此过程不需要 sudo

  2. 下载 operator.yml 文件:

    $ sudo podman cp $(sudo podman create registry.redhat.io/rhcam-1-2/openshift-migration-rhel7-operator:v1.2):/operator.yml ./
  3. 下载 controller-3.yml 文件:

    $ sudo podman cp $(sudo podman create registry.redhat.io/rhcam-1-2/openshift-migration-rhel7-operator:v1.2):/controller-3.yml ./
  4. 登录您的 OpenShift Container Platform 3 集群。
  5. 验证集群可以在 registry.redhat.io 中进行身份验证:

    $ oc run test --image registry.redhat.io/ubi8 --command sleep infinity
  6. 创建 Cluster Application Migration Operator CR 对象:

    $ oc create -f operator.yml
    namespace/openshift-migration created
    rolebinding.rbac.authorization.k8s.io/system:deployers created
    serviceaccount/migration-operator created
    customresourcedefinition.apiextensions.k8s.io/migrationcontrollers.migration.openshift.io created
    role.rbac.authorization.k8s.io/migration-operator created
    rolebinding.rbac.authorization.k8s.io/migration-operator created
    clusterrolebinding.rbac.authorization.k8s.io/migration-operator created
    deployment.apps/migration-operator created
    Error from server (AlreadyExists): error when creating "./operator.yml":
    rolebindings.rbac.authorization.k8s.io "system:image-builders" already exists 1
    Error from server (AlreadyExists): error when creating "./operator.yml":
    rolebindings.rbac.authorization.k8s.io "system:image-pullers" already exists 2
    1 2
    您可以忽略 Error from server (AlreadyExists) 信息。它们是由 Cluster Application Migration Operator 为早期版本的 OpenShift Container Platform 3 创建资源造成的,这些资源在以后的版本中已提供。
  7. 创建 Migration controller CR 对象:

    $ oc create -f controller-3.yml
  8. 确认 Velero 和 Restic Pod 正在运行:

    $ oc get pods -n openshift-migration

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

您可以使用 OLM 在 OpenShift Container Platform 4.2 目标集群上安装 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 是否正在运行。

1.5.3. 在 OpenShift Container Platform 3 源集群中配置跨原始资源共享

您必须在 OpenShift Container Platform 3 源集群中配置跨原始资源共享,以启用源集群 API 服务器和 CAM 工具间的通信。

流程

  1. 登录到已安装 CAM 工具的集群。
  2. 获取 CORS 配置的值:

    $ oc get -n openshift-migration route/migration -o go-template='(?i)//{{ .spec.host }}(:|\z){{ println }}' | sed 's,\.,\\.,g'
  3. 登陆到 OpenShift Container Platform 3 源集群。
  4. 将 CORS 配置值添加到 /etc/origin/master/master-config.yaml 配置文件的 corsAllowedOrigins 字段中:

    corsAllowedOrigins:
    - (?i)//migration-openshift-migration\.apps\.cluster\.com(:|\z) 1
    - (?i)//openshift\.default\.svc(:|\z)
    - (?i)//kubernetes\.default(:|\z)
    1
    指定您的 CORS 配置。
  5. 重启 API 服务器和控制器管理器以应用更改:

    • 在 OpenShift Container Platform 3.7 和 3.9 中,这些组件作为独立主机进程运行,由 systemd 管理,并通过运行以下命令来重新启动:

      $ systemctl restart atomic-openshift-master-api atomic-openshift-master-controllers
    • 在 OpenShift Container Platform 3.10 和 3.11 中,这些组件在由 kubelet 管理的静态 Pod 中运行,并通过运行以下命令来重新启动:

      $ /usr/local/bin/master-restart api
      $ /usr/local/bin/master-restart controllers
  6. 验证配置:

    $ curl -v -k -X OPTIONS \
    "<cluster_url>/apis/migration.openshift.io/v1alpha1/namespaces/openshift-migration/migclusters" \ 1
    -H "Access-Control-Request-Method: GET" \
    -H "Access-Control-Request-Headers: authorization" \
    -H "Origin: https://<CAM_web_console_url>" 2
    1
    指定您配置的 CORS 集群的 URL。
    2
    指定 CAM web 控制台的 URL。URL 基于 CORS 配置值,例如 https://migration-openshift-migration.apps.cluster

    输出结果类似如下:

    < HTTP/2 204
    < access-control-allow-credentials: true
    < access-control-allow-headers: Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Requested-With, If-Modified-Since
    < access-control-allow-methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
    < access-control-allow-origin: https://migration-openshift-migration.apps.cluster
    < access-control-expose-headers: Date
    < cache-control: no-store