AGC, HTTPRoute, and RoutePolicy Explained
Table of Contents
Introduction #
When you work with Azure Application Gateway for Containers (AGC) in AKS, it helps to separate traffic routing from route behavior.
That is where HTTPRoute and RoutePolicy come in.
This post brings the full picture together so it is easier to understand:
- How AGC,
HTTPRoute, andRoutePolicyfit together - What
HTTPRouteis responsible for - What
RoutePolicyis responsible for - How URL rewrites and backend weights behave
- Why errors such as
InvalidGrouphappen
Overall Architecture #
You can picture the request flow like this:
Client -> AGC (Gateway) -> HTTPRoute -> Service -> Pod
And when needed:
RoutePolicy -> attaches behavior to the HTTPRoute
That gives you a clean mental model:
- AGC is the traffic entry point
HTTPRoutedefines routing rulesRoutePolicyadds advanced behavior
What HTTPRoute Does #
The core job of HTTPRoute is to decide where traffic goes.
This is where you define:
- Path matching
- Host matching
- URL rewrites
- Backend services
Example:
|
|
Path Matching #
With this route match:
|
|
AGC matches requests such as:
/sample-api/sample-api//sample-api/health
URL Rewrite and ReplacePrefixMatch #
If you use:
|
|
you must have exactly one PathPrefix match in the route.
If not, AGC rejects the configuration with an error like:
Invalid: When using URLRewrite with replacePrefixMatch
What the rewrite does:
- Incoming path:
/sample-api/health - Path sent to backend:
/health
This is useful when the external route includes a prefix, but the backend application expects requests without that prefix.
backendRefs and Weight #
backendRefs defines which service receives traffic.
Example:
|
|
The weight value is relative, not absolute.
Examples:
svc-1 weight: 1andsvc-2 weight: 1means about50% / 50%svc-1 weight: 3andsvc-2 weight: 1means about75% / 25%- If there is only one backend,
weight: 1means it receives all traffic
What RoutePolicy Does #
RoutePolicy does not handle routing decisions. Its job is to add behavior to a route.
This is where you configure features such as:
- Session affinity
- TLS-related behavior
- Other AGC-supported route controls
One common example is sticky sessions:
|
|
This means:
- AGC manages the session cookie
- The same client is sent back to the same backend pod during that cookie lifetime
- The session is less likely to break because of pod switching
This is especially useful for:
- Stateful applications
- Session-based systems
- Any app that should not bounce between pods mid-session
How They Work Together #
The combined flow looks like this:
- A client sends a request to AGC.
- AGC receives the traffic at the gateway frontend.
HTTPRoutechecks the path, host, and filters.RoutePolicyapplies extra behavior such as session affinity.- Traffic is sent to the selected service and pod.
A simple way to remember it:
HTTPRoute= traffic rulesRoutePolicy= behavior rules- AGC = execution engine
Understanding the InvalidGroup Error #
One of the most common configuration mistakes with RoutePolicy is a missing API group in targetRef.
You might see conditions like:
Status: FalseReason: InvalidGroup
The root cause is usually this:
|
|
It should be:
|
|
Kubernetes identifies resources using API group and kind, so HTTPRoute alone is not enough for the controller to resolve the reference.
Reading Status Conditions #
Two important conditions to watch are:
ResolvedRefsAccepted
If you see:
ResolvedRefs: FalseAccepted: False
that usually means:
ResolvedRefscould not resolve the referenced objectAcceptedmeans the controller rejected the configuration
In other words, False here means the config is not working, not just that there is a warning.
Common Mistakes #
- Missing
groupintargetRef - Using
Exactinstead ofPathPrefixwhenReplacePrefixMatchis involved - Defining multiple matches with
replacePrefixMatch - Treating
weightlike a fixed percentage instead of a relative value
Final Mental Model #
If you want to keep the whole setup simple in your head, use this:
HTTPRoutedefines where traffic goesRoutePolicydefines how traffic should behave- AGC applies both and forwards traffic to the backend
That separation is what makes AGC with Gateway API easier to reason about than older, annotation-heavy ingress setups.