|
| 1 | +--- |
| 2 | +title: 'Tutorial: Troubleshoot an app using an Azure SRE Agent (preview) in Azure Container Apps' |
| 3 | +description: Deploy an automated agent to help monitor and resolve issues with an SRE Agent in Azure Container Apps. |
| 4 | +services: container-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: azure-container-apps |
| 7 | +ms.topic: tutorial |
| 8 | +ms.date: 05/19/2025 |
| 9 | +ms.author: cshoe |
| 10 | +--- |
| 11 | + |
| 12 | +# Tutorial: Troubleshoot an app using an Azure SRE Agent (preview) in Azure Container Apps |
| 13 | + |
| 14 | +The [Azure SRE Agent](../app-service/sre-agent-overview.md) helps you manage and monitor Azure resources by using AI-enabled capabilities. Agents guide you in solving problems and aids in build resilient, self-healing systems on your behalf. |
| 15 | + |
| 16 | +In this tutorial, you: |
| 17 | + |
| 18 | +> [!div class="checklist"] |
| 19 | +> * Deploy a sample container app using the Azure portal |
| 20 | +> * Create an Azure SRE Agent to monitor the app |
| 21 | +> * Intentionally misconfigure the container app |
| 22 | +> * Use AI-driven prompts to troubleshoot and fix errors |
| 23 | +
|
| 24 | +> [!IMPORTANT] |
| 25 | +> The following tutorial features an AI-enabled service powered by a language model. The steps represented in this article reflect how the model is expected to respond. However, the responses you encounter from your agent will differ from what you see listed here. Use the sample prompts as examples to help you achieve your goals. |
| 26 | +
|
| 27 | +## Prerequisites |
| 28 | + |
| 29 | +* **Azure account**: An Azure account with an active subscription is required. If you don't already have one, you can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 30 | + |
| 31 | +* **Security context**: Ensure your user account has the `Microsoft.Authorization/roleAssignments/write` permissions using either [Role Based Access Control Administrator](/azure/role-based-access-control/built-in-roles) or [User Access Administrator](/azure/role-based-access-control/built-in-roles). |
| 32 | + |
| 33 | +## 1. Create a container app |
| 34 | + |
| 35 | +Begin by creating an app for your agent to monitor. |
| 36 | + |
| 37 | +1. Go to the [Azure portal](https://portal.azure.com) and search for **Container Apps** in the top search bar. |
| 38 | + |
| 39 | +1. Select **Container Apps** in the search results. |
| 40 | + |
| 41 | +1. Select the **Create** button. |
| 42 | + |
| 43 | +### Basics tab |
| 44 | + |
| 45 | +In the *Basics* tab, take the following actions. |
| 46 | + |
| 47 | +1. Enter the following values in the *Project details* section. |
| 48 | + |
| 49 | + | Setting | Action | |
| 50 | + |---|---| |
| 51 | + | Subscription | Select your Azure subscription. | |
| 52 | + | Resource group | Select **Create new** and enter **my-aca-app-group**. | |
| 53 | + | Container app name | Enter **my-container-app**. | |
| 54 | + | Deployment source | Select **Container image**. | |
| 55 | + |
| 56 | +1. Enter the following values in the *Container Apps Environment* section. |
| 57 | + |
| 58 | + | Setting | Action | |
| 59 | + |---|---| |
| 60 | + | Region | Select a region near you. | |
| 61 | + | Container Apps Environment | Use the default value. | |
| 62 | + |
| 63 | +1. Select the **Container** tab. |
| 64 | + |
| 65 | +1. Select the checkbox next to **Use quickstart image**. |
| 66 | + |
| 67 | +### Deploy the container app |
| 68 | + |
| 69 | +1. Select **Review and create** at the bottom of the page. |
| 70 | + |
| 71 | + If no errors are found, the *Create* button is enabled. |
| 72 | + |
| 73 | + If there are errors, any tab containing errors is marked with a red dot. Navigate to the appropriate tab. Fields containing an error are highlighted in red. Once all errors are fixed, select **Review and create** again. |
| 74 | + |
| 75 | +1. Select **Create**. |
| 76 | + |
| 77 | + A page with the message *Deployment is in progress* is displayed. |
| 78 | + |
| 79 | + Once the deployment is complete, you see the message: *Your deployment is complete*. |
| 80 | + |
| 81 | +### Verify deployment |
| 82 | + |
| 83 | +1. To view your new container app, select **Go to resource**. |
| 84 | + |
| 85 | +1. To your application in a browser, select the link next to *Application URL*. |
| 86 | + |
| 87 | +1. The following message appears in your browser. |
| 88 | + |
| 89 | + :::image type="content" source="media/get-started/azure-container-apps-quickstart.png" alt-text="Your first Azure Container Apps deployment."::: |
| 90 | + |
| 91 | +## 2. Create an agent |
| 92 | + |
| 93 | +Next, create an agent to monitor the *my-aca-app-group* resource group. |
| 94 | + |
| 95 | +1. Go to the Azure portal and search for and select **SRE Agent**. |
| 96 | + |
| 97 | +1. Select **Create**. |
| 98 | + |
| 99 | +1. Enter the following values in the *Create agent* window. |
| 100 | + |
| 101 | + During this step, you create a new resource group specifically for your agent which is independent of the resource group used for your application. |
| 102 | + |
| 103 | + | Property | Value | |
| 104 | + |---|---| |
| 105 | + | Subscription | Select your Azure subscription. | |
| 106 | + | Resource group | Enter **my-sre-agent-group**. | |
| 107 | + | Name | Enter **my-aca-sre-agent**. | |
| 108 | + | Region | Select **Sweden Central**.<br><br>During preview, the SRE Agent is only available in the *Sweden Central* region, but an agent can monitor resources in any Azure region. | |
| 109 | + | Choose role | Select **Contributor role**. | |
| 110 | + |
| 111 | +1. In the *Managed resource groups* section, select the **Select resource groups** button. |
| 112 | + |
| 113 | +1. In the *Select resource groups to monitor* window, search for the resource group you want to monitor. |
| 114 | + |
| 115 | + **Avoid selecting the resource group name link.** |
| 116 | + |
| 117 | + To select a resource group, select the checkbox next to the **my-aca-app-group** resource group. |
| 118 | + |
| 119 | +1. Scroll to the bottom of the dialog window and select **Save**. |
| 120 | + |
| 121 | +1. Select **Create**. |
| 122 | + |
| 123 | +## 3. Chat with your agent |
| 124 | + |
| 125 | +Your agent has access to any resource inside the resource groups associated with the agent. Use the chat feature to help you inquire about and resolve issues related to your resources. |
| 126 | + |
| 127 | +1. Go to the Azure portal, search for and select **SRE Agent**. |
| 128 | + |
| 129 | +1. Select **my-aca-sre-agent** from the list. |
| 130 | + |
| 131 | +1. In the chat box, give your agent the following command. |
| 132 | + |
| 133 | + ```text |
| 134 | + List my container apps |
| 135 | + ``` |
| 136 | +
|
| 137 | +1. The agent responds with details about the container app deployed in the *my-aca-app-group* resource group. |
| 138 | +
|
| 139 | +Now that you have an agent that sees your container app, you can create an opportunity for the agent to make a repair on your behalf. |
| 140 | +
|
| 141 | +## 4. Break the app |
| 142 | +
|
| 143 | +By introducing a typo into the container image tag, you bring the app down so the agent can bring it back up. |
| 144 | +
|
| 145 | +1. Go to your container app in the Azure portal. |
| 146 | +
|
| 147 | +1. From the side menu, under *Application*, select **Revisions and replicas**. |
| 148 | +
|
| 149 | +1. Select **Create new revision**. |
| 150 | +
|
| 151 | +1. Select the container name beginning with **simple-hello-world** which opens the *Edit container* window. |
| 152 | +
|
| 153 | +1. Append a `1` the value in the *Image and tag* box. |
| 154 | +
|
| 155 | + The value should now read `k8se/quickstart:latest1`. |
| 156 | +
|
| 157 | +1. Select **Save** to exit the *Edit container* window. |
| 158 | +
|
| 159 | +1. Select **Create** to create the new revision. |
| 160 | +
|
| 161 | + Once you create the new revision, you return back the *Revisions and replicas* window. |
| 162 | +
|
| 163 | +1. Select **Refresh** to see your new revision in the list. |
| 164 | +
|
| 165 | +1. Wait for the deployment to fail as reported by the *Running status* column. |
| 166 | +
|
| 167 | +## 5. Roll back to fix your app |
| 168 | +
|
| 169 | +1. Go to the Azure portal, search for and select **SRE Agent**. |
| 170 | +
|
| 171 | +1. Select **my-aca-sre-agent** from the list to open a chat environment. |
| 172 | +
|
| 173 | +1. In the chat box, give your agent the following command and wait for a response. |
| 174 | +
|
| 175 | + ```text |
| 176 | + What's wrong with my-container-app? |
| 177 | + ``` |
| 178 | +
|
| 179 | + From here, the agent recognizes that the tag name is invalid. |
| 180 | +
|
| 181 | + While every chat session is different, you should see a response that resembles the following response. |
| 182 | +
|
| 183 | + > The image reference for **my-container-app** is `mcr.microsoft.com/k8se/quickstart:latest1`, which is a Microsoft Container Registry (MCR) image. |
| 184 | + > |
| 185 | + > **The tag `latest1` does not exist, causing the image pull failure.** |
| 186 | + > |
| 187 | + > You should update the image tag to a valid one, such as `latest`. Would you like me to update the container image to `mcr.microsoft.com/k8se/quickstart:latest` and redeploy the app? |
| 188 | +
|
| 189 | +1. In the chat box, respond with **yes** to approve the request to redeploy. |
| 190 | +
|
| 191 | + If your agent doesn't respond with a "yes or no" question, you can give your agent the following command and wait for a response. |
| 192 | +
|
| 193 | + ```text |
| 194 | + Rollback to the last working version. |
| 195 | + ``` |
| 196 | +
|
| 197 | +1. As the agent concludes the rollback analysis, it asks you for approval to execute the rollback operation. |
| 198 | +
|
| 199 | + Select **Approve** to approve the action to fix your container app. |
| 200 | +
|
| 201 | + :::image type="content" source="media/sre-agent-troubleshoot/azure-container-apps-sre-agent-approve.png" alt-text="Screenshot of an SRE Agent requesting permission to fix a container app."::: |
| 202 | +
|
| 203 | + After the rollback is successful, you should see a response similar to: |
| 204 | +
|
| 205 | + > ✅ The container app my-container-app is now healthy! The image was successfully updated and the app is running with 1 ready replica. |
| 206 | +
|
| 207 | +## 6. Verify repair |
| 208 | +
|
| 209 | +Now you can prompt your agent to return your app's fully qualified domain name (FQDN) so you can verify a successful deployment. |
| 210 | +
|
| 211 | +1. In the chat box, enter the following prompt. |
| 212 | +
|
| 213 | + ```text |
| 214 | + What is the FQDN for this container app? |
| 215 | +
|
| 216 | + Format your response as a clickable link. |
| 217 | + ``` |
| 218 | +
|
| 219 | +1. To verify your container app is working properly, select the link to open your app in a web browser. |
| 220 | +
|
| 221 | +## Clean up resources |
| 222 | +
|
| 223 | +If you're not going to continue to use this application, you can delete the container app and all the associated services by removing the resource groups created in this article. |
| 224 | +
|
| 225 | +Execute the following steps for both the *my-aca-app-group* and *my-sre-agent-group* resource groups. |
| 226 | +
|
| 227 | +1. Go to the resource group in the Azure portal. |
| 228 | +
|
| 229 | +1. From the *Overview* section, select **Delete resource group**. |
| 230 | +
|
| 231 | +1. Enter the resource group name in the confirmation dialog. |
| 232 | +
|
| 233 | +1. Select **Delete**. |
| 234 | +
|
| 235 | + The process to delete the resource group can take a few minutes to complete. |
| 236 | +
|
| 237 | +## Related content |
| 238 | +
|
| 239 | +* [SRE Agent overview](../app-service/sre-agent-overview.md) |
| 240 | +* [Azure SRE Agent usage](../app-service/sre-agent-usage.md) |
0 commit comments