Menu

Mimic load balancing Kubernetes using DotNet Aspire

27th April 2025 - c#, developer, Development, dotnetcore, Uncategorised
Mimic load balancing Kubernetes using DotNet Aspire

Aspire is Microsofts development, erm, platform? Software Development Kit? Stack? API? Template System? Well, it’s a lot more than all of those, it helps developers realise multi-service/server cloud systems from a standard development environment. It utilises Docker Containers to allow quite complex development scenarios to be created in one solution. It allows development-time orchestration of cloud systems, and has plugins and extensions to simulate/emulate everything from nosql databases to cloud storage to message buses.

One of the more impressive tricks in .Net Aspires repertoire is to simulate a load balanced service. This is when a single service is spun up multiple times, and subsequent requests are handled by other services. Generally, this is done by your cloud platform depending on resource availability or number of requests required to be handled. In .Net aspire, however, we can have a project which simulates this behaviour by using the .withReplicas(n) extension method.

var coolBuild=DistributedApplication.CreateBuilder(args);
var multiService=builder.AddProject<Projects.CryptoLLMResponder>("dogepredictor")
    .WithHttpEndpoint(port: 5070)
    .WithReplicas(10);

When a funded crypto bro who has subscribed to your service calls your endpoint at port:5070, they will get one of the 10 replicas created.

Anyone who has done any cloud development will appreciate this is a far cleaner and powerful way of building up these services than writing a series of kubernetes pipelines and deploying to a local cluster.

Plus, it all gets torn down at the end, which is fantastic.

But! I hear you cry, how on this green Earth do I deploy this wizardy to production?!?

Well, that’s where we fall over a little, but only because of the complex and arcane briar patch which is cloud development.. However, if you’re already using Azure, you are golden!

Azure Container Apps is a primary deployment platform for Aspire. More platforms will come, but for the time being, if you’re developing .Net then the chances are more than not you are on the Azure ecosystem. There are Kubernetes extensions available via the Aspir8 project which take your .Net Aspire App Host manifest and outputs a tool which runs through the steps automatically.

The Azure CLI (azd) can handle the creation up and teardown down and deployment azd deploy of your Aspire AppHost. Start with azd init and follow the instructions.

Bicep templates (container definitions) can also be created from the .NET Aspire project.

Once you’re done, or you want to delete your deployment, delete the resource group, then all resources and containers will be deleted too.

Its great to see this sort of technology going front and center for .NET, albeit it seems at the cost of MAUI development. I hope that we see more intuitive and powerful SAAS development systems coming from microsoft.

More Information:

https://learn.microsoft.com/en-us/dotnet/aspire/deployment/azure/aca-deployment-azd-in-depth?tabs=windows

https://learn.microsoft.com/en-us/dotnet/aspire/deployment/azure/aca-deployment

https://learn.microsoft.com/en-us/dotnet/aspire

https://prom3theu5.github.io/aspirational-manifests/getting-started.html

Leave a Reply