0
# Kubernetes Environments
1
2
Management of Kubernetes environments for container-based applications and microservices hosted on Azure Kubernetes Service integration.
3
4
## Package Information
5
6
- **Package**: azure-mgmt-web
7
- **Module**: `azure.mgmt.web.operations.KubeEnvironmentsOperations`
8
- **Access**: `client.kube_environments`
9
10
## Core Imports
11
12
```python
13
from azure.mgmt.web import WebSiteManagementClient
14
from azure.mgmt.web.models import (
15
KubeEnvironment, KubeEnvironmentProfile, ContainerAppsConfiguration,
16
AppLogsConfiguration, Arc
17
)
18
from azure.identity import DefaultAzureCredential
19
```
20
21
## Basic Usage
22
23
```python
24
from azure.mgmt.web import WebSiteManagementClient
25
from azure.identity import DefaultAzureCredential
26
27
credential = DefaultAzureCredential()
28
client = WebSiteManagementClient(credential, subscription_id)
29
30
# List all Kubernetes environments
31
kube_envs = client.kube_environments.list_by_subscription()
32
for env in kube_envs:
33
print(f"Kube Environment: {env.name}, Location: {env.location}")
34
35
# Get specific Kubernetes environment details
36
kube_env_details = client.kube_environments.get(
37
resource_group_name="my-resource-group",
38
name="my-kube-environment"
39
)
40
print(f"Default Domain: {kube_env_details.default_domain}")
41
```
42
43
## Kubernetes Environment Management
44
45
### Create or Update Kubernetes Environment
46
47
Create a new Kubernetes environment or update an existing one.
48
49
```python { .api }
50
def create_or_update(
51
self,
52
resource_group_name: str,
53
name: str,
54
kube_environment_envelope: KubeEnvironment,
55
**kwargs
56
) -> KubeEnvironment:
57
"""
58
Create or update a Kubernetes environment.
59
60
Args:
61
resource_group_name: Name of the resource group
62
name: Name of the Kubernetes environment
63
kube_environment_envelope: Kubernetes environment configuration
64
65
Returns:
66
KubeEnvironment object
67
"""
68
```
69
70
**Usage Example:**
71
72
```python
73
from azure.mgmt.web.models import (
74
KubeEnvironment, ContainerAppsConfiguration, AppLogsConfiguration
75
)
76
77
# Configure Container Apps settings
78
container_apps_config = ContainerAppsConfiguration(
79
dapr_ai_instrumentation_key="your-app-insights-key",
80
platform_reserved_cidr="10.0.0.0/16",
81
platform_reserved_dns_ip="10.0.0.10",
82
control_plane_subnet_resource_id="/subscriptions/{subscription-id}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{subnet}"
83
)
84
85
# Configure logging
86
app_logs_config = AppLogsConfiguration(
87
destination="log-analytics",
88
log_analytics_configuration={
89
"customer_id": "your-workspace-id"
90
}
91
)
92
93
# Create Kubernetes environment
94
kube_env_config = KubeEnvironment(
95
location="East US",
96
kind="containerapp",
97
container_apps_configuration=container_apps_config,
98
app_logs_configuration=app_logs_config,
99
is_internal=False
100
)
101
102
kube_env = client.kube_environments.create_or_update(
103
resource_group_name="my-resource-group",
104
name="my-kube-environment",
105
kube_environment_envelope=kube_env_config
106
)
107
print(f"Created Kubernetes environment: {kube_env.name}")
108
```
109
110
### Get Kubernetes Environment
111
112
Retrieve details for a specific Kubernetes environment.
113
114
```python { .api }
115
def get(
116
self,
117
resource_group_name: str,
118
name: str,
119
**kwargs
120
) -> KubeEnvironment:
121
"""
122
Get Kubernetes environment details.
123
124
Args:
125
resource_group_name: Name of the resource group
126
name: Name of the Kubernetes environment
127
128
Returns:
129
KubeEnvironment object
130
"""
131
```
132
133
### List Kubernetes Environments
134
135
Get all Kubernetes environments in a subscription or resource group.
136
137
```python { .api }
138
def list_by_subscription(self, **kwargs) -> List[KubeEnvironment]:
139
"""
140
List all Kubernetes environments in the subscription.
141
142
Returns:
143
List of KubeEnvironment objects
144
"""
145
146
def list_by_resource_group(
147
self,
148
resource_group_name: str,
149
**kwargs
150
) -> List[KubeEnvironment]:
151
"""
152
List Kubernetes environments in a resource group.
153
154
Args:
155
resource_group_name: Name of the resource group
156
157
Returns:
158
List of KubeEnvironment objects
159
"""
160
```
161
162
### Update Kubernetes Environment
163
164
Modify an existing Kubernetes environment.
165
166
```python { .api }
167
def update(
168
self,
169
resource_group_name: str,
170
name: str,
171
kube_environment_envelope: KubeEnvironmentPatchResource,
172
**kwargs
173
) -> KubeEnvironment:
174
"""
175
Update a Kubernetes environment.
176
177
Args:
178
resource_group_name: Name of the resource group
179
name: Name of the Kubernetes environment
180
kube_environment_envelope: Environment update configuration
181
182
Returns:
183
Updated KubeEnvironment object
184
"""
185
```
186
187
### Delete Kubernetes Environment
188
189
Remove a Kubernetes environment and all its resources.
190
191
```python { .api }
192
def delete(
193
self,
194
resource_group_name: str,
195
name: str,
196
**kwargs
197
) -> None:
198
"""
199
Delete a Kubernetes environment.
200
201
Args:
202
resource_group_name: Name of the resource group
203
name: Name of the Kubernetes environment
204
"""
205
```
206
207
**Usage Example:**
208
209
```python
210
# List environments by resource group
211
environments = client.kube_environments.list_by_resource_group(
212
resource_group_name="my-resource-group"
213
)
214
215
for env in environments:
216
print(f"Environment: {env.name}, Provisioning State: {env.provisioning_state}")
217
218
# Get specific environment
219
env_details = client.kube_environments.get(
220
resource_group_name="my-resource-group",
221
name="my-kube-environment"
222
)
223
224
print(f"Static IP: {env_details.static_ip}")
225
print(f"Default Domain: {env_details.default_domain}")
226
```
227
228
## Container Apps Integration
229
230
### Configure Container Apps
231
232
Set up container app configurations within the Kubernetes environment.
233
234
```python { .api }
235
class ContainerAppsConfiguration:
236
"""Container Apps configuration for Kubernetes environment."""
237
dapr_ai_instrumentation_key: Optional[str]
238
dapr_ai_connection_string: Optional[str]
239
platform_reserved_cidr: Optional[str]
240
platform_reserved_dns_ip: Optional[str]
241
control_plane_subnet_resource_id: Optional[str]
242
app_subnet_resource_id: Optional[str]
243
docker_bridge_cidr: Optional[str]
244
```
245
246
**Usage Example:**
247
248
```python
249
from azure.mgmt.web.models import ContainerAppsConfiguration
250
251
# Configure networking and Dapr
252
container_config = ContainerAppsConfiguration(
253
dapr_ai_instrumentation_key="your-app-insights-key",
254
platform_reserved_cidr="10.0.0.0/16",
255
platform_reserved_dns_ip="10.0.0.10",
256
control_plane_subnet_resource_id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{control-subnet}",
257
app_subnet_resource_id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{app-subnet}",
258
docker_bridge_cidr="172.17.0.1/16"
259
)
260
261
# Apply configuration
262
kube_env = KubeEnvironment(
263
location="East US",
264
container_apps_configuration=container_config
265
)
266
```
267
268
## Logging and Monitoring
269
270
### Configure Application Logs
271
272
Set up centralized logging for container applications.
273
274
```python { .api }
275
class AppLogsConfiguration:
276
"""Application logs configuration."""
277
destination: Optional[str] # "log-analytics", "azure-monitor"
278
log_analytics_configuration: Optional[LogAnalyticsConfiguration]
279
```
280
281
### Configure Log Analytics Integration
282
283
Connect the Kubernetes environment to Azure Log Analytics.
284
285
```python { .api }
286
class LogAnalyticsConfiguration:
287
"""Log Analytics workspace configuration."""
288
customer_id: Optional[str]
289
shared_key: Optional[str]
290
```
291
292
**Usage Example:**
293
294
```python
295
from azure.mgmt.web.models import AppLogsConfiguration, LogAnalyticsConfiguration
296
297
# Configure Log Analytics
298
log_analytics_config = LogAnalyticsConfiguration(
299
customer_id="your-workspace-customer-id",
300
shared_key="your-workspace-shared-key"
301
)
302
303
# Configure application logging
304
app_logs_config = AppLogsConfiguration(
305
destination="log-analytics",
306
log_analytics_configuration=log_analytics_config
307
)
308
309
# Apply to Kubernetes environment
310
kube_env = KubeEnvironment(
311
location="East US",
312
app_logs_configuration=app_logs_config
313
)
314
```
315
316
## Arc Integration
317
318
### Configure Azure Arc Connection
319
320
Enable Azure Arc integration for hybrid and multi-cloud scenarios.
321
322
```python { .api }
323
class Arc:
324
"""Azure Arc configuration for Kubernetes environment."""
325
artifact_storage_class_name: Optional[str]
326
artifact_storage_mount_path: Optional[str]
327
artifact_storage_node_name: Optional[str]
328
artifact_storage_access_mode: Optional[str]
329
```
330
331
**Usage Example:**
332
333
```python
334
from azure.mgmt.web.models import Arc
335
336
# Configure Arc integration
337
arc_config = Arc(
338
artifact_storage_class_name="default",
339
artifact_storage_mount_path="/mnt/artifacts",
340
artifact_storage_access_mode="ReadWriteOnce"
341
)
342
343
# Apply Arc configuration
344
kube_env = KubeEnvironment(
345
location="East US",
346
arc=arc_config,
347
kind="arc" # Specify Arc-enabled environment
348
)
349
```
350
351
## Environment Networking
352
353
### Internal vs External Environments
354
355
Configure network accessibility for the Kubernetes environment.
356
357
**Usage Example:**
358
359
```python
360
# Create internal (private) environment
361
internal_env = KubeEnvironment(
362
location="East US",
363
is_internal=True, # Private environment
364
container_apps_configuration=ContainerAppsConfiguration(
365
platform_reserved_cidr="10.1.0.0/16",
366
platform_reserved_dns_ip="10.1.0.10"
367
)
368
)
369
370
# Create external (public) environment
371
external_env = KubeEnvironment(
372
location="East US",
373
is_internal=False, # Public environment
374
container_apps_configuration=ContainerAppsConfiguration(
375
platform_reserved_cidr="10.2.0.0/16",
376
platform_reserved_dns_ip="10.2.0.10"
377
)
378
)
379
```
380
381
## Types
382
383
### KubeEnvironment
384
385
```python { .api }
386
class KubeEnvironment:
387
"""Represents a Kubernetes environment."""
388
id: Optional[str]
389
name: Optional[str]
390
type: Optional[str]
391
location: str
392
tags: Optional[Dict[str, str]]
393
kind: Optional[str] # "containerapp", "arc"
394
provisioning_state: Optional[str] # "Succeeded", "Failed", "InProgress"
395
deployment_errors: Optional[str]
396
is_internal: Optional[bool]
397
default_domain: Optional[str]
398
static_ip: Optional[str]
399
container_apps_configuration: Optional[ContainerAppsConfiguration]
400
app_logs_configuration: Optional[AppLogsConfiguration]
401
arc: Optional[Arc]
402
```
403
404
### KubeEnvironmentProfile
405
406
```python { .api }
407
class KubeEnvironmentProfile:
408
"""Profile reference for a Kubernetes environment."""
409
id: Optional[str]
410
name: Optional[str]
411
type: Optional[str]
412
```
413
414
### ContainerAppsConfiguration
415
416
```python { .api }
417
class ContainerAppsConfiguration:
418
"""Container Apps configuration settings."""
419
dapr_ai_instrumentation_key: Optional[str]
420
dapr_ai_connection_string: Optional[str]
421
platform_reserved_cidr: Optional[str]
422
platform_reserved_dns_ip: Optional[str]
423
control_plane_subnet_resource_id: Optional[str]
424
app_subnet_resource_id: Optional[str]
425
docker_bridge_cidr: Optional[str]
426
```
427
428
### AppLogsConfiguration
429
430
```python { .api }
431
class AppLogsConfiguration:
432
"""Application logging configuration."""
433
destination: Optional[str]
434
log_analytics_configuration: Optional[LogAnalyticsConfiguration]
435
```
436
437
### LogAnalyticsConfiguration
438
439
```python { .api }
440
class LogAnalyticsConfiguration:
441
"""Log Analytics workspace connection settings."""
442
customer_id: Optional[str]
443
shared_key: Optional[str]
444
```