教學課程:在 Azure Kubernetes Service (AKS) 中升級 KubernetesTutorial: Upgrade Kubernetes in Azure Kubernetes Service (AKS)

依循應用程式和叢集的生命週期,您可能會想要升級至 Kubernetes 的最新可用版本,並使用新功能。As part of the application and cluster lifecycle, you may wish to upgrade to the latest available version of Kubernetes and use new features. 使用 Azure CLI 可以升級 Azure Kubernetes Service (AKS) 叢集。An Azure Kubernetes Service (AKS) cluster can be upgraded using the Azure CLI.

在本教學課程 (七個章節的第七部分) 中升級了 Kubernetes 叢集。In this tutorial, part seven of seven, a Kubernetes cluster is upgraded. 您會了解如何:You learn how to:

  • 識別目前和可用的 Kubernetes 版本Identify current and available Kubernetes versions
  • 升級 Kubernetes 節點Upgrade the Kubernetes nodes
  • 驗證升級成功Validate a successful upgrade

開始之前Before you begin

在先前的教學課程中,已將應用程式封裝為容器映像。In previous tutorials, an application was packaged into a container image. 此映像已上傳至 Azure Container Registry,而您已建立 AKS 叢集。This image was uploaded to Azure Container Registry, and you created an AKS cluster. 接著已將應用程式部署至 AKS 叢集。The application was then deployed to the AKS cluster. 如果您尚未完成這些步驟,而且想要跟著做,請從教學課程 1 – 建立容器映像開始。If you have not done these steps, and would like to follow along, start with Tutorial 1 – Create container images.

在本教學課程中,您必須執行 Azure CLI 2.0.53 版或更新版本。This tutorial requires that you are running the Azure CLI version 2.0.53 or later. 執行 az --version 以尋找版本。Run az --version to find the version. 如果您需要安裝或升級,請參閱安裝 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

取得可用的叢集版本Get available cluster versions

在升級叢集之前,請使用 az aks get-upgrades 命令檢查哪些 Kubernetes 版本可進行升級:Before you upgrade a cluster, use the az aks get-upgrades command to check which Kubernetes releases are available for upgrade:

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

在下列範例中,目前的版本是 1.9.11,可用版本則顯示於 [升級] 資料行下方。In the following example, the current version is 1.9.11, and the available versions are shown under the Upgrades column.

Name     ResourceGroup    MasterVersion    NodePoolVersion    Upgrades
-------  ---------------  ---------------  -----------------  --------------
default  myResourceGroup  1.9.11           1.9.11             1.10.8, 1.10.9

升級叢集Upgrade a cluster

為了將中斷執行中應用程式的情況降到最低,系統會仔細地隔離並清空 AKS 節點。To minimize disruption to running applications, AKS nodes are carefully cordoned and drained. 在此流程中,會執行下列步驟:In this process, the following steps are performed:

  1. Kubernetes 排程器會防止在要升級的節點上排程其他 Pod。The Kubernetes scheduler prevents additional pods being scheduled on a node that is to be upgraded.
  2. 節點上的執行中 Pod 會排程於叢集中的其他節點上。Running pods on the node are scheduled on other nodes in the cluster.
  3. 系統會建立一個節點來執行最新的 Kubernetes 元件。A node is created that runs the latest Kubernetes components.
  4. 當新節點準備好並加入叢集時,Kubernetes 排程器會開始在其上執行 Pod。When the new node is ready and joined to the cluster, the Kubernetes scheduler begins to run pods on it.
  5. 舊節點會遭到刪除,而叢集中的下一個節點會開始隔離和清空流程。The old node is deleted, and the next node in the cluster begins the cordon and drain process.

使用 az aks upgrade 命令升級 AKS 叢集。Use the az aks upgrade command to upgrade the AKS cluster. 下列範例會將叢集升級至 Kubernetes 1.10.9 版。The following example upgrades the cluster to Kubernetes version 1.10.9.

注意

您一次只能升級一個次要版本。You can only upgrade one minor version at a time. 例如,您可以從 1.9.11 升級至 1.10.9,但無法直接從 1.9.6 升級至 1.11.xFor example, you can upgrade from 1.9.11 to 1.10.9, but cannot upgrade from 1.9.6 to 1.11.x directly. 若要從 1.9.11 升級至 1.11.x,必須先從 1.9.11 升級至 1.10.x,然後再執行從 1.10.x1.11.x 的升級。To upgrade from 1.9.11 to 1.11.x, first upgrade from 1.9.11 to 1.10.x, then perform another upgrade from 1.10.x to 1.11.x.

az aks upgrade --resource-group myResourceGroup --name myAKSCluster --kubernetes-version 1.10.9

下列扼要的範例輸出顯示 kubernetesVersion 現在回報 1.10.9The following condensed example output shows the kubernetesVersion now reports 1.10.9:

{
  "agentPoolProfiles": [
    {
      "count": 3,
      "maxPods": 110,
      "name": "nodepool1",
      "osType": "Linux",
      "storageProfile": "ManagedDisks",
      "vmSize": "Standard_DS1_v2",
    }
  ],
  "dnsPrefix": "myAKSClust-myResourceGroup-19da35",
  "enableRbac": false,
  "fqdn": "myaksclust-myresourcegroup-19da35-bd54a4be.hcp.eastus.azmk8s.io",
  "id": "/subscriptions/<Subscription ID>/resourcegroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/myAKSCluster",
  "kubernetesVersion": "1.10.9",
  "location": "eastus",
  "name": "myAKSCluster",
  "type": "Microsoft.ContainerService/ManagedClusters"
}

驗證升級Validate an upgrade

使用 az aks show 命令確認升級是否成功,如下所示:Confirm that the upgrade was successful using the az aks show command as follows:

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

下列範例輸出顯示 AKS 叢集執行的是 KubernetesVersion 1.10.9The following example output shows the AKS cluster runs KubernetesVersion 1.10.9:

Name          Location    ResourceGroup    KubernetesVersion    ProvisioningState    Fqdn
------------  ----------  ---------------  -------------------  -------------------  ----------------------------------------------------------------
myAKSCluster  eastus      myResourceGroup  1.10.9               Succeeded            myaksclust-myresourcegroup-19da35-bd54a4be.hcp.eastus.azmk8s.io

刪除叢集Delete the cluster

由於本教學課程是整個系列的最後一個部分,因此,您可以刪除 AKS 叢集。As this tutorial is the last part of the series, you may want to delete the AKS cluster. Kubernetes 節點會在 Azure 虛擬機器 (VM) 上執行,所以即使您不使用叢集,這些節點仍會繼續產生費用。As the Kubernetes nodes run on Azure virtual machines (VMs), they continue to incur charges even if you don't use the cluster. 請使用 az group delete 命令來移除資源群組、容器服務以及所有相關資源。Use the az group delete command to remove the resource group, container service, and all related resources.

az group delete --name myResourceGroup --yes --no-wait

注意

當您刪除叢集時,不會移除 AKS 叢集所使用的 Azure Active Directory 服務主體。When you delete the cluster, the Azure Active Directory service principal used by the AKS cluster is not removed. 如需有關如何移除服務主體的步驟,請參閱 AKS 服務主體的考量和刪除For steps on how to remove the service principal, see AKS service principal considerations and deletion.

後續步驟Next steps

在本教學課程中,您已在 AKS 叢集中升級 Kubernetes。In this tutorial, you upgraded Kubernetes in an AKS cluster. 您已了解如何︰You learned how to:

  • 識別目前和可用的 Kubernetes 版本Identify current and available Kubernetes versions
  • 升級 Kubernetes 節點Upgrade the Kubernetes nodes
  • 驗證升級成功Validate a successful upgrade

跟著此連結以深入了解 AKS。Follow this link to learn more about AKS.