# AzureKubernetesEnvironmentResource.AddLoadBalancer

- Module: [Aspire.Hosting.Azure.Kubernetes](/reference/api/go/aspire.hosting.azure.kubernetes.md)
- Defined on: [AzureKubernetesEnvironmentResource](/reference/api/go/aspire.hosting.azure.kubernetes/azurekubernetesenvironmentresource.md)
- Version: `17.0.0`
- Kind: `method`

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
type AzureKubernetesEnvironmentResource interface {
    // ... omitted for brevity
    AddLoadBalancer(
        name string,
        subnet AzureSubnetResource,
    ) AzureKubernetesLoadBalancerResource
}
```

## Signature

```go
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()`.

## Defined on

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