AzureKubernetesEnvironmentExtensions Methods
AddAzureKubernetesEnvironment(IDistributedApplicationBuilder, string) Section titled AddAzureKubernetesEnvironment(IDistributedApplicationBuilder, string)extensionIResourceBuilder<AzureKubernetesEnvironmentResource> public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AzureKubernetesEnvironmentResource> AddAzureKubernetesEnvironment( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builderIDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder .namestringThe name of the AKS environment resource.Returns
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
AddKubernetesEnvironment with Azure-specific provisioning. The cluster uses the Standard control-plane tier by default, which includes an uptime SLA and a cluster-management charge. Use ConfigureInfrastructure to select a different tier. Examples
var aks = builder.AddAzureKubernetesEnvironment("aks");AddLoadBalancer(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, IResourceBuilder<AzureSubnetResource>) Section titled AddLoadBalancer(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, IResourceBuilder<AzureSubnetResource>)extensionIResourceBuilder<AzureKubernetesLoadBalancerResource> ApplicationLoadBalancer to this AKS environment, bound to the supplied delegated subnet. Returns a resource builder that can be passed to gateway.WithLoadBalancer(lb) / ingress.WithLoadBalancer(lb) to route traffic through this load balancer. public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AzureKubernetesLoadBalancerResource> AddLoadBalancer( this IResourceBuilder<AzureKubernetesEnvironmentResource> builder, string name, IResourceBuilder<AzureSubnetResource> subnet) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.namestringThe name of the load balancer resource. Used to derive the in-cluster ApplicationLoadBalancer name ( alb-{name} ) referenced by gateway/ingress annotations.subnetIResourceBuilder<AzureSubnetResource> A subnet that will be associated with the AGC ALB. The subnet is automatically delegated to Microsoft.ServiceNetworking/trafficControllers ; this is required by AGC and is idempotent across multiple AzureKubernetesEnvironmentExtensions.AddLoadBalancer calls against the same subnet.Returns
IResourceBuilder<AzureKubernetesLoadBalancerResource> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
Each AGC Application caps at 5 frontends, so applications that need more should call Add multiple times (each call may use the same or a different subnet) and pin gateways/ingresses to specific load balancers via Azure.
Calling this method opts the AKS cluster into the managed Gateway API installation ( ingress) and the AGC ALB controller add-on ( ingress). The application load balancer property requires a preview AKS Bicep API version, so this implicitly uses 2026- for the cluster's emitted API version. Subscriptions/regions where the AKS preview features Microsoft. and Microsoft. are not registered will see deployment failures.
After provisioning, a per-LB pipeline step ( apply-) waits for the azure- GatewayClass to appear in the cluster and then kubectl apply s the Application custom resource pointing at the supplied subnet.
Examples
var vnet = builder.AddAzureVirtualNetwork("vnet", "10.0.0.0/16");var aksSubnet = vnet.AddSubnet("aks", "10.0.0.0/22");var albSubnet = vnet.AddSubnet("alb", "10.0.4.0/24");
var aks = builder.AddAzureKubernetesEnvironment("aks").WithSubnet(aksSubnet);var lb = aks.AddLoadBalancer("lb", albSubnet);
aks.AddGateway("public").WithLoadBalancer(lb);AddNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, string, int, int) Section titled AddNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, string, int, int)extensionIResourceBuilder<AksNodePoolResource> 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) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.namestringThe name of the node pool.vmSize stringoptionalThe VM size for nodes. Defaults to Standard_D2s_v5 if not specified.minCount intoptionalThe minimum node count for autoscaling. Defaults to 1.maxCount intoptionalThe maximum node count for autoscaling. Defaults to 3.Returns
IResourceBuilder<AksNodePoolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the new node pool.Remarks
KubernetesEnvironmentExtensions.WithNodePool on compute resources to schedule workloads on this pool. Examples
var aks = builder.AddAzureKubernetesEnvironment("aks");
// With defaults (Standard_D2s_v5, 1-3 nodes)var pool = aks.AddNodePool("workload");
// With explicit VM size and scalingvar gpuPool = aks.AddNodePool("gpu", "Standard_NC6s_v3", 0, 5);AddNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, Action<AksNodePoolConfig>) Section titled AddNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, string, Action<AksNodePoolConfig>)extensionIResourceBuilder<AksNodePoolResource> public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AksNodePoolResource> AddNodePool( this IResourceBuilder<AzureKubernetesEnvironmentResource> builder, string name, Action<AksNodePoolConfig> configure) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.namestringThe name of the node pool.configureAction<AksNodePoolConfig> A callback to configure VM size, autoscaling, and OS SKU.Returns
IResourceBuilder<AksNodePoolResource> The resource builder for the new node pool.Exceptions
ArgumentNullExceptionThe builder or callback is null.ArgumentExceptionThe name is empty or whitespace.Remarks
Examples
var workers = aks.AddNodePool("workers", pool =>{ pool.MinCount = 0; pool.MaxCount = 5; pool.OsSku = "AzureLinux";});WithContainerRegistry(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureContainerRegistryResource>) Section titled WithContainerRegistry(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureContainerRegistryResource>)extensionIResourceBuilder<AzureKubernetesEnvironmentResource> public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithContainerRegistry( this IResourceBuilder<AzureKubernetesEnvironmentResource> builder, IResourceBuilder<AzureContainerRegistryResource> registry) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.registryIResourceBuilder<AzureContainerRegistryResource> The Azure Container Registry resource builder.Returns
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
WithSubnet(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureSubnetResource>) Section titled WithSubnet(IResourceBuilder<AzureKubernetesEnvironmentResource>, IResourceBuilder<AzureSubnetResource>)extensionIResourceBuilder<AzureKubernetesEnvironmentResource> 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) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.subnetIResourceBuilder<AzureSubnetResource> The subnet to use for AKS node pools.Returns
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Examples
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>)extensionIResourceBuilder<AksNodePoolResource> AzureKubernetesEnvironmentExtensions.WithSubnet . public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AksNodePoolResource> WithSubnet( this IResourceBuilder<AksNodePoolResource> builder, IResourceBuilder<AzureSubnetResource> subnet) { // ... }}Parameters
builderIResourceBuilder<AksNodePoolResource> The node pool resource builder.subnetIResourceBuilder<AzureSubnetResource> The subnet to use for this node pool.Returns
IResourceBuilder<AksNodePoolResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Examples
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)extensionIResourceBuilder<AzureKubernetesEnvironmentResource> public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithSystemNodePool( this IResourceBuilder<AzureKubernetesEnvironmentResource> builder, string vmSize = "Standard_D2s_v5", int minCount = 1, int maxCount = 3) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.vmSize stringoptionalThe VM size for system pool nodes. Defaults to Standard_D2s_v5 if not specified.minCount intoptionalThe minimum node count for autoscaling. Defaults to 1.maxCount intoptionalThe maximum node count for autoscaling. Defaults to 3.Returns
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
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. Examples
var aks = builder.AddAzureKubernetesEnvironment("aks") .WithSystemNodePool("Standard_B2s");
// With explicit scalingvar aks2 = builder.AddAzureKubernetesEnvironment("aks2") .WithSystemNodePool("Standard_B2s", minCount: 2, maxCount: 5);WithSystemNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, Action<AksNodePoolConfig>) Section titled WithSystemNodePool(IResourceBuilder<AzureKubernetesEnvironmentResource>, Action<AksNodePoolConfig>)extensionIResourceBuilder<AzureKubernetesEnvironmentResource> public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithSystemNodePool( this IResourceBuilder<AzureKubernetesEnvironmentResource> builder, Action<AksNodePoolConfig> configure) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder.configureAction<AksNodePoolConfig> A callback to configure VM size, autoscaling, and OS SKU.Returns
IResourceBuilder<AzureKubernetesEnvironmentResource> The AKS environment resource builder for chaining.Exceptions
ArgumentNullExceptionThe builder or callback is null.Remarks
Examples
var aks = builder.AddAzureKubernetesEnvironment("aks") .WithSystemNodePool(pool => { pool.VmSize = "Standard_D2as_v5"; pool.OsSku = "AzureLinux"; });WithWorkloadIdentity(IResourceBuilder<AzureKubernetesEnvironmentResource>, bool) Section titled WithWorkloadIdentity(IResourceBuilder<AzureKubernetesEnvironmentResource>, bool)extensionIResourceBuilder<AzureKubernetesEnvironmentResource> public static class AzureKubernetesEnvironmentExtensions{ public static IResourceBuilder<AzureKubernetesEnvironmentResource> WithWorkloadIdentity( this IResourceBuilder<AzureKubernetesEnvironmentResource> builder, bool enabled = true) { // ... }}Parameters
builderIResourceBuilder<AzureKubernetesEnvironmentResource> The resource builder.enabledbooloptionaltrue to enable workload identity (the default); false to disable it.Returns
IResourceBuilder<AzureKubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.Remarks
Azure.AppIdentityAnnotation , which is added by WithAzureUserAssignedIdentity or auto-created by AzureResourcePreparer .