简体   繁体   English

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

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

I have used the following python code in order to upgrade AKS to the latest version.为了将 AKS 升级到最新版本,我使用了以下 python 代码。 However I am wondering if the latest version here is the stable version?但是我想知道这里的最新版本是否是稳定版本?

I couldn't find some info regarding this in docz.我在 docz 中找不到有关此的一些信息。 If we used auto-upgrade-channel it has an option to specify "stable", how would that work with this method that I used?如果我们使用自动升级通道,它有一个指定“稳定”的选项,那么我使用的这种方法将如何工作?

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!")   

I would appreciate if someone can explain it to me.如果有人可以向我解释,我将不胜感激。

As mentioned in Microsoft Documentation, stable feature which is offered by auto-upgrade channel is as below:正如微软文档中提到的,自动升级通道提供的稳定功能如下:

在此处输入图像描述

And also adding to that the auto-upgrade feature only upgrades to GA versions and not Preview versions.此外,自动升级功能仅升级到 GA 版本,而不是预览版。

So,I have modified the code as per the requirement and it will be something like below:所以,我已经根据要求修改了代码,它将如下所示:

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!") 

**Output: ** **输出: **

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将OpenCV 3.4.2更新到OpenCV 4或最新的稳定版本? - How to update OpenCV 3.4.2 to OpenCV 4 or latest stable version? Azure-sdk-for-python AKS-如何在 AKS 上获取 Kubernetes 的可用最新版本 - Azure-sdk-for-python AKS- How to get available latest version for Kubernetes on AKS 如何在 azure unbuntu 18.04LTS 实例中将 python 版本 3.6.9 升级到任何最新的稳定 python 版本 - How to upgrade python version 3.6.9 to any latest stable python version in azure unbuntu 18.04LTS instance Conda环境下如何更新Python到最新版本? - How to update Python to the latest version in Conda environment? 无法将anaconda上的python包更新到最新版本 - Cannot update python package on anaconda to latest version Seaborn 不会在 Conda 中更新到最新版本 - Seaborn will not update to latest version in Conda 升级pycharm venv python版本 - Upgrading pycharm venv python version Python(最新版本)语法错误 - Python (latest version) Syntax Error 以编程方式获取最新的 python 3 版本 - Getting the latest python 3 version programmatically 如何在亚马逊的Elastic Bean Stalk上使用最新版本的python(3.6)通过虚拟环境 - How to use the latest version of python (3.6) on Amazon's Elastic Bean Stalk Via virtual env
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM