简体   繁体   English

Azure-sdk-for-python AKS-如何在 AKS 上获取 Kubernetes 的可用最新版本

[英]Azure-sdk-for-python AKS- How to get available latest version for Kubernetes on AKS

I'm trying to get available versions of Kubernetes on AKS via python.sdk and upgrade the AKS with the latest version afterwards.我正在尝试通过 python.sdk 在 AKS 上获取可用版本的 Kubernetes,然后使用最新版本升级 AKS。

Here is what I've tried considering this doc https://docs.microsoft.com/en-us/rest/api/aks/managed-clusters/get-upgrade-profile这是我在考虑此文档时尝试过的https://docs.microsoft.com/en-us/rest/api/aks/managed-clusters/get-upgrade-profile

for resource in list(resource_list):
    if resource.type== "Microsoft.ContainerService/managedClusters":
       print("ResourceName:", resource.name, "ResourceType:", resource.type)
       containerservice_client = ContainerServiceClient(credential, sub.subscription_id)
       get_aks = containerservice_client.managed_clusters.get(group.name, resource.name)
       aks_get_upgrade = containerservice_client.managed_clusters.get_upgrade_profile(group.name, resource.name)
       print("AKSGetUpdate", aks_get_upgrade)

However it doesn't return kubernetesVersion.但是它不会返回 kubernetesVersion。

I would appreciate if someone can help with this.如果有人可以提供帮助,我将不胜感激。

You can try using the below code , which I used to test in my environment:您可以尝试使用以下代码,我曾在我的环境中对其进行测试:

from azure.identity import AzureCliCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.containerservice import ContainerServiceClient
from azure.mgmt.containerservice.models import ManagedClusterPoolUpgradeProfileUpgradesItem

credential = AzureCliCredential()
subscription_id = "SUBID"
resource_group= 'RG'
resouce_client=ResourceManagementClient(credential,subscription_id)
container_client=ContainerServiceClient(credential,subscription_id)
resouce_list=resouce_client.resources.list_by_resource_group(resource_group)
for resource in list (resouce_list) :
    if resource.type == 'Microsoft.ContainerService/managedClusters':
       print("ResourceName:", resource.name, "ResourceType:", resource.type)
       get_aks = container_client.managed_clusters.get(resource_group, resource.name)
       aks_get_details = container_client.managed_clusters.get_upgrade_profile(resource_group, resource.name)
       aks_get_upgrade = aks_get_details.control_plane_profile
       upgrades = aks_get_upgrade.upgrades
       print("AKS_current_controlPlane", aks_get_upgrade.kubernetes_version)
       for i in upgrades:
           print("AKSGetUpdate_upgrade_controlPlane", i.kubernetes_version,i.is_preview)

Output:输出:

在此处输入图片说明

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

相关问题 Azure-sdk-for-python AKS-如何在 AKS 上升级 kubernetes - Azure-sdk-for-python AKS- How to upgrade kubernetes on AKS 如何使用azure-sdk-for-python在Azure队列中禁用Nagle算法 - How to disable Nagle algorithm in Azure queue with azure-sdk-for-python 通过 python begin_create_or_update() 将 AKS 升级到最新的稳定版本 - Upgrading AKS to the latest stable version via python begin_create_or_update() 没有准备好的服务副本 - azure aks - No ready replicas for service - azure 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? 如何使用 python SDK 访问 azure AD - How to access azure AD using python SDK 是否有适用于 Python 的 Firebase SDK? - Is there a Firebase SDK available for python? 如何执行刚刚安装的最新版本python? - How to execute latest version python which just been installed? 如何在 Synology DSM 上将 Python3 升级到最新版本? - How to upgrade Python3 to the latest version on Synology DSM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM