適用於:✔️ Fleet Manager ✔️ 含中樞叢集的 Fleet Manager
及時且安全地更新叢集是平台管理者的重要關注點。 當你採用 Azure Kubernetes Fleet Manager 的 Update Runs 和 Strategies 時,你可以使用自動升級設定檔,在新的 Kubernetes 版本或節點映像版本發行時,自動執行更新執行作業。
本文說明如何使用自動升級設定檔,在 Azure Kubernetes Service (AKS) 發行新的 Kubernetes 版本或節點映像版本時,自動建立並執行更新執行作業。
附註
- 計畫性維護時段: 自動升級觸發的更新會執行您在 AKS 叢集層級設定的 計畫維護時段 。 詳情請參閱 跨多個成員叢集的計畫維護 。
- AKS 平台發起的升級: 若成員叢集在平台支援寬限期後仍維持在不支援的 Kubernetes 版本,AKS 可直接在您的艦隊自動升級設定檔、更新策略或維護期間之外升級該叢集。 請參閱 AKS 平台發起的升級,了解如何將成員叢集置於 Fleet 協調流程之下。
開始之前
- 請閱讀自動 升級設定檔的概念概述,裡面說明本指南中提到的配置。
- 設定一個包含一個或多個成員叢集的 Fleet Manager。 如果你沒有,請按照 快速入門 程序建立艦隊管理員,並加入 AKS 叢集成為成員。
- 設定更新策略。 請參考 更新操作文章中的說明。 使用 Azure CLI 時,您需要更新策略資源識別碼,才能與自動升級設定檔搭配使用。
請將以下環境變數設定為 Azure CLI 指令中使用的變數:
export GROUP=<resource-group> export FLEET=<fleet-name> export AUTOUPGRADEPROFILE=<upgrade-profile-name> # Optional export STRATEGYID=<strategy-id> export CLUSTER=<aks-cluster-name>安裝最新版的 Azure CLI。 若要安裝或升級,請參閱安裝 Azure CLI。
安裝最新
fleet嘅 Azure CLI 擴充功能。 使用az extension add指令安裝擴充功能。az extension add --name fleet請使用指令
az extension update更新到擴充功能最新版本。az extension update --name fleet
安裝最新版的 Azure CLI。 若要安裝或升級,請參閱安裝 Azure CLI。 你可以使用 Azure CLI 來驗證 Terraform 建立的自動升級設定檔。
安裝最新
fleet嘅 Azure CLI 擴充功能。 使用az extension add指令安裝擴充功能。az extension add --name fleet請使用指令
az extension update更新到擴充功能最新版本。az extension update --name fleet本文所用的 Terraform 範例建立了自己的資源群組和 Azure Kubernetes Fleet Manager,且不會以 Fleet 成員身份加入任何 AKS 叢集。 若要在實際的更新執行中驗證產生的自動升級設定檔,請在套用範例後,將現有的 AKS 叢集作為成員加入至機群中 如需詳細資訊,請參閱快速入門。
附註
依據所選的自動升級通道和節點映像選項,從節點集區快照集建立代理程式集區的叢集會受到下列影響:
-
節點映像通道:節點映像會升級為 Fleet Manager 所指定的版本。 已從 Agent 集區移除對快照 (
creationData) 的參考。 -
穩定、快速或目標 Kubernetes 次要版本通道,且節點映像設定為:
-
一致性映像:節點映像會升級至 Fleet Manager 所決定的版本。 已從 Agent 集區移除對快照 (
creationData) 的參考。 -
最新映像:代理程式池會保留對快照(
creationData)的參考,且節點映像不會被修改。
-
一致性映像:節點映像會升級至 Fleet Manager 所決定的版本。 已從 Agent 集區移除對快照 (
欲了解更多資訊,請參閱 「了解節點映像升級與快照」。
建立自動升級設定檔
使用 az fleet autoupgradeprofile create 指令建立自動升級設定檔。
你可以透過包含 --disabled 旗標與 az fleet autoupgradeprofile create 指令來停用自動更新設定檔。 若要重新啟用已停用的自動升級設定檔,請重新執行 az fleet autoupgradeprofile create 命令,但不要加上 --disabled 旗標。
附註
停用自動升級設定檔不會影響任何正在進行中的更新作業。 不過,這個流程會在您重新啟用設定檔之前停止產生新的更新。
穩定通道 Kubernetes 更新
更新至最新版本的 Kubernetes 補丁,針對次要版本 N-1,其中 N 是最新支援的次要版本。
逐一更新成員群組
依序 az fleet autoupgradeprofile create 使用指令更新成員叢集。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--channel Stable
透過現有的更新策略更新成員叢集
透過現有的更新策略來更新成員叢集。 使用 az fleet autoupgradeprofile create 指令,並將 --update-strategy-id 參數設為現有更新策略的 ID。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--update-strategy-id $STRATEGYID \
--channel Stable
透過現有的更新策略與一致的節點映像來更新成員叢集
利用現有的更新策略更新成員叢集,並確保每個 Azure 區域使用相同的節點映像版本。 使用 az fleet autoupgradeprofile create 命令,並將 --node-image-selection 參數設為 Consistent。 所有成員叢集都會執行相同的節點映像版本。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--update-strategy-id $STRATEGYID \
--channel Stable \
--node-image-selection Consistent
透過使用現有的更新策略與最新的節點映像來更新成員叢集
透過現有的更新策略更新成員叢集,並確保每個 Azure 區域使用最新的可用節點映像版本。 使用 az fleet autoupgradeprofile create 命令,並將 --node-image-selection 參數設為 Latest。 成員叢集可以執行多個節點映像版本。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--update-strategy-id $STRATEGYID \
--channel Stable \
--node-image-selection Latest
節點映像通道更新
使用包含安全性修補和錯誤修正的新近套用修補程式的機器映像檔來更新節點。
逐一更新節點映像檔
使用 az fleet autoupgradeprofile create 指令依序更新成員叢集的節點映像。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--channel NodeImage
透過現有的更新策略更新節點映像檔
利用現有的更新策略更新成員叢集的節點映像。 使用指令 az fleet autoupgradeprofile create ,並將參數設 --update-strategy-id 為現有更新策略的 ID。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--update-strategy-id $STRATEGYID \
--channel NodeImage
Target Kubernetes 小版本更新
使用 --target-kubernetes-version 參數更新至指定的目標 Kubernetes 次要版本。 請以 {主要版本}.{次要版本} 格式提供版本(例如 1.33)。 Fleet Manager 自動升級會在補丁可用時自動將成員叢集升級至指定目標版本的最新補丁版本。
這很重要
使用 Target Kubernetes 小版本 頻道時,請留意以下資訊:
- 您必須指定
--target-kubernetes-version參數。 這個參數不支援其他自動升級通道(Rapid、Stable、Node image 和 Security patch)。 - 長期支援(LTS)標誌
--long-term-support,僅在使用 Target Kubernetes 次版本 通道時可用。 對於其他頻道,請將此標記設為False。 - 你只能選擇 LTS Kubernetes 版本(N-2)來建立帶有
--long-term-support標記的自動升級設定檔。 為了讓艦隊自動升級在此情境下持續運作,請確保產生的更新執行中所有叢集都已啟用 LTS。 非 LTS 叢集會導致在遇到第一個非 LTS 叢集時更新執行失敗。 - 你無法將目標 Kubernetes 版本設定為 AKS 尚未釋出的未來 Kubernetes 版本。
將成員叢集更新為特定的 Kubernetes 次要版本
使用將--target-kubernetes-version參數設定為目標版本的指令,將成員叢集更新為特定的 Kubernetes 次要版本az fleet autoupgradeprofile create。 以下範例將成員叢集更新至 Kubernetes 版本 1.33。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--channel TargetKubernetesVersion \
--target-kubernetes-version "1.33"
將啟用 LTS 的成員叢集更新至特定的 Kubernetes 次版本
使用 az fleet autoupgradeprofile create 命令,將 --target-kubernetes-version 參數設為所需版本,並啟用 --long-term-support 旗標,即可將已啟用 LTS 的成員叢集更新至特定的 Kubernetes 次要版本。 以下範例將成員叢集更新至 Kubernetes 1.29 版本,並啟用 LTS。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--channel TargetKubernetesVersion \
--target-kubernetes-version "1.29" \
--long-term-support
安全修補通道更新
更新 Linux 節點並進行安全修正。 盡可能使用即時修補來套用更新。 否則,部署包含安全修補的新機器映像檔。
逐一更新節點的安全修補程式
使用 az fleet autoupgradeprofile create 指令依序更新成員叢集的節點映像。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--channel SecurityPatch
利用現有的更新策略更新節點並進行安全修補程式
利用現有的更新策略更新成員叢集的節點映像。 使用指令 az fleet autoupgradeprofile create ,並將參數設 --update-strategy-id 為現有更新策略的 ID。
az fleet autoupgradeprofile create \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--update-strategy-id $STRATEGYID \
--channel SecurityPatch
查看自動更新設定檔
自動升級設定檔是機群層級資源。 它們不會直接連接到單一的 AKS 叢集。 要判斷哪些設定檔可以更新你的 AKS 叢集,首先列出艦隊成員並確認這些叢集是否屬於艦隊。
az fleet member list \
--resource-group $GROUP \
--fleet-name $FLEET \
--query "[].{memberName:name,clusterResourceId:clusterResourceId}" \
--output table
請使用指令 az fleet autoupgradeprofile list 列出艦隊所有自動升級設定檔。
az fleet autoupgradeprofile list \
--resource-group $GROUP \
--fleet-name $FLEET \
--output table
使用 az fleet autoupgradeprofile show 指令顯示艦隊特定的自動升級設定檔。 檢查頻道、狀態和 updateStrategyId 輸出內容。
az fleet autoupgradeprofile show \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE
若 updateStrategyId 為空,設定檔會採用 逐一 更新順序,並依序納入 Fleet 的成員叢集。 若 updateStrategyId 包含資源識別碼,請顯示所參照的策略,以檢視用來決定所產生的更新執行作業包含哪些機群成員的階段、群組或成員選擇器。
PROFILE_STRATEGY_ID=$(az fleet autoupgradeprofile show \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE \
--query updateStrategyId \
--output tsv)
if [[ -n "$PROFILE_STRATEGY_ID" ]]; then
az fleet updatestrategy show \
--resource-group $GROUP \
--fleet-name $FLEET \
--name "${PROFILE_STRATEGY_ID##*/}"
fi
刪除自動升級設定檔
使用az fleet autoupgradeprofile delete命令來刪除現有的自動升級設定檔。 執行此指令後,系統會提示你確認刪除。 若要跳過確認並立即刪除該設定檔,請在指令中包含 --yes 。
az fleet autoupgradeprofile delete \
--resource-group $GROUP \
--fleet-name $FLEET \
--name $AUTOUPGRADEPROFILE
附註
刪除自動升級設定檔不會影響任何正在進行的更新。
建立自動升級設定檔
本節的 Terraform 範例建立了資源群組、一個 Azure Kubernetes 艦隊管理員(不含樞紐叢集)以及一個艦隊自動升級設定檔。 預設設定檔會使用帶有Latest節點影像選擇的Stable通道,並且已啟用。 將 auto_upgrade_channel、 node_image_selection、 auto_upgrade_disabled、 target_kubernetes_versionlong_term_support 和 變數設定為與前述頻道及選項相符。 樣本不設定更新策略,因此產生的設定檔總是使用 逐一 更新序列。
檢視 Terraform 程式碼
附註
本文的範例程式代碼位於 Azure Terraform GitHub 存放庫中。 查看包含 目前及先前版本 Terraform 測試結果的日誌檔案。
建立一個目錄來測試範例 Terraform 程式碼,並將其設為目前的目錄。
建立名為
providers.tf的檔案,並插入下列程序代碼:terraform { required_version = ">= 1.9.0" required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 4.0" } azapi = { source = "Azure/azapi" version = "~> 2.0" } random = { source = "hashicorp/random" version = "~> 3.0" } } } provider "azurerm" { features {} } provider "azapi" { }建立名為
variables.tf的檔案,並插入下列程序代碼:variable "location" { type = string description = "Azure region where the resource group and Fleet Manager are created." default = "eastus" } variable "resource_group_name" { type = string description = "Name of the resource group. If null, a unique name is generated." default = null } variable "fleet_name" { type = string description = "Name of the Azure Kubernetes Fleet Manager. If null, a unique name is generated." default = null } variable "auto_upgrade_profile_name" { type = string description = "Name of the Fleet auto-upgrade profile. If null, a unique name is generated." default = null } variable "auto_upgrade_channel" { type = string description = "Auto-upgrade channel used by the profile." default = "Stable" validation { condition = contains(["Rapid", "Stable", "NodeImage", "TargetKubernetesVersion"], var.auto_upgrade_channel) error_message = "Auto-upgrade channel must be one of: Rapid, Stable, NodeImage, TargetKubernetesVersion." } } variable "target_kubernetes_version" { type = string description = "Target Kubernetes version in major.minor format, for example 1.31. Required when auto_upgrade_channel is TargetKubernetesVersion; otherwise leave null." default = null validation { condition = var.target_kubernetes_version == null || can(regex("^[0-9]+\\.[0-9]+$", var.target_kubernetes_version)) error_message = "Target Kubernetes version must be in major.minor format, for example 1.31." } validation { condition = var.auto_upgrade_channel != "TargetKubernetesVersion" || var.target_kubernetes_version != null error_message = "Target Kubernetes version is required when auto_upgrade_channel is TargetKubernetesVersion." } } variable "node_image_selection" { type = string description = "Node image selection type. Latest uses the newest image per region; Consistent waits for the same image version across all member regions." default = "Latest" validation { condition = contains(["Latest", "Consistent"], var.node_image_selection) error_message = "Node image selection must be either Latest or Consistent." } } variable "auto_upgrade_disabled" { type = bool description = "Set to true to stop the profile from creating new automatic update runs. In-progress update runs aren't cancelled." default = false } variable "long_term_support" { type = bool description = "Whether the profile targets long-term support Kubernetes versions. Only supported on the TargetKubernetesVersion channel." default = false validation { condition = !var.long_term_support || var.auto_upgrade_channel == "TargetKubernetesVersion" error_message = "Long-term support can only be enabled when auto_upgrade_channel is TargetKubernetesVersion." } } variable "tags" { type = map(string) description = "Tags to apply to created resources." default = { environment = "demo" managed_by = "terraform" } }建立名為
main.tf的檔案,並插入下列程序代碼:resource "random_string" "suffix" { length = 5 lower = true numeric = true special = false upper = false } locals { resource_group_name = coalesce(var.resource_group_name, "rg-fleet-update-${random_string.suffix.result}") fleet_name = coalesce(var.fleet_name, "fleet-update-${random_string.suffix.result}") auto_upgrade_profile_name = coalesce(var.auto_upgrade_profile_name, "stable-profile-${random_string.suffix.result}") # targetKubernetesVersion is only valid on the TargetKubernetesVersion channel. auto_upgrade_properties = merge( { channel = var.auto_upgrade_channel disabled = var.auto_upgrade_disabled longTermSupport = var.long_term_support nodeImageSelection = { type = var.node_image_selection } }, var.auto_upgrade_channel == "TargetKubernetesVersion" ? { targetKubernetesVersion = var.target_kubernetes_version } : {} ) } resource "azurerm_resource_group" "example" { name = local.resource_group_name location = var.location tags = var.tags } resource "azurerm_kubernetes_fleet_manager" "example" { name = local.fleet_name location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name tags = var.tags } # autoUpgradeProfiles is only available on the preview API version, which requires schema validation to be disabled. resource "azapi_resource" "auto_upgrade_profile" { type = "Microsoft.ContainerService/fleets/autoUpgradeProfiles@2025-04-01-preview" name = local.auto_upgrade_profile_name parent_id = azurerm_kubernetes_fleet_manager.example.id schema_validation_enabled = false body = { properties = local.auto_upgrade_properties } }建立名為
outputs.tf的檔案,並插入下列程序代碼:output "resource_group_name" { description = "Name of the created resource group." value = azurerm_resource_group.example.name } output "fleet_manager_name" { description = "Name of the Azure Kubernetes Fleet Manager." value = azurerm_kubernetes_fleet_manager.example.name } output "fleet_manager_id" { description = "Resource ID of the Azure Kubernetes Fleet Manager." value = azurerm_kubernetes_fleet_manager.example.id } output "auto_upgrade_profile_name" { description = "Name of the Fleet auto-upgrade profile." value = azapi_resource.auto_upgrade_profile.name } output "auto_upgrade_profile_id" { description = "Resource ID of the Fleet auto-upgrade profile." value = azapi_resource.auto_upgrade_profile.id }將取樣
terraform.tfvars.example檔案複製到terraform.tfvars同一個目錄,然後編輯數值以符合自動升級通道、節點圖片選擇及其他你想要的選項。cp terraform.tfvars.example terraform.tfvars
初始化、驗證並套用設定
執行 terraform init 來初始化 Terraform 部署。 此指令會下載管理 Azure 資源所需的 Azure 提供者。
terraform init
執行 terraform fmt 來穩定格式化設定檔。
terraform fmt
執行 terraform valid 以確認設定檔在語法上是否有效。
terraform validate
執行 terraform plan 以建立執行計畫。
terraform plan -out main.tfplan
執行terraform apply指令將執行計劃套用至您的雲端基礎設施。
terraform apply main.tfplan
查看自動更新設定檔
從 Terraform 輸出中取得資源群組、Fleet Manager 和自動升級設定檔的名稱。
resource_group_name=$(terraform output -raw resource_group_name)
fleet_manager_name=$(terraform output -raw fleet_manager_name)
auto_upgrade_profile_name=$(terraform output -raw auto_upgrade_profile_name)
使用 az fleet autoupgradeprofile show 指令顯示自動升級設定檔的頻道、狀態及更新順序。
az fleet autoupgradeprofile show \
--resource-group $resource_group_name \
--fleet-name $fleet_manager_name \
--name $auto_upgrade_profile_name
範例未設定更新策略,因此輸出中的 updateStrategyId 為空,且設定檔會使用 One by one 更新順序,依序更新 Fleet 的成員叢集。 使用下列命令列出目前的 Fleet 成員。
az fleet member list \
--resource-group $resource_group_name \
--fleet-name $fleet_manager_name \
--output table
刪除自動升級設定檔
執行 terraform plan 並搭配 -destroy 旗標,以建立銷毀執行計畫。
terraform plan -destroy -out main.destroy.tfplan
執行 terraform apply 以套用銷毀計畫。
terraform apply main.destroy.tfplan
Warning
此指令會刪除自動升級設定檔、Azure Kubernetes Fleet Manager 以及此範例所建立的資源群組,而不僅僅是設定檔。 如果你以艦隊成員身份加入 AKS 集群,請先將他們移除艦隊成員身份。 在執行這個指令前,先確認資源群組中沒有你想保留的其他資源。
建立自動升級設定檔
更新至最新版本的 Kubernetes 補丁,針對次要版本 N-1,其中 N 是最新支援的次要版本。
在 Azure 入口網站 中,流覽至您的 Azure Kubernetes Fleet Manager 資源。
在服務選單中,在設定中選擇多叢集更新>、自動升級設定檔>+建立。
在 建立自動升級設定檔時,請設定以下選項:
- 在 自動升級細節中:
- 自動升級設定檔名稱:輸入自動升級設定檔的名稱。
- 狀態:選擇 啟用 或 停用。 發行新版本時,停用的自動升級設定檔不會觸發。
- 更新順序:選擇 「階段」 或 「逐一」。
- 在 自動升級觸發器中:
- 通道:選取穩定。
- 節點影像:選擇 「最新影像 」或 「一致影像」。
- 在 策略細節中:
- 如果您使用階段選擇了更新序列,請選擇現有的策略或建立新的策略。
- 在 自動升級細節中:
選取 [建立] 以建立自動升級設定檔。
查看自動更新設定檔
自動升級設定檔是機群層級資源。 它們不會直接連接到單一的 AKS 叢集。 要判斷哪些設定檔能更新你的 AKS 叢集,請確認這些叢集是否屬於艦隊,然後檢視艦隊的設定檔及其更新序列。
- 在 Azure 入口網站 中,流覽至您的 Azure Kubernetes Fleet Manager 資源。
- 在服務選單中選擇 艦隊成員,並確認你的 AKS 群組是否出現在成員列表中。
- 在 設定中,選擇 多叢集更新>自動升級設定檔。
- 選擇自動升級設定檔以查看頻道、狀態及更新順序。
- 若更新序列為 逐一更新,則配置檔會依序包含艦隊成員群集。 如果更新順序使用 階段,請檢視相關策略的階段、群組和成員選取器,以判斷產生的更新執行作業會納入哪些 Fleet 成員。
刪除自動升級設定檔
- 在 Azure 入口網站 中,流覽至您的 Azure Kubernetes Fleet Manager 資源。
- 在服務選單中,在 設定中選擇 多叢集更新>自動升級設定檔。
- 選擇你想刪除的個人檔案,然後選擇「 刪除>是 」以確認。
附註
刪除自動升級設定檔不會影響任何正在進行的更新。
驗證自動升級
自動升級僅在有新的 Kubernetes 或節點映像檔可用時進行。 觸發自動升級時,會建立連結的更新執行,因此您可以使用 管理更新執行 來查看自動升級的結果。
你也可以先檢查現有版本作為基準。
使用 --query 指令搭配 currentKubernetesVersion 參數,篩選 az aks show 屬性的輸出,以取得成員叢集目前的 Kubernetes 版本。
az aks show \
--resource-group $GROUP \
--name $CLUSTER \
--query currentKubernetesVersion
使用 --query 命令並搭配 nodeImageVersion 參數,依 az aks show 屬性篩選輸出,以取得成員叢集目前的節點映像版本。
az aks show \
--resource-group $GROUP \
--name $CLUSTER \
--query "agentPoolProfiles[].{name:name,mode:mode, nodeImageVersion:nodeImageVersion, osSku:osSku, osType:osType}"
當更新執行結束後,你可以重新執行這些指令並查看已部署的更新版本。
從自動更新設定檔產生更新執行
建立自動升級設定檔後,可能需要一段時間,新的 Kubernetes 或節點映像版本才能夠觸發自動升級來建立並執行更新作業。 自動升級允許你隨時透過指令 az fleet autoupgradeprofile generate-update-run 產生新的更新執行。 產生的更新執行是以目前 AKS 發佈的 Kubernetes 或節點映射版本為基礎。
欲了解更多如何從自動升級設定檔建立按需更新執行的資訊,請參見 「從自動升級設定檔產生更新執行」。