Sizing a Microsoft Foundry Agent Service Subnet
In this article
Properly sizing the subnet for a Microsoft Foundry agent service is critical for ensuring your agents can scale without exhausting IP addresses or running into performance bottlenecks. This guide walks you through the key factors—expected agent count, scaling behavior, and networking constraints—and gives you a practical method to calculate the right CIDR block size.
What You'll Need
- An Azure subscription with access to Microsoft Foundry (formerly Azure AI Foundry).
- Knowledge of your expected maximum number of concurrent agent instances (or an estimate).
- Understanding of your VNet's existing address space to avoid overlap.
- Familiarity with CIDR notation and subnet basics (e.g., /24, /26).
Step-by-Step
- Estimate the maximum number of agent instances you'll run concurrently. This is your peak load, not the typical daily average. Consider auto-scaling rules, batch jobs, and seasonal spikes. For example, if you normally run 10 agents but scale to 50 during heavy workloads, use 50 as your baseline.
- Add a buffer for future growth. Multiply your peak instance count by at least 2 to account for unexpected spikes or gradual scaling over the next 12–18 months. This buffer also covers temporary instances created during rolling updates or failover scenarios.
- Account for Azure's reserved IP addresses. Every Azure subnet reserves 5 IP addresses (for Azure infrastructure: network, gateway, Azure DNS, and two for internal use). So your usable IP count is the subnet's total minus 5.
- Calculate the required usable IP count. Take your buffered instance count and add a few extra IPs for potential network interfaces (NICs) that might be attached to other resources in the same subnet (e.g., a load balancer or a jump box). A safe rule is to add 10% more IPs.
- Choose the smallest CIDR block that fits your usable IP requirement. Use the formula:
Total IPs = 2^(32 - prefix). For example, a /28 gives 16 IPs (11 usable), /27 gives 32 (27 usable), /26 gives 64 (59 usable), and /25 gives 128 (123 usable). Pick the smallest block that gives you at least your required usable IPs. - Verify the subnet doesn't overlap with other subnets in your VNet. If it does, adjust the CIDR range or choose a different block within the VNet's address space.
- Create the subnet in the Azure portal or via CLI/ARM template. When configuring the agent service, specify the subnet ID. Ensure the subnet is delegated to the appropriate service (e.g., Microsoft.App/environments for container apps hosting agents) if required.
Common Mistakes
- Using a /24 subnet for a small agent pool. While a /24 (256 IPs) is common, it's often overkill for fewer than 20 agents. This wastes address space, especially if you have many subnets in a limited VNet.
- Forgetting the 5 reserved IPs. People often calculate based on total IPs, then wonder why they run out of addresses with fewer agents than expected.
- Ignoring auto-scaling maximums. If your agent service scales to a maximum of 100 instances, but you sized for 50, you'll hit IP exhaustion during peak loads.
- Overlapping subnets. Reusing an IP range that's already in use elsewhere in the VNet causes routing conflicts and connection failures.
Tips
- Start small, but plan for growth. It's easier to expand a subnet later if you have contiguous free address space, but you can't shrink it easily. Choose a size that accommodates at least 2x your current peak.
- Use a dedicated subnet for agent services. This isolates network traffic and makes it easier to apply network security groups (NSGs) and route tables specifically for agent workloads.
- Consider using a /26 as a default for moderate workloads. It provides 59 usable IPs, which is enough for up to ~50 agents with a small buffer. For larger deployments, /24 is a safe choice.
- Document your subnet allocation. Keep a simple table of which subnet is used for what, to avoid future overlaps.
Troubleshooting
- Agents fail to start with an IP allocation error. This often means the subnet is out of available IPs. Check the subnet's usage in the Azure portal. If it's near capacity, you'll need to either reduce the agent count or create a larger subnet and redeploy the agent service.
- Agents can't communicate with other resources. Verify that the subnet's route table and NSGs allow the necessary traffic. Also, ensure the subnet is in the same VNet as the target resources, or that VNet peering is correctly configured.
- Subnet creation fails due to overlap. Try a different CIDR range within your VNet's address space. Use the VNet's address space in the portal to see available ranges.
- Agent service deployment fails with a delegation error. Some services require the subnet to be delegated. In the subnet settings, add a delegation for the appropriate service (e.g., Microsoft.App/environments).
Frequently Asked Questions
What is the smallest subnet I can use for a single agent?
Azure requires a minimum of /29 (8 IPs, 3 usable). That's enough for one agent, but you'll have no room for scaling. A /28 (11 usable) is safer for a single agent with a small buffer.
Can I change the subnet size after creating the agent service?
You cannot change the subnet size in place. You must create a new subnet with the desired size and update the agent service to use it. This often requires a redeployment.
Does the agent service use one IP per instance?
Yes, each agent instance gets a private IP address from the subnet. Some services may also use IPs for internal load balancers or other infrastructure, so always add a buffer.
What's the difference between a /24 and a /28 subnet?
A /24 subnet has 256 total IPs (251 usable), while a /28 has 16 total IPs (11 usable). A /24 can support up to ~250 agents, whereas a /28 supports only ~6-10 agents comfortably.
Is it better to use a larger subnet than needed?
Not necessarily. Larger subnets can be wasteful if you have limited address space. However, if your VNet has plenty of free IPs, a larger subnet (like /24) gives you flexibility to scale without redeployment.
How do I know how many IPs are currently used in my subnet?
In the Azure portal, go to your subnet's overview page. It shows the number of used and available IPs. You can also use Azure CLI: az network vnet subnet show -g <resource-group> --vnet-name <vnet> -n <subnet> --query 'addressPrefix' and check the IP usage via the portal.