# Application Gateway for Containers

Source: /azure/services/application-gateway-for-containers/

## Introduction

Application Gateway for Containers is an application layer (layer 7) load balancing and ingress service for Kubernetes workloads.
It routes HTTP, HTTPS, and gRPC traffic to applications in Azure Kubernetes Service (AKS), and you configure it from Kubernetes with Gateway API and Ingress resources.
An Application Gateway for Containers resource, of type `Microsoft.ServiceNetworking/trafficControllers`, holds its frontends, the entry points that clients connect to; its association with the subnet where Azure places its proxies; and its security policies, which attach a web application firewall (WAF) policy.
For more information, see [What is Application Gateway for Containers?](https://learn.microsoft.com/azure/application-gateway/for-containers/overview) and [Application Gateway for Containers components](https://learn.microsoft.com/azure/application-gateway/for-containers/application-gateway-for-containers-components).

LocalStack for Azure emulates the Application Gateway for Containers control plane.
Application Gateway for Containers resources, frontends, associations, and security policies are Azure Resource Manager resources that you manage with the same Azure CLI commands, and the emulator validates them and returns them in the shape Azure returns them.
No traffic passes through the service: the frontends' FQDNs do not resolve, and no ALB Controller runs in AKS clusters.
The supported APIs are listed in the [API Coverage](#api-coverage) section.

## Getting started

This guide is designed for users new to Application Gateway for Containers and assumes basic knowledge of the Azure CLI and `lstk az`.
The following example follows the bring-your-own deployment strategy: it creates an Application Gateway for Containers resource and a frontend, associates the resource with a delegated subnet, and attaches a WAF policy.

:::note
The `az network alb` commands are part of the `alb` Azure CLI extension, which is in preview.
Install it, or update it if it is already installed:

```bash
az extension add --name alb --upgrade
```
:::

Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running:

```bash
lstk az start-interception
```

This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API.
To revert this configuration, run:

```bash
lstk az stop-interception
```

This reconfigures the `az` CLI to send commands to the official Azure management REST API.

### Create a resource group

Create a resource group for the example:

```bash
az group create \
  --name rg-agc-demo \
  --location westeurope
```

```bash title="Output"
{
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo",
  "location": "westeurope",
  "managedBy": null,
  "name": "rg-agc-demo",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}
```

### Create the resource and a frontend

Create the Application Gateway for Containers resource:

```bash
az network alb create \
  --resource-group rg-agc-demo \
  --name alb-demo
```

```bash title="Output"
{
  "associations": [],
  "configurationEndpoints": [
    "0cac247ff8724775ab47e565f7a496cf.alb.azure.com"
  ],
  "frontends": [],
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo/providers/Microsoft.ServiceNetworking/trafficControllers/alb-demo",
  "location": "westeurope",
  "name": "alb-demo",
  "provisioningState": "Succeeded",
  "resourceGroup": "rg-agc-demo",
  "securityPolicies": [],
  ...
  "type": "Microsoft.ServiceNetworking/TrafficControllers"
}
```

Create a frontend. Its FQDN is the host name that clients connect to:

```bash
az network alb frontend create \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --frontend-name frontend-demo
```

```bash title="Output"
{
  "fqdn": "0ok50ga837ba6oi2.fz25.alb.azure.com",
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo/providers/Microsoft.ServiceNetworking/trafficControllers/alb-demo/frontends/frontend-demo",
  "location": "westeurope",
  "name": "frontend-demo",
  "provisioningState": "Succeeded",
  "resourceGroup": "rg-agc-demo",
  ...
  "type": "Microsoft.ServiceNetworking/TrafficControllers/Frontends"
}
```

### Associate the resource with a subnet

Create a virtual network with a subnet of at least 256 addresses (a /24), and delegate the subnet to Application Gateway for Containers:

```bash
az network vnet create \
  --resource-group rg-agc-demo \
  --name vnet-agc-demo \
  --location westeurope \
  --address-prefixes 10.225.0.0/16 \
  --subnet-name subnet-alb \
  --subnet-prefixes 10.225.0.0/24 \
  --output none

az network vnet subnet update \
  --resource-group rg-agc-demo \
  --vnet-name vnet-agc-demo \
  --name subnet-alb \
  --delegations Microsoft.ServiceNetworking/trafficControllers \
  --query "delegations[0].serviceName" \
  --output tsv
```

```bash title="Output"
Microsoft.ServiceNetworking/trafficControllers
```

Read the subnet's ID, and associate the resource with the subnet:

```bash
SUBNET_ID=$(az network vnet subnet show \
  --resource-group rg-agc-demo \
  --vnet-name vnet-agc-demo \
  --name subnet-alb \
  --query id \
  --output tsv)

az network alb association create \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --association-name association-demo \
  --subnet "$SUBNET_ID"
```

```bash title="Output"
{
  "associationType": "subnets",
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo/providers/Microsoft.ServiceNetworking/trafficControllers/alb-demo/associations/association-demo",
  "location": "westeurope",
  "name": "association-demo",
  "provisioningState": "Succeeded",
  "resourceGroup": "rg-agc-demo",
  "subnet": {
    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo/providers/Microsoft.Network/virtualNetworks/vnet-agc-demo/subnets/subnet-alb",
    "resourceGroup": "rg-agc-demo"
  },
  ...
  "type": "Microsoft.ServiceNetworking/TrafficControllers/Associations"
}
```

The subnet now lists the IP configurations of the two instances that Azure places there:

```bash
az network vnet subnet show \
  --resource-group rg-agc-demo \
  --vnet-name vnet-agc-demo \
  --name subnet-alb \
  --query "length(ipConfigurations)" \
  --output tsv
```

```bash title="Output"
2
```

### Attach a WAF policy

Create a WAF policy with the Default Rule Set 2.1, which Application Gateway for Containers runs, and read its ID:

```bash
WAF_POLICY_ID=$(az network application-gateway waf-policy create \
  --resource-group rg-agc-demo \
  --name wafagcdemo \
  --type Microsoft_DefaultRuleSet \
  --version 2.1 \
  --query id \
  --output tsv)
```

Create a WAF security policy that uses the WAF policy:

```bash
az network alb security-policy waf create \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --name waf-demo \
  --waf-policy-id "$WAF_POLICY_ID"
```

```bash title="Output"
{
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo/providers/Microsoft.ServiceNetworking/trafficControllers/alb-demo/securityPolicies/waf-demo",
  "location": "westeurope",
  "name": "waf-demo",
  "policyType": "WAF",
  "provisioningState": "Succeeded",
  "resourceGroup": "rg-agc-demo",
  ...
  "type": "Microsoft.ServiceNetworking/TrafficControllers/SecurityPolicies",
  "wafPolicy": {
    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/wafagcdemo",
    "resourceGroup": "rg-agc-demo"
  }
}
```

Read the security policy's ID, and make it the security policy of the whole resource:

```bash
SECURITY_POLICY_ID=$(az network alb security-policy show \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --name waf-demo \
  --query id \
  --output tsv)

az network alb update \
  --resource-group rg-agc-demo \
  --name alb-demo \
  --waf-policy-id "$SECURITY_POLICY_ID" \
  --query "securityPolicyConfigurations.wafSecurityPolicy.id" \
  --output tsv
```

```bash title="Output"
/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-agc-demo/providers/Microsoft.ServiceNetworking/trafficControllers/alb-demo/securityPolicies/waf-demo
```

### List the resource's children

List the frontends, associations, and security policies of the resource:

```bash
az network alb frontend list \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --query "[].{name:name, state:provisioningState}" \
  --output table

az network alb association list \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --query "[].{name:name, state:provisioningState}" \
  --output table

az network alb security-policy list \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --query "[].{name:name, state:provisioningState}" \
  --output table
```

```bash title="Output"
Name           State
-------------  ---------
frontend-demo  Succeeded
Name              State
----------------  ---------
association-demo  Succeeded
Name      State
--------  ---------
waf-demo  Succeeded
```

### Delete the resources

Delete the frontend, then the Application Gateway for Containers resource, which deletes its association and its security policy:

```bash
az network alb frontend delete \
  --resource-group rg-agc-demo \
  --alb-name alb-demo \
  --name frontend-demo \
  --yes

az network alb delete \
  --resource-group rg-agc-demo \
  --name alb-demo \
  --yes
```

Delete the resource group:

```bash
az group delete \
  --name rg-agc-demo \
  --yes
```

## Features

The Application Gateway for Containers emulator supports the following features:

- **Resource lifecycle**: Create, get, update, list, and delete Application Gateway for Containers resources, by resource group and across a subscription, with their tags. A resource gets its configuration endpoint, and deleting it deletes its frontends, its association, and its security policies.
- **Frontends**: Create, get, update, list, and delete frontends, each with an FQDN under `alb.azure.com`. A resource takes up to five public frontends and one private frontend.
- **Private frontends**: With private ingress, a preview at API version 2026-03-01, a frontend can be private: it names its association, and its FQDN is under `privatelink.alb.azure.com`. Each private frontend is a private link resource, and a private endpoint that names it connects to the resource and is approved at once.
- **Associations**: An association names a subnet delegated to `Microsoft.ServiceNetworking/trafficControllers` that has at least 250 free addresses, and the subnet lists the IP configurations of the two instances Azure places there. A resource takes one association, whose subnet cannot change, and the subnet cannot be deleted while the association holds it.
- **Security policies**: A WAF security policy names an Application Gateway WAF policy in the same subscription and region, and the resource's security policy configuration names the security policy it runs. The WAF policy lists the resources that run it, and cannot be deleted while one does.
- **WAF policy support**: A WAF policy with a feature that Application Gateway for Containers does not run fails to attach, as on Azure: a managed rule set other than the Default Rule Set 2.1 and Bot Manager 1.0 and 1.1, the HTTP DDoS rule set, a custom block response, a rate limit grouped by the `X-Forwarded-For` header, or a JavaScript challenge.
- **Long-running operations**: Writes and deletes answer with Azure's status codes and operation headers, and complete at once.
- **Validation**: The emulator refuses names, request bodies, regions, subnets, and references as Azure does, with Azure's error codes.
- **Resource groups and Resource Graph**: The resources and their children are listed in their resource group and in Resource Graph, and moving them to another resource group is refused, as on Azure.

## Limitations

- **No traffic passes through the service**: The frontends' FQDNs do not resolve, and the emulator runs no proxies, so no request reaches a backend and no WAF policy inspects one.
- **No ALB Controller**: No ALB Controller runs in AKS clusters, so the Gateway API and Ingress resources that configure Application Gateway for Containers have no effect.
- **Changes complete at once**: Creating and deleting an association complete before the command returns, where Azure takes about five minutes for each.
- **IP access rules security policies are refused**: The emulator refuses them as Azure refuses them for a subscription without the preview feature, and keeps no feature registrations.

## Samples

Explore end-to-end examples in the [LocalStack for Azure Samples](https://github.com/localstack/localstack-azure-samples) repository.

## API Coverage


### Application Gateway for Containers API coverage

Source service: `application-gateway-for-containers`. 27 of 27 tracked operations are implemented.

Service documentation: /azure/services/application-gateway-for-containers/

| Operation | Status |
| --- | --- |
| AssociationsInterface.CreateOrUpdate | Implemented |
| AssociationsInterface.Delete | Implemented |
| AssociationsInterface.Get | Implemented |
| AssociationsInterface.ListByTrafficController | Implemented |
| AssociationsInterface.Update | Implemented |
| FrontendsInterface.CreateOrUpdate | Implemented |
| FrontendsInterface.Delete | Implemented |
| FrontendsInterface.Get | Implemented |
| FrontendsInterface.ListByTrafficController | Implemented |
| FrontendsInterface.Update | Implemented |
| PrivateEndpointConnectionsInterface.Delete | Implemented |
| PrivateEndpointConnectionsInterface.Get | Implemented |
| PrivateEndpointConnectionsInterface.ListByTrafficController | Implemented |
| PrivateEndpointConnectionsInterface.Update | Implemented |
| PrivateLinkResourcesInterface.Get | Implemented |
| PrivateLinkResourcesInterface.ListByTrafficController | Implemented |
| SecurityPoliciesInterface.CreateOrUpdate | Implemented |
| SecurityPoliciesInterface.Delete | Implemented |
| SecurityPoliciesInterface.Get | Implemented |
| SecurityPoliciesInterface.ListByTrafficController | Implemented |
| SecurityPoliciesInterface.Update | Implemented |
| TrafficControllerInterface.CreateOrUpdate | Implemented |
| TrafficControllerInterface.Delete | Implemented |
| TrafficControllerInterface.Get | Implemented |
| TrafficControllerInterface.ListByResourceGroup | Implemented |
| TrafficControllerInterface.ListBySubscription | Implemented |
| TrafficControllerInterface.Update | Implemented |
