0
# Azure Container Service Management Client
1
2
A comprehensive Python client library for managing Azure Kubernetes Service (AKS) resources through the Azure Resource Manager REST API. This library enables developers to programmatically create, configure, and manage Kubernetes clusters on Azure, including operations for cluster lifecycle management, node pool configuration, networking setup, and security policies.
3
4
## Package Information
5
6
- **Package Name**: azure-mgmt-containerservice
7
- **Language**: Python
8
- **Installation**: `pip install azure-mgmt-containerservice`
9
- **API Version**: 2025-07-01
10
- **Python Support**: 3.9+
11
12
## Core Imports
13
14
```python
15
from azure.mgmt.containerservice import ContainerServiceClient
16
from azure.identity import DefaultAzureCredential
17
```
18
19
For async operations:
20
21
```python
22
from azure.mgmt.containerservice.aio import ContainerServiceClient as AsyncContainerServiceClient
23
from azure.identity.aio import DefaultAzureCredential as AsyncDefaultAzureCredential
24
```
25
26
## Basic Usage
27
28
```python
29
from azure.mgmt.containerservice import ContainerServiceClient
30
from azure.identity import DefaultAzureCredential
31
32
# Initialize the client
33
credential = DefaultAzureCredential()
34
subscription_id = "your-subscription-id"
35
client = ContainerServiceClient(credential, subscription_id)
36
37
# List all managed clusters
38
clusters = client.managed_clusters.list()
39
for cluster in clusters:
40
print(f"Cluster: {cluster.name}, Location: {cluster.location}")
41
42
# Get a specific cluster
43
cluster = client.managed_clusters.get("resource-group-name", "cluster-name")
44
print(f"Cluster status: {cluster.provisioning_state}")
45
46
# Close the client
47
client.close()
48
```
49
50
Async usage:
51
52
```python
53
import asyncio
54
from azure.mgmt.containerservice.aio import ContainerServiceClient
55
from azure.identity.aio import DefaultAzureCredential
56
57
async def main():
58
credential = DefaultAzureCredential()
59
async with ContainerServiceClient(credential, subscription_id) as client:
60
# List clusters asynchronously
61
clusters = []
62
async for cluster in client.managed_clusters.list():
63
clusters.append(cluster)
64
65
print(f"Found {len(clusters)} clusters")
66
67
asyncio.run(main())
68
```
69
70
## Architecture
71
72
The client follows the Azure SDK architecture pattern with a main client class that provides access to operation groups:
73
74
- **ContainerServiceClient**: Main client managing authentication, configuration, and request pipeline
75
- **Operations Groups**: Specialized classes for different resource types (clusters, agent pools, etc.)
76
- **Models**: Strongly-typed data classes representing Azure resources and their properties
77
- **Long-Running Operations (LRO)**: Asynchronous operations that return pollers for tracking progress
78
- **Pagination**: Automatic handling of large result sets through async iterators
79
80
Both synchronous and asynchronous versions follow the same API patterns, with async methods returning coroutines.
81
82
## Capabilities
83
84
### Managed Cluster Operations
85
86
Core AKS cluster management including creation, updates, scaling, credential rotation, and deletion. Supports both basic and advanced cluster configurations with comprehensive networking, security, and monitoring options.
87
88
```python { .api }
89
def get(resource_group_name: str, resource_name: str, **kwargs) -> ManagedCluster: ...
90
def begin_create_or_update(resource_group_name: str, resource_name: str, parameters: ManagedCluster, **kwargs) -> LROPoller[ManagedCluster]: ...
91
def begin_delete(resource_group_name: str, resource_name: str, **kwargs) -> LROPoller[None]: ...
92
def list(**kwargs) -> ItemPaged[ManagedCluster]: ...
93
def list_by_resource_group(resource_group_name: str, **kwargs) -> ItemPaged[ManagedCluster]: ...
94
```
95
96
[Managed Clusters](./managed-clusters.md)
97
98
### Agent Pool Operations
99
100
Node pool management for AKS clusters including system and user node pools, auto-scaling configuration, OS and VM size selection, and maintenance operations.
101
102
```python { .api }
103
def get(resource_group_name: str, resource_name: str, agent_pool_name: str, **kwargs) -> AgentPool: ...
104
def begin_create_or_update(resource_group_name: str, resource_name: str, agent_pool_name: str, parameters: AgentPool, **kwargs) -> LROPoller[AgentPool]: ...
105
def begin_delete(resource_group_name: str, resource_name: str, agent_pool_name: str, **kwargs) -> LROPoller[None]: ...
106
def list(resource_group_name: str, resource_name: str, **kwargs) -> ItemPaged[AgentPool]: ...
107
```
108
109
[Agent Pools](./agent-pools.md)
110
111
### Maintenance Configuration
112
113
Scheduled maintenance windows and maintenance configuration management for AKS clusters, including both node OS updates and Kubernetes version upgrades.
114
115
```python { .api }
116
def get(resource_group_name: str, resource_name: str, config_name: str, **kwargs) -> MaintenanceConfiguration: ...
117
def create_or_update(resource_group_name: str, resource_name: str, config_name: str, parameters: MaintenanceConfiguration, **kwargs) -> MaintenanceConfiguration: ...
118
def delete(resource_group_name: str, resource_name: str, config_name: str, **kwargs) -> None: ...
119
def list_by_managed_cluster(resource_group_name: str, resource_name: str, **kwargs) -> ItemPaged[MaintenanceConfiguration]: ...
120
```
121
122
[Maintenance](./maintenance.md)
123
124
### Private Networking
125
126
Private endpoint connections, private link resources, and private link service ID resolution for secure, private connectivity to AKS clusters.
127
128
```python { .api }
129
def get(resource_group_name: str, resource_name: str, private_endpoint_connection_name: str, **kwargs) -> PrivateEndpointConnection: ...
130
def update(resource_group_name: str, resource_name: str, private_endpoint_connection_name: str, parameters: PrivateEndpointConnection, **kwargs) -> PrivateEndpointConnection: ...
131
def begin_delete(resource_group_name: str, resource_name: str, private_endpoint_connection_name: str, **kwargs) -> LROPoller[None]: ...
132
def list(resource_group_name: str, resource_name: str, **kwargs) -> PrivateEndpointConnectionListResult: ...
133
```
134
135
[Private Networking](./private-endpoints.md)
136
137
### Snapshots
138
139
Node pool snapshot operations for backup, restore, and blue-green deployment scenarios, enabling reliable cluster state management.
140
141
```python { .api }
142
def get(resource_group_name: str, resource_name: str, **kwargs) -> Snapshot: ...
143
def create_or_update(resource_group_name: str, resource_name: str, parameters: Snapshot, **kwargs) -> Snapshot: ...
144
def delete(resource_group_name: str, resource_name: str, **kwargs) -> None: ...
145
```
146
147
[Snapshots](./snapshots.md)
148
149
### Trusted Access
150
151
Trusted access role bindings and role management for secure integration with other Azure services and custom applications.
152
153
```python { .api }
154
def get(resource_group_name: str, resource_name: str, trusted_access_role_binding_name: str, **kwargs) -> TrustedAccessRoleBinding: ...
155
def begin_create_or_update(resource_group_name: str, resource_name: str, trusted_access_role_binding_name: str, trusted_access_role_binding: TrustedAccessRoleBinding, **kwargs) -> LROPoller[TrustedAccessRoleBinding]: ...
156
def begin_delete(resource_group_name: str, resource_name: str, trusted_access_role_binding_name: str, **kwargs) -> LROPoller[None]: ...
157
def list(resource_group_name: str, resource_name: str, **kwargs) -> ItemPaged[TrustedAccessRoleBinding]: ...
158
```
159
160
[Trusted Access](./trusted-access.md)
161
162
### Machine Operations
163
164
Individual node/machine management within agent pools, including machine-specific operations, status monitoring, and maintenance actions.
165
166
```python { .api }
167
def get(resource_group_name: str, resource_name: str, agent_pool_name: str, machine_name: str, **kwargs) -> Machine: ...
168
def list(resource_group_name: str, resource_name: str, agent_pool_name: str, **kwargs) -> ItemPaged[Machine]: ...
169
```
170
171
[Machines](./machines.md)
172
173
### Operations Discovery
174
175
Lists all available operations in the Azure Container Service provider for API discovery and documentation purposes.
176
177
```python { .api }
178
def list(**kwargs) -> ItemPaged[OperationValue]: ...
179
```
180
181
### Private Link Resources
182
183
Manages private link resources for AKS managed clusters to enable private cluster functionality and secure connectivity.
184
185
```python { .api }
186
def list(resource_group_name: str, resource_name: str, **kwargs) -> PrivateLinkResourcesListResult: ...
187
```
188
189
### Private Link Service Resolution
190
191
Resolves private link service IDs for managed clusters, essential for establishing private connectivity configurations.
192
193
```python { .api }
194
def post(resource_group_name: str, resource_name: str, parameters: PrivateLinkResource, **kwargs) -> PrivateLinkResource: ...
195
```
196
197
### Trusted Access Roles
198
199
Manages trusted access roles that can be granted to external services for secure access to AKS clusters, with regional role definitions.
200
201
```python { .api }
202
def list(location: str, **kwargs) -> ItemPaged[TrustedAccessRole]: ...
203
```
204
205
### Core Models and Types
206
207
Essential data models representing AKS resources including cluster specifications, agent pool configurations, network profiles, and authentication settings.
208
209
```python { .api }
210
class ManagedCluster: ...
211
class AgentPool: ...
212
class ContainerServiceNetworkProfile: ...
213
class ManagedClusterIdentity: ...
214
```
215
216
[Models and Types](./models.md)
217
218
## Authentication
219
220
The client requires Azure credentials with appropriate permissions. Common authentication patterns:
221
222
```python
223
# Using DefaultAzureCredential (recommended)
224
from azure.identity import DefaultAzureCredential
225
credential = DefaultAzureCredential()
226
227
# Using service principal
228
from azure.identity import ClientSecretCredential
229
credential = ClientSecretCredential(
230
tenant_id="tenant-id",
231
client_id="client-id",
232
client_secret="client-secret"
233
)
234
235
# Using managed identity
236
from azure.identity import ManagedIdentityCredential
237
credential = ManagedIdentityCredential()
238
```
239
240
## Error Handling
241
242
The client raises standard Azure SDK exceptions:
243
244
```python
245
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError
246
247
try:
248
cluster = client.managed_clusters.get("rg", "cluster-name")
249
except ResourceNotFoundError:
250
print("Cluster not found")
251
except HttpResponseError as e:
252
print(f"HTTP error: {e.status_code} - {e.message}")
253
```