通过 python begin_create_or_update() 将 AKS 升级到最新的稳定版本

Upgrading AKS to the latest stable version via python begin_create_or_update()

为了将 AKS 升级到最新版本,我使用了以下 python 代码。不过我想知道这里最新的版本是不是稳定版?

我在 docz 中找不到与此相关的信息。 如果我们使用 auto-upgrade-channel 它有一个选项来指定“稳定”,那将如何与我使用的这种方法一起使用?

for resource in list(resource_list):
    if resource.type== "Microsoft.ContainerService/managedClusters":
       location=resource.location
       print("Location:", location)
       containerservice_client = ContainerServiceClient(credential, sub.subscription_id)
       get_aks = containerservice_client.managed_clusters.get(group.name, resource.name)
                    
       print("Getting availabele versions on AKS Cluster....")
       aks_get_version = containerservice_client.managed_clusters.get_upgrade_profile(group.name, resource.name)
  
       aks_get_upgrade = aks_get_version.control_plane_profile
       upgrades = aks_get_upgrade.upgrades
       print("ResourceName:", resource.name, "AKS_current_Version", aks_get_upgrade.kubernetes_version)
       current_version = aks_get_upgrade.kubernetes_version
       agent_pool=containerservice_client.agent_pools.list(group.name, resource.name)
       if upgrades:
          for i in upgrades:
              print("ResourceName:", resource.name, "AKSAvailable_Versions_List:", i.kubernetes_version,i.is_preview)
              latest_version = i.kubernetes_version
          print("Latest Available Version:", latest_version)      
          for x in agent_pool:
              agent_pool_name=x.name
              print("Agent_Pool_Name:",x.name)
          if latest_version != current_version:
             print("Upgrading to a new version....")
             param=ManagedCluster(location=location, kubernetes_version=latest_version,agent_pool_profiles=[ManagedClusterAgentPoolProfile(orchestrator_version=latest_version,name=agent_pool_name,mode=x.mode,type=x.type_properties_type)])
                        update_aks=containerservice_client.managed_clusters.begin_create_or_update(resource_group_name=group.name,resource_name=resource.name,parameters=param)     
          else:
            print("Kubernetes version is the latest one!")    
       else:
          print("There is no new updates available!")   

如果有人能给我解释一下,我将不胜感激。

如 Microsoft 文档中所述,auto-upgrade 频道提供的稳定功能如下:

此外,auto-upgrade 功能仅升级到 GA 版本,而不是预览版本。

所以,我已经根据要求修改了代码,它会像下面这样:

from azure.identity import AzureCliCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.containerservice import ContainerServiceClient
from azure.mgmt.containerservice.models import (ManagedClusterAgentPoolProfile,
                                                ManagedCluster)

credential = AzureCliCredential()
subscription_id = "mysub"
resource_group= 'myresourcegroup'
resouce_client=ResourceManagementClient(credential,subscription_id)
containerservice_client=ContainerServiceClient(credential,subscription_id)
resource_list=resouce_client.resources.list_by_resource_group(resource_group)
for resource in list(resource_list):
if resource.type == "Microsoft.ContainerService/managedClusters":
   location=resource.location
   print("Location:", location)
   get_aks = containerservice_client.managed_clusters.get(resource_group, resource.name)          
   print("Getting availabele versions on AKS Cluster....")
   aks_get_version = containerservice_client.managed_clusters.get_upgrade_profile(resource_group, resource.name)

   aks_get_upgrade = aks_get_version.control_plane_profile
   upgrades = aks_get_upgrade.upgrades
   print("ResourceName:", resource.name, "AKS_current_Version", aks_get_upgrade.kubernetes_version)
   current_version = aks_get_upgrade.kubernetes_version
   agent_pool=containerservice_client.agent_pools.list(resource_group, resource.name)
   if upgrades:
      latest_version=list()
      preview=list()
      l= (len(upgrades)-1)
      print(l)
      for i in upgrades:
          print("ResourceName:", resource.name, "AKSAvailable_Versions_List:", i.kubernetes_version, "Preview:" , i.is_preview)
          latest_version.append(i.kubernetes_version)
          preview.append(i.is_preview)
      latest_stable_version = latest_version[-l]
      version_preview_for_stable=preview[-l]
      print("Latest Stable Available Version:", latest_stable_version)
      for x in agent_pool:
        agent_pool_name=x.name
        print("Agent_Pool_Name:",x.name)
      if version_preview_for_stable == None and latest_stable_version != current_version :
        print("Upgrading to a new version....")

      else:
        print("Kubernetes version is the latest one!")    
   else:
      print("There is no new updates available!") 

**输出:**