Azure Container Service Management Client Library
The `azure-mgmt-containerservice` library is the Microsoft Azure Container Service Management Client Library for Python, enabling programmatic interaction with Azure Kubernetes Service (AKS) and other container-related resources. It is currently at version 41.0.0 and frequently updated to support the latest Azure Container Service APIs, with a release cadence that includes multiple major and minor versions throughout the year. [2, 13]
Common errors
-
ModuleNotFoundError: No module named 'azure.mgmt.containerservice'
cause The `azure-mgmt-containerservice` package, or its underlying `azure-mgmt` dependency, was not installed, or the Python environment lacks access to the installed package.fixEnsure the correct package is installed in your active Python environment using: `pip install azure-mgmt-containerservice`. -
ModuleNotFoundError: No module named 'azure.mgmt.containerservice.vYYYY_MM_DD'
cause Your code is attempting to import a specific, versioned API module (e.g., `v2021_10_01`) that is either no longer available or was never part of your installed `azure-mgmt-containerservice` package version, often due to SDK updates or mismatches with Azure CLI versions.fixRemove the explicit API version from the import statement (e.g., `from azure.mgmt.containerservice import ContainerServiceClient`) as the SDK client typically handles API versioning internally. If issues persist, upgrade the package: `pip install --upgrade azure-mgmt-containerservice`. -
(ResourceGroupNotFound) Resource group 'your_resource_group_name' could not be found.
cause The specified Azure resource group either does not exist, is misspelled, or the authenticated credentials lack the necessary permissions to access it within the current Azure subscription context.fixVerify the resource group name for typos and confirm its existence in the correct Azure subscription. Ensure your Azure credentials (e.g., `DefaultAzureCredential` or service principal) have at least 'Reader' permissions on the subscription or resource group. If using Azure CLI, ensure the correct subscription is active: `az account set --subscription <subscription-id>`. -
AttributeError: 'ManagedClustersOperations' object has no attribute 'some_method'
cause This error typically occurs when a method or property you are trying to use on a client object (like `ManagedClustersOperations`) has been renamed, removed, or significantly altered in a different version of the `azure-mgmt-containerservice` library than your code expects.fixConsult the official documentation for your installed `azure-mgmt-containerservice` version to find the correct method or property names. Consider upgrading the library (`pip install --upgrade azure-mgmt-containerservice`) and then reviewing the latest documentation for breaking changes and updated API usage.
Warnings
- breaking Version 41.0.0 and newer packages now exclusively target the latest API-Version available on Azure, removing APIs from older versions. Applications relying on specific, non-latest API versions must pin the package to a previous release. [2, 3]
- breaking The client operation group `ContainerServiceClient.container_service` has been deleted or renamed in version 41.0.0. [2]
- deprecated Older Azure SDK authentication methods, such as those using `azure.common.credentials`, are deprecated. The `azure-identity` library should be used for modern token-based authentication. [1, 6, 18]
- gotcha Python 2.7 support for Azure SDK Python packages ended on January 1, 2022. This package requires Python 3.9+. [2, 13]
Install
-
pip install azure-mgmt-containerservice azure-identity
Imports
- ContainerServiceClient
from azure.mgmt.containerservice import ContainerServiceClient
- DefaultAzureCredential
from azure.common.credentials import ServicePrincipalCredentials
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient
# Set environment variables for authentication:
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
# And AZURE_SUBSCRIPTION_ID
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")
# Authenticate with Azure
credential = DefaultAzureCredential()
# Create a Container Service client
client = ContainerServiceClient(credential=credential, subscription_id=subscription_id)
print(f"Successfully created Azure Container Service client for subscription: {subscription_id}")
# Example: List managed clusters (actual operation not shown for brevity)
# for cluster in client.managed_clusters.list():
# print(f"Cluster Name: {cluster.name}, Location: {cluster.location}")