Reputation: 2639
I have used the following python code in order to upgrade AKS to the latest version. However I am wondering if the latest version here is the stable version?
I couldn't find some info regarding this in 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.
Upvotes: 0
Views: 297
Reputation: 11421
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.
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 : **
Upvotes: 1