{"id":4681,"date":"2023-03-14T08:49:26","date_gmt":"2023-03-14T15:49:26","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=4681"},"modified":"2023-03-14T08:49:28","modified_gmt":"2023-03-14T15:49:28","slug":"how-to-upgrade-kubernetes-in-azure-kubernetes-service-aks","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=4681","title":{"rendered":"How to Upgrade Kubernetes in Azure Kubernetes Service (AKS)"},"content":{"rendered":"\n<p>As part of the application and cluster lifecycle, you may want to upgrade to the latest available version of Kubernetes. You can upgrade your Azure Kubernetes Service (AKS) cluster by using the Azure CLI, Azure PowerShell, or the Azure portal.<\/p>\n\n\n\n<p>In this tutorial, part seven of seven, you learn how to:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Identify current and available Kubernetes versions.<\/li><li>Upgrade your Kubernetes nodes.<\/li><li>Validate a successful upgrade.<\/li><\/ul>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#before-you-begin\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"before-you-begin\">Before you begin<\/h2>\n\n\n\n<p>In previous tutorials, an application was packaged into a container image, and this container image was uploaded to Azure Container Registry (ACR). You also created an AKS cluster. The application was then deployed to the AKS cluster. If you have not done these steps and would like to follow along, start with&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-prepare-app\">Tutorial 1: Prepare an application for AKS<\/a>.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>If you&#8217;re using Azure CLI, this tutorial requires that you&#8217;re running Azure CLI version 2.34.1 or later. Run&nbsp;<code>az --version<\/code>&nbsp;to find the version. If you need to install or upgrade, see&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/cli\/azure\/install-azure-cli\">Install Azure CLI<\/a>.<\/li><li>If you&#8217;re using Azure PowerShell, this tutorial requires that you&#8217;re running Azure PowerShell version 5.9.0 or later. Run&nbsp;<code>Get-InstalledModule -Name Az<\/code>&nbsp;to find the version. If you need to install or upgrade, see&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/powershell\/azure\/install-az-ps\">Install Azure PowerShell<\/a>.<\/li><\/ul>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#get-available-cluster-versions\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"get-available-cluster-versions\">Get available cluster versions<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_1_azure-cli\">Azure CLI<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_1_azure-powershell\">Azure PowerShell<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_1_azure-portal\">Azure portal<\/a><\/li><\/ul>\n\n\n\n<p>Before you upgrade a cluster, use the&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/cli\/azure\/aks#az_aks_get_upgrades\">az aks get-upgrades<\/a>&nbsp;command to check which Kubernetes releases are available.<\/p>\n\n\n\n<p>Azure CLICopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az aks get-upgrades --resource-group myResourceGroup --name myAKSCluster\n<\/code><\/pre>\n\n\n\n<p>In the following example output, the current version is&nbsp;<em>1.18.10<\/em>, and the available versions are shown under&nbsp;<em>upgrades<\/em>.<\/p>\n\n\n\n<p>OutputCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"agentPoolProfiles\": null,\n  \"controlPlaneProfile\": {\n    \"kubernetesVersion\": \"1.18.10\",\n    ...\n    \"upgrades\": &#91;\n      {\n        \"isPreview\": null,\n        \"kubernetesVersion\": \"1.19.1\"\n      },\n      {\n        \"isPreview\": null,\n        \"kubernetesVersion\": \"1.19.3\"\n      }\n    ]\n  },\n  ...\n}\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#upgrade-a-cluster\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"upgrade-a-cluster\">Upgrade a cluster<\/h2>\n\n\n\n<p>AKS nodes are carefully cordoned and drained to minimize any potential disruptions to running applications. The following steps are performed during this process:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The Kubernetes scheduler prevents additional pods from being scheduled on a node that is to be upgraded.<\/li><li>Running pods on the node are scheduled on other nodes in the cluster.<\/li><li>A new node is created that runs the latest Kubernetes components.<\/li><li>When the new node is ready and joined to the cluster, the Kubernetes scheduler begins to run pods on the new node.<\/li><li>The old node is deleted, and the next node in the cluster begins the cordon and drain process.<\/li><\/ol>\n\n\n\n<p>&nbsp;Note<\/p>\n\n\n\n<p>If no patch is specified, the cluster will automatically be upgraded to the specified minor version&#8217;s latest GA patch. For example, setting&nbsp;<code>--kubernetes-version<\/code>&nbsp;to&nbsp;<code>1.21<\/code>&nbsp;will result in the cluster upgrading to&nbsp;<code>1.21.9<\/code>.<\/p>\n\n\n\n<p>When upgrading by alias minor version, only a higher minor version is supported. For example, upgrading from&nbsp;<code>1.20.x<\/code>&nbsp;to&nbsp;<code>1.20<\/code>&nbsp;will not trigger an upgrade to the latest GA&nbsp;<code>1.20<\/code>&nbsp;patch, but upgrading to&nbsp;<code>1.21<\/code>&nbsp;will trigger an upgrade to the latest GA&nbsp;<code>1.21<\/code>&nbsp;patch.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_2_azure-cli\">Azure CLI<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_2_azure-powershell\">Azure PowerShell<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_2_azure-portal\">Azure portal<\/a><\/li><\/ul>\n\n\n\n<p>Use the&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/cli\/azure\/aks#az_aks_upgrade\">az aks upgrade<\/a>&nbsp;command to upgrade your AKS cluster.<\/p>\n\n\n\n<p>Azure CLICopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az aks upgrade \\\n    --resource-group myResourceGroup \\\n    --name myAKSCluster \\\n    --kubernetes-version KUBERNETES_VERSION\n<\/code><\/pre>\n\n\n\n<p>&nbsp;Note<\/p>\n\n\n\n<p>You can only upgrade one minor version at a time. For example, you can upgrade from&nbsp;<em>1.14.x<\/em>&nbsp;to&nbsp;<em>1.15.x<\/em>, but you cannot upgrade from&nbsp;<em>1.14.x<\/em>&nbsp;to&nbsp;<em>1.16.x<\/em>&nbsp;directly. To upgrade from&nbsp;<em>1.14.x<\/em>&nbsp;to&nbsp;<em>1.16.x<\/em>, you must first upgrade from&nbsp;<em>1.14.x<\/em>&nbsp;to&nbsp;<em>1.15.x<\/em>, then perform another upgrade from&nbsp;<em>1.15.x<\/em>&nbsp;to&nbsp;<em>1.16.x<\/em>.<\/p>\n\n\n\n<p>The following example output shows the result of upgrading to&nbsp;<em>1.19.1<\/em>. Notice the&nbsp;<em>kubernetesVersion<\/em>&nbsp;now reports&nbsp;<em>1.19.1<\/em>.<\/p>\n\n\n\n<p>OutputCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"agentPoolProfiles\": &#91;\n    {\n      \"count\": 3,\n      \"maxPods\": 110,\n      \"name\": \"nodepool1\",\n      \"osType\": \"Linux\",\n      \"storageProfile\": \"ManagedDisks\",\n      \"vmSize\": \"Standard_DS1_v2\",\n    }\n  ],\n  \"dnsPrefix\": \"myAKSClust-myResourceGroup-19da35\",\n  \"enableRbac\": false,\n  \"fqdn\": \"myaksclust-myresourcegroup-19da35-bd54a4be.hcp.eastus.azmk8s.io\",\n  \"id\": \"\/subscriptions\/&lt;Subscription ID&gt;\/resourcegroups\/myResourceGroup\/providers\/Microsoft.ContainerService\/managedClusters\/myAKSCluster\",\n  \"kubernetesVersion\": \"1.19.1\",\n  \"location\": \"eastus\",\n  \"name\": \"myAKSCluster\",\n  \"type\": \"Microsoft.ContainerService\/ManagedClusters\"\n}\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#view-the-upgrade-events\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"view-the-upgrade-events\">View the upgrade events<\/h2>\n\n\n\n<p>When you upgrade your cluster, the following Kubernetes events may occur on the nodes:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Surge<\/strong>: Create surge node.<\/li><li><strong>Drain<\/strong>: Pods are being evicted from the node. Each pod has a&nbsp;<em>5 minute timeout<\/em>&nbsp;to complete the eviction.<\/li><li><strong>Update<\/strong>: Update of a node has succeeded or failed.<\/li><li><strong>Delete<\/strong>: Delete a surge node.<\/li><\/ul>\n\n\n\n<p>Use&nbsp;<code>kubectl get events<\/code>&nbsp;to show events in the default namespaces while running an upgrade.<\/p>\n\n\n\n<p>Azure CLICopyOpen Cloudshell<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get events \n<\/code><\/pre>\n\n\n\n<p>The following example output shows some of the above events listed during an upgrade.<\/p>\n\n\n\n<p>OutputCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\ndefault 2m1s Normal Drain node\/aks-nodepool1-96663640-vmss000001 Draining node: &#91;aks-nodepool1-96663640-vmss000001]\n...\ndefault 9m22s Normal Surge node\/aks-nodepool1-96663640-vmss000002 Created a surge node &#91;aks-nodepool1-96663640-vmss000002 nodepool1] for agentpool %!s(MISSING)\n...\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#validate-an-upgrade\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"validate-an-upgrade\">Validate an upgrade<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_3_azure-cli\">Azure CLI<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_3_azure-powershell\">Azure PowerShell<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_3_azure-portal\">Azure portal<\/a><\/li><\/ul>\n\n\n\n<p>Confirm that the upgrade was successful using the&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/cli\/azure\/aks#az_aks_show\">az aks show<\/a>&nbsp;command.<\/p>\n\n\n\n<p>Azure CLICopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az aks show --resource-group myResourceGroup --name myAKSCluster --output table\n<\/code><\/pre>\n\n\n\n<p>The following example output shows the AKS cluster runs&nbsp;<em>KubernetesVersion 1.19.1<\/em>:<\/p>\n\n\n\n<p>OutputCopy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Name          Location    ResourceGroup    KubernetesVersion    CurrentKubernetesVersion  ProvisioningState    Fqdn\n------------  ----------  ---------------  -------------------  ------------------------  -------------------  ----------------------------------------------------------------\nmyAKSCluster  eastus      myResourceGroup  1.19.1               1.19.1                    Succeeded            myaksclust-myresourcegroup-19da35-bd54a4be.hcp.eastus.azmk8s.io\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#delete-the-cluster\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"delete-the-cluster\">Delete the cluster<\/h2>\n\n\n\n<p>As this tutorial is the last part of the series, you may want to delete your AKS cluster. The Kubernetes nodes run on Azure virtual machines and continue incurring charges even if you don&#8217;t use the cluster.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_4_azure-cli\">Azure CLI<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_4_azure-powershell\">Azure PowerShell<\/a><\/li><li><a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/tutorial-kubernetes-upgrade-cluster?tabs=azure-cli#tabpanel_4_azure-portal\">Azure portal<\/a><\/li><\/ul>\n\n\n\n<p>Use the&nbsp;<a href=\"https:\/\/learn.microsoft.com\/en-us\/cli\/azure\/group#az_group_delete\">az group delete<\/a>&nbsp;command to remove the resource group, container service, and all related resources.<\/p>\n\n\n\n<p>Azure CLICopyOpen Cloudshell<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az group delete --name myResourceGroup --yes --no-wait\n<\/code><\/pre>\n\n\n\n<p>&nbsp;Note<\/p>\n\n\n\n<p>When you delete the cluster, the Azure Active Directory (AAD) service principal used by the AKS cluster isn&#8217;t removed. For steps on how to remove the service principal, see\u00a0<a href=\"https:\/\/learn.microsoft.com\/en-us\/azure\/aks\/kubernetes-service-principal#other-considerations\">AKS service principal considerations and deletion<\/a>. If you used a managed identity, the identity is managed by the platform and it doesn&#8217;t require that you provision or rotate any secrets.<\/p>\n\n\n\n<p>Ref: <\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of the application and cluster lifecycle, you may want to upgrade to the latest available version of Kubernetes. You can upgrade your Azure Kubernetes Service (AKS) cluster by using the Azure CLI, Azure PowerShell, or the Azure portal. In this tutorial, part seven of seven, you learn how to: Identify current and available <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=4681\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1249,10],"tags":[1541,1540],"class_list":["post-4681","post","type-post","status-publish","format-standard","hentry","category-azure-microsoft","category-microsoft","tag-upgrade-azure-kubernetes","tag-upgrade-kubernetes"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4681"}],"version-history":[{"count":1,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4681\/revisions"}],"predecessor-version":[{"id":4682,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/4681\/revisions\/4682"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}