迁移后映像更新

使用 migctl migration generate-artifacts 命令创建的容器工件并不仅用于在目标集群中部署迁移的工作负载。它们还用于“投产后”维护操作,包括采用应用和用户模式操作系统软件更新和安全补丁,修改嵌入的配置,添加或替换文件,以及更新 Migrate to Containers 运行时软件。

查看生成的映像 Dockerfile

此类维护操作会利用生成的 Dockerfile 和捕获的系统映像层。与 Migrate to Containers 运行时层结合使用时,这些文件可以内置于可执行容器映像中。

如下图所示,生成的容器工件已经创建,且不忘 CI/CD 流水线构建阶段集成:

CI/CD 流水线示意图。

Dockerfile 的结构为多阶段构建,可让您更轻松地进行维护和操作,同时避免映像膨胀。

下面是生成的 Dockerfile 的示例:

# Please refer to the documentation:
# https://cloud.google.com/migrate/anthos/docs/dockerfile-reference

FROM anthos-migrate.gcr.io/v2k-run-embedded:v1.6.0 as migrate-for-anthos-runtime

# Image containing data captured from the source VM
FROM gcr.io/myproject/myworkload-non-runnable-base:v1.0.0 as source-content

# If you want to update parts of the image, add your commands here.
# For example:
# RUN apt-get update
# RUN apt-get install -y \
#               package1=version \
#               package2=version \
#               package3=version
# RUN yum update
# RUN wget http://github.com

COPY --from=migrate-for-anthos-runtime / /

# Migrate for GKE Enterprise image includes entrypoint
ENTRYPOINT [ "/.v2k.go" ]

第二个 FROM 指令引用从已迁移虚拟机上捕获的系统映像层。此层本身无法运行,需要与 Migrate to Containers 运行时层结合使用以构建可执行映像。

如需详细了解如何使用 Cloud Build 构建容器映像,请参阅构建容器映像

更新迁移的工作负载组件层

如果要将任何更新或修改应用于迁移的工作负载映像层,您应在第二个 FROM 指令完成之后应用它们。

在以下示例中,我们使用 Cloud Build 和 gcloud CLI 更新以 SUSE Enterprise Linux(SLES)虚拟机作为来源迁移的容器映像。以下示例更了 SLES 发行版 openssh 软件包。

更新后的 Dockerfile:

# Image containing data captured from the source VM
FROM anthos-migrate.gcr.io/v2k-run-embedded:v1.6.0 as migrate-for-anthos-runtime

# Image containing data captured from the source VM
FROM gcr.io/myproject/myworkload-non-runnable-base:v1.0.0 as source-content

# If you want to update parts of the image, add your commands here.
# For example:
# RUN apt-get update
# RUN apt-get install -y \
#               package1=version \
#               package2=version \
#               package3=version
# RUN yum update
# RUN wget http://github.com

RUN zypper ref -s && zypper -n in openssh
COPY --from=migrate-for-anthos-runtime / /

# Migrate to Containers image includes entrypoint
ENTRYPOINT [ "/.v2k.go" ]

构建更新后的映像:

  1. 将生成的 Dockerfile 从 Cloud Storage 存储分区下载到 Cloud Shell 环境中的本地目录。
  2. 如上例所示那样,修改 Dockerfile 以添加突出显示的 RUN 指令。
  3. 构建更新后的映像,并使用更新后的版本标记将其推送到 Container Registry,确保为构建提供足够的完成时间。以下示例中的映像位于当前目录中:

    gcloud builds submit --timeout 4h --tag gcr.io/myproject/mySUSEworkload:v1.0.1 .
    
  4. 您可以使用新构建的映像来更新现有部署,例如对已部署的应用执行滚动升级:

    kubectl set image deployment/myWorkload my-app=gcr.io/myproject/mySUSEworkload:v1.0.1 --record
    

更新 Migrate to Containers 层版本

新版本的 Migrate to Containers 软件发布后,您可以在已部署的工作负载映像中更新该软件版本。此类更新可能包括新功能、增强功能或问题修复。

如需更新 Migrate to Containers 软件层,请修改 Dockerfile 并将版本标记更改为要应用的更新版本。

您可以使用前面的示例,将 FROM 指令修改为以下内容,从而将版本从 v1.6.0 更新为假设版本 v1.15.0:

FROM anthos-migrate.gcr.io/v2k-run-embedded:v1.15.0 as migrate-for-anthos-runtime

更新 Dockerfile 之后,您将需要构建新的工作负载容器映像版本并将其应用于现有部署以进行更新。

后续步骤