Azure Kubernetes Configuration Management
The Microsoft Azure Kubernetes Configuration Management Client Library for Python provides functionality to manage Kubernetes configurations, including source control configurations, flux configurations, and extensions on Azure-managed Kubernetes clusters. It is part of the broader Azure SDK for Python, currently at version 3.1.0, and follows a consistent release cadence with other Azure SDKs, receiving regular updates and bug fixes.
Common errors
-
azure.core.exceptions.ClientAuthenticationError: Authentication failed: 'DefaultAzureCredential' cannot retrieve credentials. ... Please check the troubleshooting guide for more information.
cause The `DefaultAzureCredential` could not find valid credentials in any of its supported locations (environment variables, Azure CLI, Managed Identity, etc.) or the found credentials lack necessary permissions.fixEnsure you are authenticated to Azure (e.g., `az login` via Azure CLI), or that required environment variables (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` for service principal) are correctly set and have the necessary role assignments (e.g., Contributor or specific resource roles) on your Azure subscription. -
azure.core.exceptions.ResourceNotFoundError: The resource with name 'my-non-existent-cluster' was not found.
cause The resource ID (e.g., resource group name, cluster name, or other identifier) provided to a client method does not correspond to an existing resource in your Azure subscription or the API path is incorrect.fixVerify that the resource names and IDs (e.g., `resource_group_name`, `cluster_name`) used in your code exactly match existing resources in your Azure subscription. Double-check for typos and ensure the specified resource exists in the correct region/resource group. -
TypeError: __init__ missing 1 required positional argument: 'subscription_id'
cause The `KubernetesConfigurationClient` constructor requires a `subscription_id` in addition to the credential object, and it was omitted or passed incorrectly.fixEnsure the client is initialized correctly, providing both the credential object and the Azure subscription ID, like: `client = KubernetesConfigurationClient(credential, subscription_id)`.
Warnings
- breaking Major version updates (e.g., from 2.x to 3.x) often introduce breaking changes due to underlying Azure API version changes or significant SDK design updates. Client constructors, method signatures, and model schemas can change.
- gotcha `DefaultAzureCredential` might fail to find credentials if environment variables (like `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) are not set, or if you are not logged in via Azure CLI/VS Code.
- gotcha Resource-specific operations often require precise `cluster_rp`, `cluster_resource_name`, and `cluster_name` parameters. `cluster_rp` (Resource Provider) can be confusing and specific to the Kubernetes distribution (e.g., 'Microsoft.ContainerService' for AKS, 'Microsoft.Kubernetes' for Arc-enabled clusters).
Install
-
pip install azure-mgmt-kubernetesconfiguration
Imports
- KubernetesConfigurationClient
from azure.mgmt.kubernetesconfiguration.kubernetes_configuration_client import KubernetesConfigurationClient
from azure.mgmt.kubernetesconfiguration import KubernetesConfigurationClient
- DefaultAzureCredential
from azure.common.credentials import ServicePrincipalCredentials
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.kubernetesconfiguration import KubernetesConfigurationClient
# Set your Azure Subscription ID as an environment variable (AZURE_SUBSCRIPTION_ID)
# or replace os.environ.get with your actual subscription ID string.
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
if not subscription_id or subscription_id == 'YOUR_SUBSCRIPTION_ID':
raise ValueError(
"Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_SUBSCRIPTION_ID'."
)
# Authenticate using DefaultAzureCredential.
# This will try several authentication methods, including Azure CLI, Azure Developer CLI,
# environment variables, and Managed Identity if applicable.
credential = DefaultAzureCredential()
# Create a KubernetesConfigurationClient instance
client = KubernetesConfigurationClient(credential, subscription_id)
print(f"Listing operations for Kubernetes Configuration in subscription {subscription_id}:")
try:
# List all available operations related to Kubernetes Configuration.
# This is a common and safe way to test client connectivity and permissions without
# requiring specific resource names.
operations = client.operations.list()
# Iterate and print basic details of each operation
for op in operations:
print(f"- {op.display.provider}/{op.display.resource}: {op.display.operation}")
print("Quickstart example completed successfully.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your subscription ID is correct and you have appropriate permissions.")