|
| 1 | +--- |
| 2 | +type: docs |
| 3 | +title: "How-To: Deploy an Application to Azure Container Instances" |
| 4 | +linkTitle: "Deploy to ACI" |
| 5 | +description: "Learn how to configure and deploy an application to Azure Container Instances" |
| 6 | +weight: 500 |
| 7 | +slug: 'azure-container-instances' |
| 8 | +categories: "How-To" |
| 9 | +tags: ["Azure","containers"] |
| 10 | +--- |
| 11 | + |
| 12 | +This how-to guide will provide an overview of how to: |
| 13 | + |
| 14 | +- Configure and deploy a Radius [Environment]({{< ref "/guides/deploy-apps/environments/overview" >}}) that uses [Azure Container Instances (ACI)](https://learn.microsoft.com/en-us/azure/container-instances/) as the compute provider. |
| 15 | +- Define and deploy the demo application to the ACI Radius Environment, which provisions the necessary resources to run the application in ACI. |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +- [rad CLI]({{< ref "installation#step-1-install-the-rad-cli" >}}) |
| 20 | +The [Bicep extension]({{< ref "installation#step-2-install-the-vs-code-extension" >}}) for VS Code is recommended for Bicep language support |
| 21 | +- Radius [installed]({{< ref "/guides/operations/kubernetes/kubernetes-install" >}}) on a [supported Kubernetes cluster]({{< ref "/guides/operations/kubernetes/overview#supported-kubernetes-clusters" >}}) |
| 22 | +- An Azure provider configured and registered with your Radius control plane, either through [Service Principal](https://docs.radapp.io/guides/operations/providers/azure-provider/howto-azure-provider-sp/) or [Workload Identity](https://docs.radapp.io/guides/operations/providers/azure-provider/howto-azure-provider-wi/) that have been assigned to the `Contributor` and `Azure Container Instances Contributor` roles on the subscription or resource group where the ACI containers will be deployed |
| 23 | +- A [managed identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/) is [required]({{< ref "/reference/resource-schema/core-schema/environment-schema#identity" >}}) for ACI deployments, if you choose to utilize a [user-assigned managed identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-manage-user-assigned-managed-identities?pivots=identity-mi-methods-azp) then you need to ensure it is assigned to the `Contributor` and `Azure Container Instances Contributor` roles on the subscription and resource group where the ACI containers will be deployed |
| 24 | + |
| 25 | +## Step 1: Create a Radius Resource Group and Workspace |
| 26 | + |
| 27 | +Since the Radius control plane is hosted on your Kubernetes cluster, you'll need to create a new Radius Resource Group and Workspace so that you can target your application deployments to an ACI Environment. These will then be associated with the ACI Environment that you will configure and create in subsequent steps. |
| 28 | + |
| 29 | +1. Create a new Radius Workspace called `aci-workspace`: |
| 30 | + ```bash |
| 31 | + rad workspace create kubernetes aci-workspace |
| 32 | + ``` |
| 33 | + |
| 34 | +1. Then, create a new Radius Resource Group called `aciGroup` and switch to it: |
| 35 | + ```bash |
| 36 | + rad group create aciGroup |
| 37 | + rad group switch aciGroup |
| 38 | + ``` |
| 39 | + |
| 40 | +1. Finally, create a new ACI Environment within the `aci-workspace` workspace you just created and switch to it: |
| 41 | + ```bash |
| 42 | + rad env create aci-demo -w aci-workspace |
| 43 | + rad env switch aci-demo |
| 44 | + ``` |
| 45 | + |
| 46 | +## Step 2: Define the Environment with ACI compute |
| 47 | + |
| 48 | +Create a new file named `env.bicep` and add the following Environment definition. This Environment uses the `aci` compute provider and a user-assigned managed identity to provision the necessary resources for ACI and also registers a default Recipe for provisioning an Azure Redis Cache. |
| 49 | + |
| 50 | +{{< rad file="snippets/env.bicep" embed=true >}} |
| 51 | + |
| 52 | +> Note: be sure to replace the `resourceGroup` and `scope` values with your resource group ID and the `managedIdentity` value with your managed identity resource ID. |
| 53 | +
|
| 54 | +## Step 3: Deploy the Environment |
| 55 | + |
| 56 | +1. Run the following command to deploy the Environment and associate it with the `aci-workspace` you created in the previous step: |
| 57 | + ```bash |
| 58 | + rad deploy ./env.bicep --workspace aci-workspace |
| 59 | + ``` |
| 60 | + |
| 61 | + You should see the following terminal output: |
| 62 | + |
| 63 | + ``` |
| 64 | + Deployment In Progress... |
| 65 | +
|
| 66 | + Deployment Complete |
| 67 | +
|
| 68 | + Resources: |
| 69 | + aci-demo Applications.Core/environments |
| 70 | + ``` |
| 71 | + |
| 72 | +<br> |
| 73 | + |
| 74 | +Navigate to your resource group in the [Azure portal](https://portal.azure.com/) and you should see the relevant Azure resources that were provisioned by Radius for your ACI Radius Environment, including the virtual network, internal load balancer, and network security group: |
| 75 | + |
| 76 | +{{< image src="azure-portal-env.png" alt="Screenshot of the Azure portal showing the resource group with the virtual network, internal load balancer, and network security group resources created by Radius" width=700px >}} |
| 77 | + |
| 78 | +## Step 4: Define the Application and its resources |
| 79 | + |
| 80 | +Create a file named `app.bicep` and add the application definition, along with Redis cache, gateway, and container resources to the file: |
| 81 | + |
| 82 | +{{< rad file="snippets/app.bicep" embed=true >}} |
| 83 | + |
| 84 | +> Notice that for ACI containers, you define a Gateway resource that provides L7 traffic for the container. Radius will provision an Azure Application Gateway on your behalf and configure the container to use the Gateway as its ingress. The Gateway will be provisioned with a public IP address and a DNS name that you can use to access the application. |
| 85 | +
|
| 86 | +## Step 5: Deploy the Application |
| 87 | + |
| 88 | +Run the following command to deploy the application: |
| 89 | + |
| 90 | +```bash |
| 91 | +rad deploy ./app.bicep --workspace aci-workspace |
| 92 | +``` |
| 93 | + |
| 94 | +> Note that you are deploying the application specifically targeting the `aci-workspace` you had created in a previous step, which ensures that your application gets deployed to the ACI Environment. The same application can also be targeted to deploy into a workspace associated with a Kubernetes Radius Environment instead. |
| 95 | +
|
| 96 | +Once the deployment succeeds, you should see the following terminal output: |
| 97 | + |
| 98 | +``` |
| 99 | +Deployment In Progress... |
| 100 | +
|
| 101 | +Completed database Applications.Datastores/redisCaches |
| 102 | +Completed gateway Applications.Core/gateways |
| 103 | +Completed demo-app Applications.Core/applications |
| 104 | +.. frontend Applications.Core/containers |
| 105 | +
|
| 106 | +Deployment Complete |
| 107 | +
|
| 108 | +Resources: |
| 109 | + demo-app Applications.Core/applications |
| 110 | + frontend Applications.Core/containers |
| 111 | + gateway Applications.Core/gateways |
| 112 | + database Applications.Datastores/redisCaches |
| 113 | +
|
| 114 | +Public Endpoints: |
| 115 | + gateway Applications.Core/gateways http://gateway.demo-app.4.149.194.115.nip.io |
| 116 | +``` |
| 117 | + |
| 118 | +## Step 6: View the deployed resources |
| 119 | + |
| 120 | +Now you can check the Radius application graph in your terminal to view resources that were provisioned for your application: |
| 121 | + |
| 122 | +```bash |
| 123 | +rad app graph -a demo-app |
| 124 | +``` |
| 125 | + |
| 126 | +You should see the following output: |
| 127 | + |
| 128 | +``` |
| 129 | +Displaying application: demo-app |
| 130 | +
|
| 131 | +Name: frontend (Applications.Core/containers) |
| 132 | +Connections: |
| 133 | + gateway (Applications.Core/gateways) -> frontend |
| 134 | + frontend -> database (Applications.Datastores/redisCaches) |
| 135 | +Resources: |
| 136 | + frontend (Microsoft.ContainerInstance/containerGroupProfiles) |
| 137 | + frontend (Microsoft.ContainerInstance/nGroups) |
| 138 | + frontend (Microsoft.Network/loadBalancers/applications) |
| 139 | + frontend (Microsoft.Network/virtualNetworks/subnets) |
| 140 | +
|
| 141 | +Name: gateway (Applications.Core/gateways) |
| 142 | +Connections: |
| 143 | + gateway -> frontend (Applications.Core/containers) |
| 144 | +Resources: |
| 145 | + gateway (Microsoft.Network/applicationGateways) |
| 146 | + gateway-nsg (Microsoft.Network/networkSecurityGroups) |
| 147 | + gateway (Microsoft.Network/publicIPAddresses) |
| 148 | + gateway (Microsoft.Network/virtualNetworks/subnets) |
| 149 | +
|
| 150 | +Name: database (Applications.Datastores/redisCaches) |
| 151 | +Connections: |
| 152 | + frontend (Applications.Core/containers) -> database |
| 153 | +Resources: |
| 154 | + cache-vxkt2iou25nht (Microsoft.Cache/redis) |
| 155 | +``` |
| 156 | + |
| 157 | +Navigate to your resource group in the [Azure portal](https://portal.azure.com/) and you should see the relevant Azure resources that were provisioned by Radius for your application, including the container instance, container group profile, Ngroup, load balancer, virtual network, and network security groups that are required for the application to run on ACI: |
| 158 | + |
| 159 | +{{< image src="azure-portal-app.png" alt="Screenshot of the Azure portal showing the resource group with all the ACI resources" width=700px >}} |
| 160 | +<br> |
| 161 | + |
| 162 | +## Step 7: Browse the Application |
| 163 | + |
| 164 | +In your Azure portal, click on the Gateway public IP address resource and you should see the public IP address of the Gateway resource. This is the public DNS name that you can use to access your application. Copy the public DNS name. |
| 165 | + |
| 166 | +{{< image src="azure-portal-gateway.png" alt="Screenshot of the Azure portal showing the public IP address of the Gateway resource" width=700px >}}<br> |
| 167 | + |
| 168 | +Open a web browser and in the address bar paste in the public DNS name of the Gateway resource that you just copied with a `:3000` appended to that address, as the application container is exposed to users on port 3000. You should see the demo application landing page showing that your application is running on your Azure Container Instance, along with some information about its containers and resources. |
| 169 | + |
| 170 | +{{< image src="demo-app-landing.png" alt="Screenshot of the demo app landing page" width=700px >}} |
| 171 | + |
| 172 | +Navigate to the Todo List tab and test out the application. Using the Todo page will update the saved state in your Azure Redis cache. |
| 173 | + |
| 174 | +{{< image src="demo-app.png" alt="Screenshot of the todo list in the demo app" width=700px >}} |
| 175 | + |
| 176 | +## Cleanup |
| 177 | + |
| 178 | +1. Run the following command to delete your app and its container and Redis cache resources: |
| 179 | + |
| 180 | + ```bash |
| 181 | + rad app delete demo-app --yes |
| 182 | + ``` |
| 183 | + |
| 184 | +1. Run the following command to delete your environment: |
| 185 | + |
| 186 | + ```bash |
| 187 | + rad env delete aci-env --yes |
| 188 | + ``` |
| 189 | + |
| 190 | +1. Run the following command to delete your workspace: |
| 191 | + |
| 192 | + ```bash |
| 193 | + rad workspace delete aci-workspace --yes |
| 194 | + ``` |
| 195 | + |
| 196 | +1. Finally, navigate to your Azure portal and delete the related resources that were created for the ACI Environment, namely the virtual network, internal load balancer, and network security group. You can also delete the resource group if you no longer need it. |
| 197 | + |
| 198 | + {{< image src="azure-portal-env.png" alt="Screenshot of the Azure portal showing the resource group with the virtual network, internal load balancer, and network security group resources created by Radius" width=700px >}} |
| 199 | + |
| 200 | +## Further reading |
| 201 | +- [Azure resources overview]({{< ref "/guides/author-apps/azure/overview" >}}) |
| 202 | +- [Radius Environment schema]({{< ref "/reference/resource-schema/core-schema/environment-schema" >}}) |
| 203 | +- [Radius Application schema]({{< ref "/reference/resource-schema/core-schema/application-schema" >}}) |
| 204 | +- [Radius Container schema]({{< ref "/reference/resource-schema/core-schema/container-schema" >}}) |
0 commit comments