aspire: [YARP + Aspire] Service discovery does not work after deployment in Azure
I use YARP in my microservice architecture and have experienced issues deploying to Azure.
I use YARP with these two extension methods and they work great for local development:
AddServiceDiscoveryDestinationResolver
AddHttpForwarderWithServiceDiscovery
After deployment to Azure, YARP could no longer find the other container apps (404), regardless of whether they were configured internally or externally in the Ingress settings.
My workaround now looks like this: I completely omit the methods mentioned for deployment and leave the service discovery to the Azure Container App Environment.
if (builder.Environment.IsDevelopment())
{
// Service discovery is not needed in Azure Container App Environment
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddAccessToken()
.AddResilience()
.AddServiceDiscoveryDestinationResolver();
builder.Services.AddHttpForwarderWithServiceDiscovery();
}
else
{
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
.AddAccessToken()
.AddResilience();
}
This now works, but I’m not sure if this is the intended solution.
Maybe someone also has an explanation why YARP does not work with the actually correct urls in the context of Azure Container Apps.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 16 (10 by maintainers)
Update: I found the issue: the Host header set is wrong, it is currently set to the “short uri” (like in the repo
apiserviceinstead of the FQDN of the discovered endpoint.I am stil trying to understand why this short uri was set tin the host header in the first place.
@ReubenBond can we look into this for 9?
Tried it, same issue.
Just faced this exact same issue. The fix from @4eversoft works great and makes sense since ACA is already designed to discover services just by their name.
If it helps, I collected these logs of a failed request before disabling service discovery in Prod environment:
Added the workaround:
Now it just works: