自訂 Windows IIS 服務的遷移計畫
查看在建立遷移作業時填入的遷移計畫檔案。您可以在執行遷移作業前自訂這個值。遷移計畫的詳細資料可用於從來源 VM 中擷取工作負載容器構件。
本節將說明遷移計畫的內容,以及您在執行遷移作業前,可能會考慮採用的客製化類型,並產生部署構件。
事前準備
本文假設您已建立遷移計畫,並取得產生的遷移計畫檔案。
遷移計畫結構
以下是完整的遷移計畫結構。接下來的章節將討論這個結構、說明各個部分的功能,以及如何修改。
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
部分說明瞭在這個 VM 中執行 IIS 網站的 Pod 的基本需求。探索程序會在來源 VM 中搜尋一般設定,並使用這些設定填入這個部分。這些設定包含特定圖片設定中的欄位 (如以下各節所述),並同時影響所有圖片。
image
段
globalSettings
後方的 image
部分會列出要在 Pod 上安裝的 Windows 功能。探索程序會將原始 VM 中所有 Windows 功能填入這個部分,並可安裝在 Windows 容器上。
msvcRuntimes
段
遷移應用程式時,應用程式可能會依附於特定版本的 Microsoft Visual C++ 執行階段 (MSVCRT)。「遷移至容器」會自動偵測來源 VM 上安裝的執行階段,並將這些執行階段納入遷移計畫。
您可以新增或移除 msvcRuntimes
的會員,修改遷移計畫中的執行階段清單:
完整的可能值清單如下: (2015 年執行階段也支援 2017、2019 和 2022 年執行階段)
msvcRuntimes:
- MSVC2012_x64
- MSVC2013_x64
- MSVC2015_x64
- MSVC2012_x86
- MSVC2013_x86
- MSVC2015_x86
pathEnvVarAdditionalEntries
段
Windows IIS 應用程式可能會有非預設的 PATH
環境變數項目,系統會在來源 VM 上自動偵測這些項目,並納入遷移計畫。您可以編輯 pathEnvVarAdditionalEntries
的成員來修改 PATH
環境變數:
pathEnvVarAdditionalEntries:
- "C:\\myDllsFolder"
- "C:\\ProgramData\\SomeSoftware"
編輯圖片部分
您可能會在下列情況下編輯 image
部分:
遷移的網站不需要部分建議功能。如果來源 VM 除了代管 IIS 網站之外還有其他用途,就會發生這種情況。
您修改了遷移計畫中的 IIS 部分,並新增了依賴其他 Windows 功能的設定。(例如,Windows 驗證功能取決於 Windows 驗證功能)。
target
段
target
區段會指定您使用的 Windows 基礎映像檔 (例如 1909)。您不太需要編輯這個欄位。
images
段
images
區段的每個子項目都會指定單一輸出圖片。
在構件 ZIP 檔案中,每個這類映像檔都有一個獨立的子目錄,以及專屬的 Dockerfile
和 deployment_spec.yaml
(請參閱「部署容器映像檔」)。
name
欄位
name
欄位會說明圖片名稱。這會影響圖片子目錄的名稱和構件中的 deployment_spec.yaml
檔案。
probes
欄位
probes
欄位會說明映像檔的健康檢查設定。如要進一步瞭解 kubelet 探測功能,請參閱「設定有效性、就緒性和啟動探測功能」。
編輯 IIS 健康狀態探測
健康檢查探針可監控受管理容器的停機時間和就緒狀態。健康探針監控可減少遷移容器的停機時間,並提供更完善的監控功能。
不明的健康狀態可能會導致可用性降低、可用性監控出現誤報,以及潛在的資料遺失。如果沒有健康檢查,kubelet 只能假設容器的健康狀態,並可能將流量傳送至尚未就緒的容器執行個體。如果執行個體尚未準備就緒,可能會導致流量流失。Kubelet 也可能不會偵測到處於凍結狀態的容器,並且不會重新啟動這些容器。
健康檢查探針會在容器啟動時執行小型指令碼陳述式。指令碼會在每個週期檢查成功的條件,這些條件由所用探針類型定義。在遷移計畫中,使用 periodSeconds
欄位定義期間。您可以在自訂遷移計畫時手動定義這些探針。
您可以設定三種類型的探針。所有探針都是在 探針 v1 核心參考資料中定義的探針 v1 核心,並與 容器 v1 核心的對應欄位共用相同的函式。
*有效性探測:有效性探測可用於瞭解何時應重新啟動容器。
Readiness 探測:Readiness 探測可用於瞭解容器何時可開始接收流量。如要等到探測成功後才開始傳送流量至 pod,請指定就緒探測。readiness 探測可能會與 liveness 探測類似。不過,就緒探測會指出 pod 在啟動時不會接收任何流量,只有在探測成功後才會開始接收流量。
啟動探測:kubelet 會使用啟動探測,瞭解容器應用程式何時啟動。如果設定了這類探針,它會在成功前停用有效性和就緒性檢查,確保這些探針不會干擾應用程式啟動。
探索完成後,探針設定會新增至遷移計畫。探針可用於預設設定,如以下範例所示。預設設定會使用 exec
指令進行 liveness 和 readiness 探測。兩者都使用名為 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 服務。不過,某些工作負載可能需要執行額外服務 (包括資料庫、記錄機制、Proxy 等),才能正常運作。
如要在已遷移的容器中執行其他服務,請在 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 ...
為 currentcontrolset
和 software
指定的路徑,是 HKEY_LOCAL_MACHINE\System\CurrentControlSet
登錄檔巢狀結構或 HKEY_LOCAL_MACHINE\Software
登錄檔巢狀結構中的鍵。
編輯 useractions
部分
根據預設,只有指定圖像中網站的虛擬目錄會複製到圖像。
如果程式碼或設定會從這個目錄外匯入檔案,請將檔案新增至 useractions
部分。
此外,您必須編輯 useractions
registry
部分,才能新增程式碼所依賴的任何登錄值。
與 IIS 相關的設定
IIS 相關設定分為與特定網站相關的設定 (屬於圖片規格),以及與所有網站相關的設定 (位於 gloabalIis
部分之後)。
sites
段
「網站」部分會說明遷移至特定映像檔的網站。多張圖片可能會包含相同的網站。
如果您想使用 Cloud Load Balancing、Ingress 或 Cloud 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
(預設)、NetworkService
、LocalSystem
或 LocalService
。
詳情請參閱「瞭解 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
執行遷移計畫以產生容器構件時,「遷移至容器」會根據 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
(預設):如果「遷移至容器」判定目前的設定不允許,則將已遷移的容器轉換為使用 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
會指定用於連線至資料提供者的連線字串。
編輯連線字串部分
遷移至容器會自動將在遷移 VM 中偵測到的連結字串複製到遷移計畫。
系統可能無法偵測到部分連結字串,因此您應按照上述方式編輯遷移計畫,新增這些字串。(例如,如果連線字串位於 applicationhost.config
檔案的加密部分)。
如要瞭解如何判斷要將哪些連線字串新增至遷移計畫,請參閱 Microsoft 說明文件中的「在執行階段擷取連線字串」。
連線字串外部依附元件
- 連線字串可能包含依附元件,例如對網站相關檔案或 Windows 使用者的參照。您可以將自訂使用者動作新增至遷移計畫,以便在檔案系統中複製額外檔案。手動編輯 Dockerfile 來新增 Windows 使用者。
- 連線字串可能包含依附元件,例如外部資料來源的參照。這些依附元件必須手動遷移,確保遷移的容器工作負載可存取資料來源。
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
表示特定權限角色。
後續步驟
- 瞭解如何執行遷移作業。