title: Azure-sdk-for-python AKS- How to upgrade kubernetes on AKS
body: <p>I've tried to find out which python sdk I can use for upgrading Kubernetes on AKS, in another word how to run this command via python sdk?</p>
  <pre><code>az aks upgrade --name mycluster --resource-group myrg --kubernetes-version newversion
  </code></pre>
  <p>however my search wasn't successful.</p>
  <p>Here is a part of my function: init.py</p>
  <pre><code>import logging
  from azure.mgmt.containerservice import ContainerServiceClient
  from azure.identity import ClientSecretCredential
  from azure.mgmt.subscription import SubscriptionClient
  from azure.mgmt.resource import ResourceManagementClient
  ....
  for group in list(group_list):
                #print(&quot;ResourceGroupName:&quot;, group.name)
                resource_list = resource_client.resources.list_by_resource_group(group.name)
                print(&quot;Fetching AKS resource\n&quot;)
                
                for resource in list(resource_list):
                  if resource.type== &quot;Microsoft.ContainerService/managedClusters&quot;:
                    print(&quot;ResourceName:&quot;, resource.name, &quot;ResourceType:&quot;, resource.type)
                    containerservice_client = ContainerServiceClient(credential, sub.subscription_id)
                    
                    print(&quot;Getting availabele versions...\n&quot;)
                    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(&quot;AKS_current_controlPlane&quot;, aks_get_upgrade.kubernetes_version)
                    for i in upgrades:
                      print(&quot;AKSGetUpdate_upgrade_controlPlane&quot;, i.kubernetes_version,i.is_preview)
  </code></pre>
  <p>It seems</p>
  <pre><code>managed_clusters.update 
  </code></pre>
  <p>can be a solution but then the question is how to pass properties.kubernetesVersion and properties.agentPoolProfiles[0].orchestratorVersion values in it?</p>
  <pre><code>parameters = {&quot;properties.kubernetesVersion&quot;: i.kubernetes_version, &quot;properties.agentPoolProfiles[0].orchestratorVersion&quot;: i.kubernetes_version}
  containerservice_client.managed_clusters.create_or_update(group.name, resource.name, parameters)
  </code></pre>
  <p>However I get this error:</p>
  <pre><code>Exception: AttributeError: 'ManagedClustersOperations' object has no attribute 'create_or_update'
  </code></pre>
  <p>I would appreciate if someone can help with this.</p>
  <p><strong>Updated</strong></p>
  <p>Modified the code based on the given answer however it doesn't update my cluster and doesn't give me any error either, I don't know what I'm missing and how to do troubleshooting in this stage:</p>
  <pre><code>print(&quot;Getting availabele versions on AKS:&quot;, resource.name)
  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(&quot;AKS_current_controlPlane&quot;, aks_get_upgrade.kubernetes_version)
                    
  agent_pool=containerservice_client.agent_pools.list(group.name, resource.name)
   for i in upgrades:
        print(&quot;AKSAvailable_Versions_List:&quot;, i.kubernetes_version,i.is_preview)
        latest_version = i.kubernetes_version
   print(&quot;LatestVersion:&quot;, latest_version)  
                      
   for x in agent_pool:
       agent_pool_name=x.name
       print(&quot;Agent_Pool_Name:&quot;,x.name)
   ManagedClusterAgentPoolProfile(orchestrator_version=latest_version,name=agent_pool_name)
  
  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) 
  </code></pre>
  <p>OutPut:
  AKS_current_controlPlane 1.19.11
  LatestVersion: 1.20.9
  Agent_Pool_Name: default</p>