Skip to content
Docs Try Aspire
Docs Try

AzureKubernetesEnvironmentExtensions Methods

Class Methods 7 members
Provides extension methods for adding Azure Kubernetes Service (AKS) environments to the application model.
AddAzureKubernetesEnvironment(IDistributedApplicationBuilder, string) Section titled AddAzureKubernetesEnvironment(IDistributedApplicationBuilder, string) extension IResourceBuilder<AzureKubernetesEnvironmentResource>
Adds an Azure Kubernetes Service (AKS) environment to the distributed application. This provisions an AKS cluster and configures it as a Kubernetes compute environment.
public static class AzureKubernetesEnvironmentExtensions
{
public static IResourceBuilder<AzureKubernetesEnvironmentResource> AddAzureKubernetesEnvironment(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder.
name string The name of the AKS environment resource.
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1.
This method internally creates a Kubernetes environment for Helm-based deployment and provisions an AKS cluster via Azure Bicep. It combines the functionality of AddKubernetesEnvironment with Azure-specific provisioning.
var aks = builder.AddAzureKubernetesEnvironment("aks");
AddNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, string, int, int) Section titled AddNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, string, int, int) extension IResourceBuilder<AksNodePoolResource>
Adds a node pool to the AKS cluster.
public static class AzureKubernetesEnvironmentExtensions
{
public static IResourceBuilder<AksNodePoolResource> AddNodePool(
this IResourceBuilder<AzureKubernetesEnvironmentResource> builder,
string name,
string vmSize = "Standard_D2s_v5",
int minCount = 1,
int maxCount = 3)
{
// ...
}
}
builder IResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.
name string The name of the node pool.
vmSize string optional The VM size for nodes. Defaults to Standard_D2s_v5 if not specified.
minCount int optional The minimum node count for autoscaling. Defaults to 1.
maxCount int optional The maximum node count for autoscaling. Defaults to 3.
IResourceBuilder<AksNodePoolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the new node pool.
The returned node pool resource can be passed to KubernetesEnvironmentExtensions.WithNodePool on compute resources to schedule workloads on this pool.
var aks = builder.AddAzureKubernetesEnvironment("aks");
// With defaults (Standard_D2s_v5, 1-3 nodes)
var pool = aks.AddNodePool("workload");
// With explicit VM size and scaling
var gpuPool = aks.AddNodePool("gpu", "Standard_NC6s_v3", 0, 5);
WithContainerRegistry(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureContainerRegistryResource>) Section titled WithContainerRegistry(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureContainerRegistryResource>) extension IResourceBuilder<AzureKubernetesEnvironmentResource>
Configures the AKS environment to use a specific Azure Container Registry for image storage. When set, this replaces the auto-created default container registry.
public static class AzureKubernetesEnvironmentExtensions
{
public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithContainerRegistry(
this IResourceBuilder<AzureKubernetesEnvironmentResource> builder,
IResourceBuilder<AzureContainerRegistryResource> registry)
{
// ...
}
}
builder IResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.
registry IResourceBuilder<AzureContainerRegistryResource> The Azure Container Registry resource builder.
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
If not called, a default Azure Container Registry is automatically created. The registry endpoint is flowed to the inner Kubernetes environment so that Helm deployments can push and pull images.
WithSubnet(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureSubnetResource>) Section titled WithSubnet(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureSubnetResource>) extension IResourceBuilder<AzureKubernetesEnvironmentResource>
Configures the AKS cluster to use a VNet subnet for node pool networking. Unlike AzureVirtualNetworkExtensions.WithDelegatedSubnet, this does NOT add a service delegation to the subnet — AKS uses plain (non-delegated) subnets.
public static class AzureKubernetesEnvironmentExtensions
{
public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithSubnet(
this IResourceBuilder<AzureKubernetesEnvironmentResource> builder,
IResourceBuilder<AzureSubnetResource> subnet)
{
// ...
}
}
builder IResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.
subnet IResourceBuilder<AzureSubnetResource> The subnet to use for AKS node pools.
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
var vnet = builder.AddAzureVirtualNetwork("vnet", "10.0.0.0/16");
var subnet = vnet.AddSubnet("aks-subnet", "10.0.0.0/22");
var aks = builder.AddAzureKubernetesEnvironment("aks")
.WithSubnet(subnet);
WithSubnet(IResourceBuilder<AksNodePoolResource>, IResourceBuilder<AzureSubnetResource>) Section titled WithSubnet(IResourceBuilder<AksNodePoolResource>, IResourceBuilder<AzureSubnetResource>) extension IResourceBuilder<AksNodePoolResource>
Configures a specific AKS node pool to use its own VNet subnet. When applied, this node pool's subnet overrides the environment-level subnet set via AzureKubernetesEnvironmentExtensions.WithSubnet.
public static class AzureKubernetesEnvironmentExtensions
{
public static IResourceBuilder<AksNodePoolResource> WithSubnet(
this IResourceBuilder<AksNodePoolResource> builder,
IResourceBuilder<AzureSubnetResource> subnet)
{
// ...
}
}
builder IResourceBuilder<AksNodePoolResource> The node pool resource builder.
subnet IResourceBuilder<AzureSubnetResource> The subnet to use for this node pool.
IResourceBuilder<AksNodePoolResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
var vnet = builder.AddAzureVirtualNetwork("vnet", "10.0.0.0/16");
var defaultSubnet = vnet.AddSubnet("default", "10.0.0.0/22");
var gpuSubnet = vnet.AddSubnet("gpu-subnet", "10.0.4.0/24");
var aks = builder.AddAzureKubernetesEnvironment("aks")
.WithSubnet(defaultSubnet);
var gpuPool = aks.AddNodePool("gpu", AksNodeVmSizes.StandardNCSv3.StandardNC6sV3, 0, 5)
.WithSubnet(gpuSubnet);
WithSystemNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, int, int) Section titled WithSystemNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, int, int) extension IResourceBuilder<AzureKubernetesEnvironmentResource>
Replaces the default system node pool with a customized configuration.
public static class AzureKubernetesEnvironmentExtensions
{
public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithSystemNodePool(
this IResourceBuilder<AzureKubernetesEnvironmentResource> builder,
string vmSize = "Standard_D2s_v5",
int minCount = 1,
int maxCount = 3)
{
// ...
}
}
builder IResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.
vmSize string optional The VM size for system pool nodes. Defaults to Standard_D2s_v5 if not specified.
minCount int optional The minimum node count for autoscaling. Defaults to 1.
maxCount int optional The maximum node count for autoscaling. Defaults to 3.
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
Every AKS cluster requires exactly one system node pool for hosting system pods. By default, the system pool uses Standard_D2s_v5. Use this method to change the VM size when the default SKU is not available in your subscription or region. Calling this method multiple times replaces the previous system pool configuration.
var aks = builder.AddAzureKubernetesEnvironment("aks")
.WithSystemNodePool("Standard_B2s");
// With explicit scaling
var aks2 = builder.AddAzureKubernetesEnvironment("aks2")
.WithSystemNodePool("Standard_B2s", minCount: 2, maxCount: 5);
WithWorkloadIdentity(IResourceBuilder<AzureKubernetesEnvironmentResource>, bool) Section titled WithWorkloadIdentity(IResourceBuilder<AzureKubernetesEnvironmentResource>, bool) extension IResourceBuilder<AzureKubernetesEnvironmentResource>
Enables or disables workload identity on the AKS environment, allowing pods to authenticate to Azure services using federated credentials.
public static class AzureKubernetesEnvironmentExtensions
{
public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithWorkloadIdentity(
this IResourceBuilder<AzureKubernetesEnvironmentResource> builder,
bool enabled = true)
{
// ...
}
}
builder IResourceBuilder<AzureKubernetesEnvironmentResource> The resource builder.
enabled bool optional true to enable workload identity (the default); false to disable it.
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
This ensures the AKS cluster is configured with OIDC issuer and workload identity enabled. Workload identity is automatically wired when compute resources have an Azure.AppIdentityAnnotation, which is added by WithAzureUserAssignedIdentity or auto-created by AzureResourcePreparer.