How to Deploy .NET Aspire Apps to Azure Container Apps

The recently unveiled .NET Aspire, designed for developing cloud-native applications, perfectly complements Azure Container Apps (ACA). Tailored for managing applications consisting of interdependent microservices, .NET Aspire seamlessly integrates with ACA, which is specifically crafted for microservices and built on cloud-native technology.

Furthermore, the .NET Aspire stack provides a customized deployment experience for ACA through the Azure Developer CLI (AZD). With a single command, you can effortlessly create, provision, and deploy Azure resources for your Aspire solution.

This post delves into the advantages of hosting your applications in ACA compared to an unmanaged cluster. We will also demonstrate the straightforward process of getting started by walking through sample code.

Why Choose Azure Container Apps?

Azure Container Apps (ACA) serves as a platform for running container-first applications and microservices. Powered by Kubernetes, it stands out for its user-friendly approach, making it significantly simpler for the average developer to use and manage. Teams utilizing ACA can concentrate on developing their applications and swiftly moving toward production without the need to delve into the complexities of cluster management from the outset.

Moreover, ACA proves to be an excellent choice for those seeking flexibility and cost efficiency. Operating as a serverless environment, it provides pay-per-use consumption hosting that scales to zero, along with dedicated specialized compute hosting featuring fixed pricing and reliability. With comprehensive support for open-source technologies like Dapr and KEDA, ACA empowers developers to leverage the best practices and tools of the broader microservices ecosystem—all within a unified platform!

These attributes position ACA as an ideal option for developers aiming to construct cloud applications with minimal overhead and complexity. If you're intrigued, keep reading—we'll guide you through some sample code to demonstrate just how swift and uncomplicated it is to deploy a .NET Aspire solution to ACA.

Begin Your Journey with .NET 8, .NET Aspire, and AZD

If you haven't embarked on your .NET Aspire journey alongside .NET 8, navigate to the .NET Aspire documentation. This resource will guide you through all the necessary steps to kickstart your development process, covering the installation of Visual Studio (or Visual Studio Code), .NET 8, the .NET Aspire workload, and Docker Desktop. Alternatively, you have the option to utilize the entire process through the .NET CLI if that's your preference.

Create your .NET Aspire project

If you haven't set up a .NET Aspire project yet, there's no need to worry; the starter project serves as an excellent starting point. In Visual Studio, generate a new .NET Aspire Starter Application, making sure to choose "Use Redis for caching," and you're ready to go.

Create new project

Alternatively, you can create this directly from the .NET CLI using the following command:

dotnet new aspire-starter --use-redis-cache --output AspireSample

Configure the Azure Developer CLI

The Azure Developer CLI (AZD) stands out as a new open-source tool designed to streamline Azure deployments. AZD goes beyond merely facilitating the creation, provisioning, and deployment of Azure resources for your Aspire solution with a single command—it seamlessly integrates with various .NET tools and is accessible from both Visual Studio Code and Visual Studio.

Note. Visual Studio's publishing team is actively investing in several AZD features, with current support for AZD-based publishing. If you haven't explored AZD yet, now is an opportune moment to leverage its repeatable, composable deployment capabilities. As you'll discover later in this article, the synergy between Aspire and AZD creates an automated way to deploy your .NET Cloud Native apps to ACA without the need for any infrastructure code.

AZD builds upon the foundation of the Azure CLI and Bicep. Similar to how ACA simplifies Kubernetes, AZD simplifies deployment by offering intelligent defaults for Aspire solutions. Additionally, if necessary, you can customize the Bicep templates pulled in by AZD.

Refer to this documentation for the installation steps for AZD. 

Initialize Your Project for ACA

Next, initiate an AZD environment for your .NET Aspire application. Establishing multiple apps within the same environment facilitates seamless communication between them.

Run the following command in /AspireSample/AspireSample.AppHost.

azd init

.NET Team R&D

In a matter of seconds, AZD will recognize this as a .NET Aspire application and recommend deploying it to ACA. Confirm your choice and proceed.

.NET Team R&D

AZD currently displays each component of our .NET Aspire solution. Now, you have the option to choose which components you wish to deploy publicly, meaning they will have HTTP ingress accessible to all internet traffic. In this starter application, there is a front end and an API. We intend to make the web frontend public while keeping the API private, and accessible only within the ACA environment.

To configure this, select the web frontend.

Lastly, establish the environment name, such as "dev," "prod," or "test." Provide the environment name and proceed.

AZD will then finalize the initialization of the app and generate a markdown file detailing the actions performed by the CLI behind the scenes.

Deploy Your Project to ACA

AZD streamlines the provisioning and deployment of your solution in a single step. Before proceeding, it's essential to authenticate with Azure AD, enabling the invocation of the Azure Resource Management APIs.

To accomplish this, execute the following command to open a browser for authenticating the command-line session.

azd auth login

Now, we will provision and deploy our application.

azd up

You will then be asked for the subscription and location you would like to deploy to.

Note. In case you encounter an error when attempting to invoke the deploy action after running 'azd up,' ensure that you have an Admin user assigned to the registry. Access the Azure Portal, locate the subscription to which you deployed, and navigate to Container registry > Settings > Access keys. Subsequently, select the "Admin user" checkbox. This action will generate a username and two passwords, granting access to the ACR resource. When prompted for your username and password, enter the values displayed in the Azure Portal. For additional details, refer to the "Enable admin user" documentation.

AZD will generate links to both the web frontend and API service applications. The last line of the terminal output provides a link to the Azure Portal page displaying all the deployed resources.

Packing services

The Azure Portal provides a diverse range of resources to assist you in scaling and comprehending your application. Beyond tools for managing costs, performance, and security, you can configure your application to scale dynamically based on incoming demand.

Essentials

That concludes the process! If you wish to delve deeper into the inner workings of what AZD is accomplishing to provision and deploy your app, you can refer to this documentation for more insights.

Conclusion

This article has guided you through the seamless integration of .NET Aspire with Azure Container Apps (ACA) using the Azure Developer CLI (AZD). By leveraging the user-friendly features of ACA and the deployment capabilities of AZD, you can effortlessly create, provision, and deploy your .NET Aspire applications. The article demonstrated the initiation of a project, the configuration of AZD environments, and the deployment process. Furthermore, it highlighted the flexibility and advantages offered by ACA, allowing you to efficiently manage resources and scale your applications based on demand through the Azure Portal. For a more in-depth understanding of the deployment process, you can explore the provided documentation. Now equipped with these insights, you can embark on your journey to deploy .NET Cloud Native apps to ACA with confidence and ease.

Reference


Recommended Free Ebook
Similar Articles
Ezmata Technologies Pvt Ltd
You manage your core business, while we manage your Infrastructure through ITaaS.