Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Deploy an Aspire project to Azure Container Apps

Feedback

In this article

Aspire projects are designed to run in containerized environments. Azure Container Apps is a fully managed environment that enables you to run microservices and containerized applications on a serverless platform. This article will walk you through creating a new Aspire solution and deploying it to Microsoft Azure Container Apps using the Azure Developer CLI (azd). You'll learn how to complete the following tasks:

  • Provision an Azure resource group and Container Registry
  • Publish the Aspire projects as container images in Azure Container Registry
  • Provision a Redis container in Azure
  • Deploy the apps to an Azure Container Apps environment
  • View application console logs to troubleshoot application issues

Prerequisites

To work with Aspire, you need the following installed locally:

For more information, seeAspire setup and tooling, andAspire SDK.

As an alternative to this tutorial and for a more in-depth guide, seeDeploy an Aspire project to Azure Container Apps usingazd (in-depth guide).

Deploy Aspire projects withazd

With Aspire and Azure Container Apps (ACA), you have a great hosting scenario for building out your cloud-native apps with .NET. We built some great new features into the Azure Developer CLI (azd) specific for making Aspire development and deployment to Azure a friction-free experience. For production scenarios that require granular control over infrastructure, seeCustomize Aspire Azure deployments. But for new projects, you won't find an easier path to success for getting a new microservice topology deployed into the cloud.

Create an Aspire project

As a starting point, this article assumes that you've created an Aspire project from theAspire Starter Application template. For more information, seeQuickstart: Build your first Aspire project.

Resource naming

When you create new Azure resources, it's important to follow the naming requirements. For Azure Container Apps, the name must be 2-32 characters long and consist of lowercase letters, numbers, and hyphens. The name must start with a letter and end with an alphanumeric character.

For more information, seeNaming rules and restrictions for Azure resources.

Install the Azure Developer CLI

The process for installingazd varies based on your operating system, but it is widely available viawinget,brew,apt, or directly viacurl. To installazd, seeInstall Azure Developer CLI.

Initialize the template

  1. Open a new terminal window andcd into the directory of your Aspire solution.

  2. Execute theazd init command to initialize your project withazd, which will inspect the local directory structure and determine the type of app.

    azd init

    For more information on theazd init command, seeazd init.

  3. SelectUse code in the current directory whenazd prompts you with three app initialization options.

    ? How do you want to initialize your app?  [Use arrows to move, type to filter]> Use code in the current directory  Select a template  Create a minimal project
  4. After scanning the directory,azd prompts you to confirm that it found the correct AspireAppHost project. Select theConfirm and continue initializing my app option.

    Detected services:  .NET (Aspire)  Detected in: D:\source\repos\AspireSample\AspireSample.AppHost\AspireSample.AppHost.csprojazd will generate the files necessary to host your app on Azure using Azure Container Apps.? Select an option  [Use arrows to move, type to filter]> Confirm and continue initializing my app  Cancel and exit
  5. Enter an environment name, which is used to name provisioned resources in Azure and managing different environments such asdev andprod.

    Generating files to run your app on Azure:  (✓) Done: Generating ./azure.yaml  (✓) Done: Generating ./next-steps.mdSUCCESS: Your app is ready for the cloud!You can provision and deploy your app to Azure by running the azd up command in this directory. For more information on configuring your app, see ./next-steps.md

azd generates a number of files and places them into the working directory. These files are:

  • azure.yaml: Describes the services of the app, such as Aspire AppHost project, and maps them to Azure resources.
  • .azure/config.json: Configuration file that informsazd what the current active environment is.
  • .azure/aspireazddev/.env: Contains environment specific overrides.

Deploy the template

  1. Once anazd template is initialized, the provisioning and deployment process can be executed as a single command from theAppHost project directory usingazd up:

    azd up
  2. Select the subscription you'd like to deploy to from the list of available options:

    Select an Azure Subscription to use:  [Use arrows to move, type to filter]  1. SampleSubscription01 (xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx)  2. SampleSubscription02 (xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx)
  3. Select the desired Azure location to use from the list of available options:

    Select an Azure location to use:  [Use arrows to move, type to filter]  42. (US) Central US (centralus)  43. (US) East US (eastus)> 44. (US) East US 2 (eastus2)  46. (US) North Central US (northcentralus)  47. (US) South Central US (southcentralus)

After you make your selections,azd executes the provisioning and deployment process.

By default, a service can only be reached from inside the Azure Container Apps environment it is running in. Selecting a service here will also allow it to be reached from the Internet.? Select which services to expose to the Internet webfrontend? Select an Azure Subscription to use:  1. <YOUR SUBSCRIPTION>? Select an Azure location to use: 1. <YOUR LOCATION>Packaging services (azd package)Provisioning Azure resources (azd provision)Provisioning Azure resources can take some time.Subscription: <YOUR SUBSCRIPTION>Location: <YOUR LOCATION>  You can view detailed progress in the Azure Portal:  <LINK TO DEPLOYMENT>  (✓) Done: Resource group: <YOUR RESOURCE GROUP>  (✓) Done: Container Registry: <ID>  (✓) Done: Log Analytics workspace: <ID>  (✓) Done: Container Apps Environment: <ID>SUCCESS: Your application was provisioned in Azure in 1 minute 13 seconds.You can view the resources created under the resource group <YOUR RESOURCE GROUP> in Azure Portal:<LINK TO RESOURCE GROUP OVERVIEW>Deploying services (azd deploy)  (✓) Done: Deploying service apiservice  - Endpoint: <YOUR UNIQUE apiservice APP>.azurecontainerapps.io/  (✓) Done: Deploying service webfrontend  - Endpoint: <YOUR UNIQUE webfrontend APP>.azurecontainerapps.io/Aspire Dashboard: <LINK TO DEPLOYED Aspire DASHBOARD>SUCCESS: Your up workflow to provision and deploy to Azure completed in 3 minutes 50 seconds.

Theazd up command acts as wrapper for the following individualazd commands to provision and deploy your resources in a single step:

  1. azd package: The app projects and their dependencies are packaged into containers.
  2. azd provision: The Azure resources the app will need are provisioned.
  3. azd deploy: The projects are pushed as containers into an Azure Container Registry instance, and then used to create new revisions of Azure Container Apps in which the code will be hosted.

When theazd up stages complete, your app will be available on Azure, and you can open the Azure portal to explore the resources.azd also outputs URLs to access the deployed apps directly.

Test the deployed app

Now that the app has been provisioned and deployed, you can browse to the Azure portal. In the resource group where you deployed the app, you'll see the three container apps and other resources.

A screenshot of the Aspire project's resource group in the Azure portal.

Click on theweb Container App to open it up in the portal.

A screenshot of the Aspire project's front end in the Azure portal.

Click theApplication URL link to open the front end in the browser.

A screenshot of the Aspire project's front end in the browser.

When you click the "Weather" node in the navigation bar, the front endweb container app makes a call to theapiservice container app to get data. The front end's output will be cached using theredis container app and theAspire Redis Output Caching integration. As you refresh the front end a few times, you'll notice that the weather data is cached. It will update after a few seconds.

Deploy the Aspire Dashboard

You can deploy the Aspire dashboard as part of your hosted app. This feature is now fully supported. When deploying, the azd output logs print an additional URL to the deployed dashboard.

You can runazd monitor to automatically launch the dashboard.

azd monitor

Clean up resources

Run the following Azure CLI command to delete the resource group when you no longer need the Azure resources you created. Deleting the resource group also deletes the resources contained inside of it.

az group delete --name <your-resource-group-name>

For more information, seeClean up resources in Azure.

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?