# AddLoadBalancer

- Module: [Aspire.Hosting.Azure.Kubernetes](/reference/api/go/aspire.hosting.azure.kubernetes.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`AzureKubernetesEnvironmentResource`](/reference/api/go/aspire.hosting.azure.kubernetes/azurekubernetesenvironmentresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Adds an Azure Application Gateway for Containers (AGC) `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.

## Definition

```go
func (AzureKubernetesEnvironmentResource) AddLoadBalancer(
    name string,
    subnet AzureSubnetResource,
) AzureKubernetesLoadBalancerResource
```

## Parameters

- `name` (`string`) -- The name of the load balancer resource. Used to derive the in-cluster `ApplicationLoadBalancer` name (`alb-{name}`) referenced by gateway/ingress annotations.
- `subnet` ([`AzureSubnetResource`](/reference/api/go/aspire.hosting.azure.kubernetes/azuresubnetresource.md)) -- 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 `AddLoadBalancer` calls against the same subnet.

## Returns

[`AzureKubernetesLoadBalancerResource`](/reference/api/go/aspire.hosting.azure.kubernetes/azurekubernetesloadbalancerresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`AzureKubernetesEnvironmentResource`](/reference/api/go/aspire.hosting.azure.kubernetes/azurekubernetesenvironmentresource.md)
