Sign in
agent:

List All AKS Clusters

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This task retrieves and displays all Azure Kubernetes Service (AKS) clusters present within a specific Azure subscription. This helps users keep track of their deployed clusters, manage resources, and monitor cluster configurations.

import azure.identity from azure.mgmt.containerservice import ContainerServiceClient if subscription_id: # Initialize Azure credentials credential = azure.identity.DefaultAzureCredential() # Setup Azure AKS client aks_client = ContainerServiceClient(credential, subscription_id) try: # List all AKS clusters all_clusters = [cluster for cluster in aks_client.managed_clusters.list()] # Filter clusters based on location if specified if location: all_clusters = [cluster for cluster in all_clusters if cluster.location == location] print(f"Total AKS Clusters Found: {len(all_clusters)}\n") for cluster in all_clusters: node_count = sum([pool.count for pool in cluster.agent_pool_profiles]) print(f"Cluster Name: {cluster.name}") print(f"Region: {cluster.location}") print(f"Node Count: {node_count}") print(f"Kubernetes Version: {cluster.kubernetes_version}\n") #print(f"cluster_id: {cluster.id}") #for debugging #print(all_clusters) # for debugging except azure.core.exceptions.AzureError as ae: print(f"Azure SDK Error: {ae.message}") except Exception as e: print(f"An unexpected error occurred: {e}")
copied