升级 Azure Kubernetes 服务 (AKS) 群集Upgrade an Azure Kubernetes Service (AKS) cluster

在 AKS 群集的生命周期中,经常需要升级到最新的 Kubernetes 版本。As part of the lifecycle of an AKS cluster, you often need to upgrade to the latest Kubernetes version. 必须应用最新的 Kubernetes 安全版本,或者通过升级来获取最新功能。It is important you apply the latest Kubernetes security releases, or upgrade to get the latest features. 本文演示如何在 AKS 群集中升级主组件或单个默认的节点池。This article shows you how to upgrade the master components or a single, default node pool in an AKS cluster.

对于使用多个节点池或 Windows Server 节点的 AKS 群集(当前在 AKS 中为预览版),请参阅升级 AKS 中的节点池For AKS clusters that use multiple node pools or Windows Server nodes (currently in preview in AKS), see Upgrade a node pool in AKS.

准备阶段Before you begin

本文要求运行 Azure CLI 2.0.65 或更高版本。This article requires that you are running the Azure CLI version 2.0.65 or later. 运行 az --version 即可查找版本。Run az --version to find the version. 如果需要进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

警告

AKS 群集升级会触发节点的隔离和排空。An AKS cluster upgrade triggers a cordon and drain of your nodes. 如果可用计算配额较低,则升级可能会失败。If you have a low compute quota available, the upgrade may fail. 有关详细信息,请参阅增加配额See increase quotas for more information.

检查是否有可用的 AKS 群集升级Check for available AKS cluster upgrades

若要检查哪些 Kubernetes 版本可用于群集,请使用 az aks get-upgrades 命令。To check which Kubernetes releases are available for your cluster, use the az aks get-upgrades command. 以下示例在名为 myResourceGroup 的资源组中检查是否有可供名为 myAKSCluster 的群集使用的升级:The following example checks for available upgrades to the cluster named myAKSCluster in the resource group named myResourceGroup:

az aks get-upgrades --resource-group myResourceGroup --name myAKSCluster --output table

备注

升级 AKS 群集时,不能跳过 Kubernetes 次要版本。When you upgrade an AKS cluster, Kubernetes minor versions cannot be skipped. 例如,允许从 1.12.x 升级到 1.13.x,或者从 1.13.x 升级到 1.14.x,但不允许从 1.12.x 升级到 1.14.x。For example, upgrades between 1.12.x -> 1.13.x or 1.13.x -> 1.14.x are allowed, however 1.12.x -> 1.14.x is not.

若要从 1.12.x 升级到 1.14.x,请先从 1.12.x 升级到 1.13.x,然后再从 1.13.x 升级到 1.14.x。To upgrade, from 1.12.x -> 1.14.x, first upgrade from 1.12.x -> 1.13.x, then upgrade from 1.13.x -> 1.14.x.

以下示例输出表明,群集可以升级到版本 1.13.9 和 1.13.10:The following example output shows that the cluster can be upgraded to versions 1.13.9 and 1.13.10:

Name     ResourceGroup     MasterVersion    NodePoolVersion    Upgrades
-------  ----------------  ---------------  -----------------  ---------------
default  myResourceGroup   1.12.8           1.12.8             1.13.9, 1.13.10

如果没有可用的升级,你将获得:If no upgrade is available, you will get:

ERROR: Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.

升级 AKS 群集Upgrade an AKS cluster

如果有一系列适用于 AKS 群集的版本,则可使用 az aks upgrade 命令进行升级。With a list of available versions for your AKS cluster, use the az aks upgrade command to upgrade. 在升级过程中,AKS 将向运行指定 Kubernetes 版本的群集添加一个新节点,然后仔细地一次隔离并清空一个旧节点,将对正在运行的应用程序造成的中断情况降到最低。During the upgrade process, AKS adds a new node to the cluster that runs the specified Kubernetes version, then carefully cordon and drains one of the old nodes to minimize disruption to running applications. 确认新节点运行应用程序 Pod 以后,就会删除旧节点。When the new node is confirmed as running application pods, the old node is deleted. 此过程会重复进行,直至群集中的所有节点都已升级完毕。This process repeats until all nodes in the cluster have been upgraded.

az aks upgrade \
    --resource-group myResourceGroup \
    --name myAKSCluster \
    --kubernetes-version KUBERNETES_VERSION

升级群集需要几分钟时间,具体取决于有多少节点。It takes a few minutes to upgrade the cluster, depending on how many nodes you have.

备注

允许群集升级完成的总时间。There is a total allowed time for a cluster upgrade to complete. 此时间是通过取 10 minutes * total number of nodes in the cluster 的乘积来计算的。This time is calculated by taking the product of 10 minutes * total number of nodes in the cluster. 例如,在 20 节点群集中,升级操作必须在 200 分钟内成功,否则 AKS 将使操作失败,以避免出现无法恢复的群集状态。For example in a 20 node cluster, upgrade operations must succeed in 200 minutes or AKS will fail the operation to avoid an unrecoverable cluster state. 若要在升级失败时恢复,请在达到超时值后重试升级操作。To recover on upgrade failure, retry the upgrade operation after the timeout has been hit.

若要确认升级是否成功,请使用 az aks show 命令:To confirm that the upgrade was successful, use the az aks show command:

az aks show --resource-group myResourceGroup --name myAKSCluster --output table

以下示例输出表明群集现在运行 1.13.10:The following example output shows that the cluster now runs 1.13.10:

Name          Location    ResourceGroup    KubernetesVersion    ProvisioningState    Fqdn
------------  ----------  ---------------  -------------------  -------------------  ---------------------------------------------------------------
myAKSCluster  chinaeast2      myResourceGroup  1.13.10               Succeeded            myaksclust-myresourcegroup-19da35-90efab95.hcp.chinaeast2.cx.prod.service.azk8s.cn

后续步骤Next steps

本文演示了如何升级现有的 AKS 群集。This article showed you how to upgrade an existing AKS cluster. 若要详细了解如何部署和管理 AKS 群集,请参阅相关教程系列。To learn more about deploying and managing AKS clusters, see the set of tutorials.