Microsoft Azure Web Apps Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Management of Kubernetes environments for container-based applications and microservices hosted on Azure Kubernetes Service integration.
azure.mgmt.web.operations.KubeEnvironmentsOperationsclient.kube_environmentsfrom azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.web.models import (
KubeEnvironment, KubeEnvironmentProfile, ContainerAppsConfiguration,
AppLogsConfiguration, Arc
)
from azure.identity import DefaultAzureCredentialfrom azure.mgmt.web import WebSiteManagementClient
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()
client = WebSiteManagementClient(credential, subscription_id)
# List all Kubernetes environments
kube_envs = client.kube_environments.list_by_subscription()
for env in kube_envs:
print(f"Kube Environment: {env.name}, Location: {env.location}")
# Get specific Kubernetes environment details
kube_env_details = client.kube_environments.get(
resource_group_name="my-resource-group",
name="my-kube-environment"
)
print(f"Default Domain: {kube_env_details.default_domain}")Create a new Kubernetes environment or update an existing one.
def create_or_update(
self,
resource_group_name: str,
name: str,
kube_environment_envelope: KubeEnvironment,
**kwargs
) -> KubeEnvironment:
"""
Create or update a Kubernetes environment.
Args:
resource_group_name: Name of the resource group
name: Name of the Kubernetes environment
kube_environment_envelope: Kubernetes environment configuration
Returns:
KubeEnvironment object
"""Usage Example:
from azure.mgmt.web.models import (
KubeEnvironment, ContainerAppsConfiguration, AppLogsConfiguration
)
# Configure Container Apps settings
container_apps_config = ContainerAppsConfiguration(
dapr_ai_instrumentation_key="your-app-insights-key",
platform_reserved_cidr="10.0.0.0/16",
platform_reserved_dns_ip="10.0.0.10",
control_plane_subnet_resource_id="/subscriptions/{subscription-id}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{subnet}"
)
# Configure logging
app_logs_config = AppLogsConfiguration(
destination="log-analytics",
log_analytics_configuration={
"customer_id": "your-workspace-id"
}
)
# Create Kubernetes environment
kube_env_config = KubeEnvironment(
location="East US",
kind="containerapp",
container_apps_configuration=container_apps_config,
app_logs_configuration=app_logs_config,
is_internal=False
)
kube_env = client.kube_environments.create_or_update(
resource_group_name="my-resource-group",
name="my-kube-environment",
kube_environment_envelope=kube_env_config
)
print(f"Created Kubernetes environment: {kube_env.name}")Retrieve details for a specific Kubernetes environment.
def get(
self,
resource_group_name: str,
name: str,
**kwargs
) -> KubeEnvironment:
"""
Get Kubernetes environment details.
Args:
resource_group_name: Name of the resource group
name: Name of the Kubernetes environment
Returns:
KubeEnvironment object
"""Get all Kubernetes environments in a subscription or resource group.
def list_by_subscription(self, **kwargs) -> List[KubeEnvironment]:
"""
List all Kubernetes environments in the subscription.
Returns:
List of KubeEnvironment objects
"""
def list_by_resource_group(
self,
resource_group_name: str,
**kwargs
) -> List[KubeEnvironment]:
"""
List Kubernetes environments in a resource group.
Args:
resource_group_name: Name of the resource group
Returns:
List of KubeEnvironment objects
"""Modify an existing Kubernetes environment.
def update(
self,
resource_group_name: str,
name: str,
kube_environment_envelope: KubeEnvironmentPatchResource,
**kwargs
) -> KubeEnvironment:
"""
Update a Kubernetes environment.
Args:
resource_group_name: Name of the resource group
name: Name of the Kubernetes environment
kube_environment_envelope: Environment update configuration
Returns:
Updated KubeEnvironment object
"""Remove a Kubernetes environment and all its resources.
def delete(
self,
resource_group_name: str,
name: str,
**kwargs
) -> None:
"""
Delete a Kubernetes environment.
Args:
resource_group_name: Name of the resource group
name: Name of the Kubernetes environment
"""Usage Example:
# List environments by resource group
environments = client.kube_environments.list_by_resource_group(
resource_group_name="my-resource-group"
)
for env in environments:
print(f"Environment: {env.name}, Provisioning State: {env.provisioning_state}")
# Get specific environment
env_details = client.kube_environments.get(
resource_group_name="my-resource-group",
name="my-kube-environment"
)
print(f"Static IP: {env_details.static_ip}")
print(f"Default Domain: {env_details.default_domain}")Set up container app configurations within the Kubernetes environment.
class ContainerAppsConfiguration:
"""Container Apps configuration for Kubernetes environment."""
dapr_ai_instrumentation_key: Optional[str]
dapr_ai_connection_string: Optional[str]
platform_reserved_cidr: Optional[str]
platform_reserved_dns_ip: Optional[str]
control_plane_subnet_resource_id: Optional[str]
app_subnet_resource_id: Optional[str]
docker_bridge_cidr: Optional[str]Usage Example:
from azure.mgmt.web.models import ContainerAppsConfiguration
# Configure networking and Dapr
container_config = ContainerAppsConfiguration(
dapr_ai_instrumentation_key="your-app-insights-key",
platform_reserved_cidr="10.0.0.0/16",
platform_reserved_dns_ip="10.0.0.10",
control_plane_subnet_resource_id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{control-subnet}",
app_subnet_resource_id="/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{app-subnet}",
docker_bridge_cidr="172.17.0.1/16"
)
# Apply configuration
kube_env = KubeEnvironment(
location="East US",
container_apps_configuration=container_config
)Set up centralized logging for container applications.
class AppLogsConfiguration:
"""Application logs configuration."""
destination: Optional[str] # "log-analytics", "azure-monitor"
log_analytics_configuration: Optional[LogAnalyticsConfiguration]Connect the Kubernetes environment to Azure Log Analytics.
class LogAnalyticsConfiguration:
"""Log Analytics workspace configuration."""
customer_id: Optional[str]
shared_key: Optional[str]Usage Example:
from azure.mgmt.web.models import AppLogsConfiguration, LogAnalyticsConfiguration
# Configure Log Analytics
log_analytics_config = LogAnalyticsConfiguration(
customer_id="your-workspace-customer-id",
shared_key="your-workspace-shared-key"
)
# Configure application logging
app_logs_config = AppLogsConfiguration(
destination="log-analytics",
log_analytics_configuration=log_analytics_config
)
# Apply to Kubernetes environment
kube_env = KubeEnvironment(
location="East US",
app_logs_configuration=app_logs_config
)Enable Azure Arc integration for hybrid and multi-cloud scenarios.
class Arc:
"""Azure Arc configuration for Kubernetes environment."""
artifact_storage_class_name: Optional[str]
artifact_storage_mount_path: Optional[str]
artifact_storage_node_name: Optional[str]
artifact_storage_access_mode: Optional[str]Usage Example:
from azure.mgmt.web.models import Arc
# Configure Arc integration
arc_config = Arc(
artifact_storage_class_name="default",
artifact_storage_mount_path="/mnt/artifacts",
artifact_storage_access_mode="ReadWriteOnce"
)
# Apply Arc configuration
kube_env = KubeEnvironment(
location="East US",
arc=arc_config,
kind="arc" # Specify Arc-enabled environment
)Configure network accessibility for the Kubernetes environment.
Usage Example:
# Create internal (private) environment
internal_env = KubeEnvironment(
location="East US",
is_internal=True, # Private environment
container_apps_configuration=ContainerAppsConfiguration(
platform_reserved_cidr="10.1.0.0/16",
platform_reserved_dns_ip="10.1.0.10"
)
)
# Create external (public) environment
external_env = KubeEnvironment(
location="East US",
is_internal=False, # Public environment
container_apps_configuration=ContainerAppsConfiguration(
platform_reserved_cidr="10.2.0.0/16",
platform_reserved_dns_ip="10.2.0.10"
)
)class KubeEnvironment:
"""Represents a Kubernetes environment."""
id: Optional[str]
name: Optional[str]
type: Optional[str]
location: str
tags: Optional[Dict[str, str]]
kind: Optional[str] # "containerapp", "arc"
provisioning_state: Optional[str] # "Succeeded", "Failed", "InProgress"
deployment_errors: Optional[str]
is_internal: Optional[bool]
default_domain: Optional[str]
static_ip: Optional[str]
container_apps_configuration: Optional[ContainerAppsConfiguration]
app_logs_configuration: Optional[AppLogsConfiguration]
arc: Optional[Arc]class KubeEnvironmentProfile:
"""Profile reference for a Kubernetes environment."""
id: Optional[str]
name: Optional[str]
type: Optional[str]class ContainerAppsConfiguration:
"""Container Apps configuration settings."""
dapr_ai_instrumentation_key: Optional[str]
dapr_ai_connection_string: Optional[str]
platform_reserved_cidr: Optional[str]
platform_reserved_dns_ip: Optional[str]
control_plane_subnet_resource_id: Optional[str]
app_subnet_resource_id: Optional[str]
docker_bridge_cidr: Optional[str]class AppLogsConfiguration:
"""Application logging configuration."""
destination: Optional[str]
log_analytics_configuration: Optional[LogAnalyticsConfiguration]class LogAnalyticsConfiguration:
"""Log Analytics workspace connection settings."""
customer_id: Optional[str]
shared_key: Optional[str]Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-web