自定义 Windows IIS 服务的迁移计划

查看创建迁移期间填充的迁移计划文件。您可以进行自定义,然后再继续执行迁移。迁移计划的详细信息将用于从源虚拟机中提取工作负载容器工件。

本部分介绍了迁移计划内容以及在执行迁移和生成部署工件之前您可以考虑的自定义种类。

须知事项

本文档假设您已经创建了迁移并生成了迁移计划文件。

迁移计划结构

以下是完整的迁移计划结构。后续部分将讨论此结构,介绍该结构的每个部分以及如何对各个部分进行修改。

globalSettings:
    globalIis:
        enablegmsa: string
        apppools:
            - enable32bitapponwin64: bool
              identitytype: string
              managedruntimeversion: string
              name: string
        connectionStrings:
            add:
                - connectionstring: string
                  name: string
                  providername: string
        security:
            authentication:
                windowsAuthentication:
                    enabled: bool
                    providers:
                        - value: string
            authorization:
                add:
                    - access_type: string
                      roles: string
                      users: string
                      verbs: string
                remove:
                    - roles: string
                      users: string
                      verbs: string
    image:
        extraFeatures:
            - string
    target:
        baseVersion: string
        requirements:
            - string
        warnings:
            - string
    msvcRuntimes:
            - string
    pathEnvVarAdditionalEntries:
            - string
images:
    - name: string
      probes:
        enabled: bool
        livenessProbe:
            probehandler:
                exec:
                    command:
                        - string
                        - string
            initialdelayseconds: int
            timeoutseconds: int
            periodseconds: int
            successthreshold: int
            failurethreshold: int
            terminationgraceperiodseconds: optional[int]
        readinessProbe:
            probehandler:
                exec:
                    command:
                        - string
                        - string
            initialdelayseconds: int
            timeoutseconds: int
            periodseconds: int
            successthreshold: int
            failurethreshold: int
            terminationgraceperiodseconds: optional[int]
      useractions:
        files:
            - source: string
              target: string
        registry:
            currentcontrolset:
                - path: string
            software:
                - path: string
      workloads:
        sites:
            site:
                - applications:
                    - applicationpool: string
                      path: string
                      virtualdirectories:
                        - path: string
                          physicalpath: string
                  bindings:
                    - port: int
                      protocol: string
                      sslflags: int
                  connectionstrings:
                    - connectionstring: string
                      name: string
                      providername: string
                  name: string
                  security:
                    authentication:
                        windowsAuthentication:
                            enabled: bool
                            providers:
                                - value: string
                    authorization:
                        add:
                            - access_type: string
                              roles: string
                              users: string
                              verbs: string
                        remove:
                            - roles: string
                              users: string
                              verbs: string
                  serverautostart: bool
version: string

globalSettings 部分

globalSettings 部分介绍了 pod 从此虚拟机运行 IIS 站点所需满足的基本要求。发现过程会搜索来源虚拟机中的常规配置,并使用这些配置来填充本部分。这些配置包含特定映像配置中存在的字段(如以下部分所述),并且同时影响所有映像。

image 部分

globalSettings 后面的 image 部分描述了需要在 pod 上安装的 Windows 功能列表。发现过程会使用原始虚拟机中存在且可以安装在 Windows 容器上的所有 Windows 功能填充本部分。

msvcRuntimes 部分

迁移应用时,它可能依赖于特定版本的 Microsoft Visual C++ 运行时 (MSVCRT)。Migrate to Containers 会自动检测来源虚拟机上安装的运行时,并将其包含在迁移计划中。

您可以通过添加或移除 msvcRuntimes 的成员来修改迁移计划中的运行时列表:

可能的值的完整列表如下(2015 运行时还支持 2017、2019 和 2022 运行时)

    msvcRuntimes:
        - MSVC2012_x64
        - MSVC2013_x64
        - MSVC2015_x64
        - MSVC2012_x86
        - MSVC2013_x86
        - MSVC2015_x86

pathEnvVarAdditionalEntries 部分

Windows IIS 应用可能具有非默认的 PATH 环境变量条目,这些条目在来源虚拟机上自动检测,并包含在迁移计划中。您可以通过修改 pathEnvVarAdditionalEntries 的成员来修改 PATH 环境变量:

    pathEnvVarAdditionalEntries:
      - "C:\\myDllsFolder"
      - "C:\\ProgramData\\SomeSoftware"

修改 image 部分

在以下情况下,您可能需要修改 image 部分:

  1. 迁移的站点不需要某些建议的功能。如果来源虚拟机除了托管 IIS 网站以外还有其他用途,则会发生这种情况。

  2. 您修改了迁移计划中的 IIS 部分,并添加了依赖于其他 Windows 功能的配置。(例如,Windows 身份验证依赖于 Windows 身份验证功能)。

target 部分

target 部分指定您使用的基础 Windows 映像(例如 1909)。您应该很少需要修改此字段。

images 部分

images 部分的每个子项都会指定一个输出映像。
在工件 zip 中,每个此类映像都有一个单独的子目录,其中包含该映像的 Dockerfiledeployment_spec.yaml(请参阅部署容器映像)。

name 字段

name 字段描述映像名称。它会影响映像子目录的名称以及工件中的 deployment_spec.yaml 文件。

probes 字段

probes 字段描述了映像的健康探测配置。如需详细了解 kubelet 探测,请参阅配置活跃性、就绪性和启动探测

修改 IIS 健康探测

健康探测可以监控代管式容器的停机时间和就绪状态。健康探测监控有助于减少迁移后的容器的停机时间,并更好地进行监控。

未知的健康状况可能导致可用性降级、误报的可用性监控以及潜在的数据丢失。如果没有健康状况探测,kubelet 只能假设容器的健康状况并可能将流量发送到尚未就绪的容器实例。如果实例未准备就绪,可能会导致流量丢失。Kubelet 可能也无法检测到处于冻结状态的容器,并将不会重启容器。

健康探测通过在容器启动时运行小型脚本语句来执行。该脚本会在每个周期检查成功条件(由使用的探测类型定义)。周期由迁移计划中的 periodSeconds 字段定义。您可以在自定义迁移计划时手动定义这些探测。

有三种类型的探测可以配置。所有探测都是探测 v1 核心参考文档中定义的探测 v1 核心,并且与容器 v1 核心的相应字段共享相同的功能。

  • * 活跃性探测:活跃性探测用于了解何时重启容器。

  • 就绪性探测:就绪性探测用于了解容器何时准备好开始接受流量。如需仅在探测成功时开始将流量发送到 Pod,请指定就绪性探测。就绪性探测的作用可能类似于活跃性探测。但是,就绪性探测表示 Pod 会在未收到任何流量的情况下启动,并且仅在探测成功后开始接收流量。

  • 启动探测:kubelet 使用启动探测来了解容器应用何时启动。如果配置了此探测,在它成功之前,它会停用活跃性和就绪性检查,以确保这些探测不会干扰应用启动。

发现后,探测配置将添加到迁移计划中。探测可以在其默认配置中使用,如以下示例所示。默认配置使用 exec 命令执行活跃性和就绪性探测。两者都使用名为 probe.ps1 的 PowerShell 脚本,该脚本调用 IIS 命令行工具 appcmd 来检查 IIS 网站的状态。

探测默认处于停用状态,如需启用探测,请将 enabled 标志设置为 true

images:
name: IMAGE_NAME
      probes:
        enabled: false
        livenessProbe:
            probehandler:
                exec:
                    command:
                        - powershell.exe
                        - C:\m4a\probe.ps1
            initialdelayseconds: 0
            timeoutseconds: 1
            periodseconds: 10
            successthreshold: 1
            failurethreshold: 3
            terminationgraceperiodseconds: null
        readinessProbe:
            probehandler:
                exec:
                    command:
                        - powershell.exe
                        - C:\m4a\probe.ps1
            initialdelayseconds: 0
            timeoutseconds: 1
            periodseconds: 10
            successthreshold: 1
            failurethreshold: 3
            terminationgraceperiodseconds: null

windowsServices 部分

迁移期间创建的 Windows 容器会运行并监控单项 Windows IIS 服务。但是,某些工作负载可能需要运行其他服务(包括数据库、日志记录机制、代理等)才能正常运作。

如需在迁移的容器中运行其他服务,请将条目添加到 windowsServices 部分,并复制 useractions 部分中必要的二进制文件。

version: v1
globalSettings:
    target:
       …
    globalIIS:
    …
images:
  - name: migrated-image-zgwb2
    workloads:
    sites:
      site:
        - applications:
          ...
          bindings:
          - port: 80
            protocol: http
          name: Default Web Site
          …
    windowsServices:
    - MyService
    useractions:
      files:
        - source: C:\Program Files\MyService
          target: C:\Program Files\MyService
      registry:
        currentcontrolset:
          - key: services\MyService

useractions 部分

useractions 部分指定您可能想要迁移的其他文件和注册表项。

例如:

      useractions:
        files:
        - source: DRIVE:\FOLDER-OR-FILE-PATH
          target: DRIVE:\FOLDER-OR-FILE-PATH
        - source: C:\myfolder
          target: C:\myfolder
        - source: D:\myfile
          target: D:\myfile
        - source: D:\myfile
          target: C:\myfile
        ...
        registry:
          currentcontrolset:
          - path: KEY
          ...
          software:
          - path: KEY
          ...

currentcontrolsetsoftware 指定的路径是 HKEY_LOCAL_MACHINE\System\CurrentControlSet 注册表 hiveHKEY_LOCAL_MACHINE\Software 注册表 hive 中的键。

修改 useractions 部分

默认情况下,复制到该映像的唯一文件是指定映像中站点的虚拟目录。
如果您的代码或配置从此目录外部导入文件,则应将它们添加到 useractions 部分中。
此外,您还应通过修改 useractions registry 部分来添加代码依赖的所有注册表值。

IIS 相关设置分为与特定站点相关的设置(属于映像规范的一部分)和与所有站点相关的设置(在 gloabalIis 部分后面)。

sites 部分

sites 部分描述迁移到特定映像的站点。同一站点可以包含在多个映像中。

如果您想使用 Cloud Load Balancing、Ingress 或 Anthos Service Mesh 处理 SSL 配置,则需要将 protocol 设置为 http

sites:
  site:
  - applications:
    - path: /
      virtualdirectories:
        - path: /
          physicalpath: '%SystemDrive%\inetpub\wwwroot'
          bindings:
          - port: 8080
            protocol: http
          name: Default Web Site

apppools 部分

apppools 部分描述在所迁移 pod 上创建的应用池

identitytype 字段将应用池的 IIS 身份指定为 ApplicationPoolIdentity(默认值)、NetworkServiceLocalSystemLocalService

如需了解详情,请参阅了解 IIS 中的身份应用池身份

以下是包含 identitytype 的示例迁移计划:

migrationPlan:
    applications:
      iis:
        applicationhost:
          apppools:
          - name: DefaultAppPool
            # Allowed values include: ApplicationPoolIdentity (default), NetworkService, LocalSystem, LocalService
            identitytype="NetworkService"
          - managedruntimeversion: v4.0
            name: .NET v4.5 Classic
          - managedruntimeversion: v4.0
            name: .NET v4.5

当您执行迁移计划以生成容器工件时,Migrate to Containers 会根据 identitytype 字段设置自动添加必要的 Dockerfile 指令。

例如,如果将 identitytype 设置为 NetworkService,则指令采用以下格式:

RUN c:\windows\system32\inetsrv\appcmd.exe set apppool \"DefaultAppPool\" \"/-processModel.identityType:NetworkService\";

Migrate to Containers 会根据目标 identitytype 以及针对 IUSR 内置用户,自动将读取 ACL 指令添加到该网站的文件夹。对于通过继承或明确指定原始应用账号的应用文件系统项,这是自动完成的。

如需了解详情,请参阅设置 ACL

enablegmsa 字段

enablegmsa 字段是迁移计划中的语法糖。它是覆盖应用池的 identity 字段的快捷方式。

支持的 enablegmsa 字段值为:

  • auto(默认模式):如果 Migrate to Containers 确定其当前配置不被接受,则使用迁移的容器以使用 gMSA。
  • all:务必将已迁移的容器转换为使用 gMSA,并忽略 identitytype 的设置。在这种情况下,始终将 identitytype 解释为 NetworkService

以下是包含 enablegmsa 的示例迁移计划:

migrationPlan:
    applications:
      iis:
        # Allowed values include: auto (default), all
        enablegmsa: auto|all

如需了解详情,请参阅将应用配置为使用 gMSA

连接字符串

连接字符串定义了从迁移后的容器工作负载到 .NET Framework 数据提供商的连接。

Migrate to Containers 支持站点范围和全局范围内的连接字符串。

如需向站点添加连接字符串,请修改迁移计划中的 site 定义以设置 connectionstrings 属性:

sites:
  site:
    # Add the site connection strings here.
    connectionstrings:
    - name: connectionname1
      providername: System.Data.SqlClient
      connectionstring: Database=connectedDB1;Password=Welcome1;User=admin;
    - name: connectionname2
      providername: System.Data.OleDb
      connectionstring: Database=connectedDB2;Password=Welcome2;User=admin;
  - applications:
    - path: /
      virtualdirectories:
      ...

如需向全局范围添加连接字符串(使其可供所有站点访问),请直接在 globalIis 后面修改连接字符串:

globalIis:
  enablegmsa: auto
  connectionStrings:
  connectionstring:
    - name: connectionname3
      providername: System.Data.SqlClient
      connectionstring: Database=connectedDB3;Password=Welcome3;User=admin;
  applicationhost:
      ...

其中:

  • name 指定连接名称。
  • providername 可用于指定数据提供商的类型。Migrate to Containers 仅支持 System.Data.SqlClient 值。支持 .NET Framework 数据提供商:
    • System.Data.SqlClient
    • System.Data.OleDb
    • System.Data.Odbc
    • System.Data.OracleClient
  • connectionstring 指定用于连接到数据提供商的连接字符串

修改连接字符串部分

Migrate to Containers 会自动将在迁移后的虚拟机中检测到的连接字符串复制到迁移计划。

部分连接字符串可能无法检测到,应按照上文所述修改迁移计划来添加。(例如,如果连接字符串位于 applicationhost.config 文件的加密部分中)。

如需有关如何确定要将哪些连接字符串添加到迁移计划的指导信息,请参阅 Microsoft 文档中的在运行时检索连接字符串

连接字符串外部依赖项

  • 连接字符串可以包含依赖项,例如对文件的引用或对与站点关联的某个 Windows 用户的引用。您可以向迁移计划添加自定义用户操作,以复制文件系统中的额外文件。手动修改 Dockerfile 以添加 Windows 用户。
  • 连接字符串可以包含依赖项,例如对外部数据源的引用。必须手动迁移这些依赖项,以确保迁移后的容器工作负载可以访问数据源。

security 部分

security 部分包含身份验证和授权子部分。

  • Windows 身份验证用于验证 Active Directory 用户。
  • Windows 授权是一种机制,用于指定允许哪些用户对 IIS 网站拥有哪些类型的访问权限。访问权限类型是 HTTP 动词(POST、GET、PUT、PATCH、DELETE)。

与连接字符串类似,如需为所有站点设置授权或身份验证,请修改 globalIis,如以下示例所示。如需为特定站点设置授权或身份验证,请修改相应的站点元素。

globalIis:
    security:
      authentication:
        windowsAuthentication:
          providers:
          - NTLM
      authorization:
        - add:
          user:John
          access:
          role:
         - remove:
              user:Jane
              access: GET
              role: 
            ...

其中:

  • providers 指定您的安全协议的提供方。
  • user 指定用户名。
  • access 指定用户的权限。访问权限类型是 HTTP 动词(POST、GET、PUT、PATCH、DELETE)。
  • role 指定特定权限角色。

后续步骤