Deploy apps to Azure Container Apps easily with .NET Aspire
Published Jan 17 2024 02:08 PM 6,481 Views

The recently announced .NET 8's Aspire stack for building cloud-native apps is a great match for Azure Container Apps. .NET Aspire was designed to easily manage applications comprised of a series of interdependent microservices. Container Apps is also tailored for microservices and built on cloud native tech which means .NET Aspire integrates to it seamlessly– right out of the box! 


Furthermore, the .NET Aspire stack offers a tailored deployment experience for ACA through the Azure Developer CLI (AZD), which lets you create, provision, and deploy the Azure resources for your Aspire solution with a single command.


In this blog post, we discuss the benefits of hosting your apps in ACA versus an unmanaged cluster. We will also show you just how easy it is to get started by walking through sample code.




Why Azure Container Apps?


Azure Container Apps (ACA) is a platform for running container-first applications and microservices. It is powered by Kubernetes but is far simpler to use and manage for the average developer. Teams using ACA can focus on building their applications and getting to production instead of having to learn the intricacies of cluster management just to get started.


It is also a great option if you want flexibility and minimize costs. As a serverless environment, ACA offers both pay-per-use consumption hosting that scales to 0 and dedicated specialized compute hosting with fixed pricing and reliability. With full support for open sources technologies like Dapr and KEDA, ACA allows developers to draw from best practices and tools of the broader microservices ecosystem - all from a single platform!


These features make ACA a great choice for developers who want to build applications for the cloud with minimal overhead and complexity. If you’re curious, read on - we will go through some sample code so you can see for yourself just how fast and easy it is to deploy a .NET Aspire solution to ACA.


Get started with .NET 8 and .NET Aspire


Haven’t had a chance to experience the .NET Aspire stack? To add the workload to your .NET environment, you will need the following:


There are two ways to set up the .NET Aspire workload, depending on your choice of IDE.


Use the Visual Studio installer


This is the method we will use for our examples to take advantage of additional benefits like built-in templates and easier initial setup configuration.


  • Open the Visual Studio Installer.
  • Select Modify next to Visual Studio 2022 Preview.
  • Select the ASP.NET and web development workload.
  • On the Installation details panel, select .NET Aspire SDK (Preview).
  • Select Modify to install the .NET Aspire component.



Use the dotnet workload install aspire command


If you are not using Visual Studio, you can install the .NET Aspire workload from the .NET CLI. Use the command below:


dotnet workload install aspire


Create a new .NET Aspire solution


To create a new .NET Aspire solution, reference this documentation.


Set up the Azure Developer CLI


The Azure Developer CLI (AZD) is a new open-source tool that accelerates deployment to Azure. Not only does AZD let you create, provision, and deploy the Azure resources for your Aspire solution with a single command, it integrates broadly with .NET tools and can be accessed from both Visual Studio Code and Visual Studio.


AZD builds upon the foundation of the Azure CLI and Bicep. In the same way that ACA simplifies Kubernetes, AZD simplifies deployment by providing smart defaults for Aspire solutions. You can further customize the bicep templates pulled in by AZD if required.


You can install AZD using this documentation.


Initialize your project for ACA


Now, let’s create an AZD environment for our .NET Aspire app. Having multiple apps in the same environment allows them to communicate with each other.


Run the following command in the root of your project.


azd init




Within a few seconds, AZD will detect that this is a .NET Aspire app and suggest a deployment to ACA. Confirm and continue.




AZD now shows each of the components of our .NET Aspire solution. You can now choose which ones you want deployed publicly, meaning they will have HTTP ingress open to all internet traffic. In this starter application, there is a frontend and an API. We want the web frontend to be public while the API should be private only to the ACA environment.


To get that set-up, select webfrontend.


Finally, we will set up the environment name – for example, dev and prod and test. Provide the environment name and continue.


AZD then completes the initialization of the app and generates a markdown file that provides details about what the CLI did under the hood.


Deploy your project to ACA


AZD lets you provision and deploy your solution in a single step. First, however, we need to authenticate with Azure AD so we can call the Azure resource management APIs.


To do so, run the following command to launch a browser to authenticate 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: If you get the error above after running azd up, make sure you have an Admin user on the registry.  Open the Azure Portal and navigate to the subscription you deployed to.





Enter the Container registry / Settings / Access keys, and then select the Admin user checkbox. This will generate a username and two passwords for you to access the ACR resource.





You will be prompted for your username and password. Enter the values shown in Azure Portal. For more information, see Enable admin user.




AZD will generate links to the web frontend and API service applications. The final line of the terminal output contains a link to the Azure Portal page that shows all the deployed resources.




The Azure Portal offers a large variety of resources to help you scale and understand your application. Not only are there tools to manage costs, performance, and security, you can set your application to scale depending on incoming demand.


That’s it! To learn more about what AZD is doing under the hood to provision and deploy your app, you can read through this documentation.


Now, we will take a quick look at what the same process looks like if we were deploying to an unmanaged Kubernetes cluster.


Initialize your project for an unmanaged cluster


You cannot use AZD to set up your project for deployment to your own cluster. Instead, you will need to download a community tool called Aspir8. You can find more information on the project by reading the .NET team’s blog post on .NET Aspire Preview 2 and looking through its documentation.


At a high level, you initialize your project through a CLI command with options based on your needs. The tool does not offer much of the AZD functionality we discussed earlier, such as deploying some components of your solution publicly and others privately. In addition, you will need to manually pass in information that is automated in AZD due to its integration with other Azure resources.


Deploy your project to your own cluster


To deploy your project to your own cluster, you will need to first build the projects and containers. That generates a manifest file, which is a YAML or JSON file that manages version configurations alongside your code. Additional manifests will be generated depending on the complexity of your cluster.


Then, you will have to manually apply those manifests to a cluster for deployment. There are a variety of other tasks automated by AZD that you must handle for your own cluster, such as secret management. Instead of having security, observability, and scalability integrated into a single platform, functionality must be pieced together from across the microservices ecosystem by the developer team.


Next Steps


Congratulations, you can now deploy Aspire apps to ACA. You should now have a better understanding of the benefits of deploying your Aspire app to ACA as opposed to unmanaged infra. Thank you for reading!


Want to learn more? You can...


Version history
Last update:
‎Apr 29 2024 03:18 PM
Updated by: