|
| 1 | +--- |
| 2 | +title: 'Tutorial: Create a container app on Azure Arc' |
| 3 | +description: Get started with Azure Container Apps on Azure Arc-enabled Kubernetes deploying your first app. |
| 4 | +services: container-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: container-apps |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 11/29/2022 |
| 9 | +ms.author: cshoe |
| 10 | +--- |
| 11 | + |
| 12 | +# Tutorial: Create an Azure Container App on Azure Arc-enabled Kubernetes (Preview) |
| 13 | + |
| 14 | +In this tutorial, you create a [Container app to an Azure Arc-enabled Kubernetes cluster](azure-arc-enable-cluster.md) (Preview) and learn to: |
| 15 | + |
| 16 | +> [!div class="checklist"] |
| 17 | +> * Create a container app on Azure Arc |
| 18 | +> * View your application's diagnostics |
| 19 | +
|
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +Before you proceed to create a container app, you first need to set up an [Azure Arc-enabled Kubernetes cluster to run Azure Container Apps](azure-arc-enable-cluster.md). |
| 23 | + |
| 24 | +## Add Azure CLI extensions |
| 25 | + |
| 26 | +Launch the Bash environment in [Azure Cloud Shell](../cloud-shell/quickstart.md). |
| 27 | + |
| 28 | +[](https://shell.azure.com) |
| 29 | + |
| 30 | +Next, add the required Azure CLI extensions. |
| 31 | + |
| 32 | +> [!WARNING] |
| 33 | +> The following command installs a custom Container Apps extension that can't be used with the public cloud service. You need to uninstall the extension if you switch back to the Azure public cloud. |
| 34 | +
|
| 35 | +```azurecli-interactive |
| 36 | +az extension add --upgrade --yes --name customlocation |
| 37 | +az extension remove --name containerapps |
| 38 | +az extension add -s https://download.microsoft.com/download/5/c/2/5c2ec3fc-bd2a-4615-a574-a1b7c8e22f40/containerapp-0.0.1-py2.py3-none-any.whl --yes |
| 39 | +``` |
| 40 | + |
| 41 | +## Create a resource group |
| 42 | + |
| 43 | +Create a resource group for the services created in this tutorial. |
| 44 | + |
| 45 | +```azurecli-interactive |
| 46 | +az group create --name myResourceGroup --location eastus |
| 47 | +``` |
| 48 | + |
| 49 | +## Get custom location information |
| 50 | + |
| 51 | +Get the following location group, name, and ID from your cluster administrator. See [Create a custom location](azure-arc-enable-cluster.md) for details. |
| 52 | + |
| 53 | +```azurecli-interactive |
| 54 | +customLocationGroup="<RESOURCE_GROUP_CONTAINING_CUSTOM_LOCATION>" |
| 55 | +``` |
| 56 | + |
| 57 | +```azurecli-interactive |
| 58 | +customLocationName="<NAME_OF_CUSTOM_LOCATION>" |
| 59 | +``` |
| 60 | + |
| 61 | +Get the custom location ID. |
| 62 | + |
| 63 | +```azurecli-interactive |
| 64 | +customLocationId=$(az customlocation show \ |
| 65 | + --resource-group $customLocationGroup \ |
| 66 | + --name $customLocationName \ |
| 67 | + --query id \ |
| 68 | + --output tsv) |
| 69 | +``` |
| 70 | + |
| 71 | +## Retrieve connected environment ID |
| 72 | + |
| 73 | +Now that you have the custom location ID, you can query for the connected environment. |
| 74 | + |
| 75 | +A connected environment is largely the same as a standard Container Apps environment, but network restrictions are controlled by the underlying Arc-enabled Kubernetes cluster. |
| 76 | + |
| 77 | +```azure-interactive |
| 78 | +myConnectedEnvironment = az containerapp connected-env list --custom-location customLocationId -o tsv --query '[].id' |
| 79 | +``` |
| 80 | + |
| 81 | +## Create an app |
| 82 | + |
| 83 | +The following example creates a Node.js app. |
| 84 | + |
| 85 | +```azurecli-interactive |
| 86 | + az container app create \ |
| 87 | + --resource-group myResourceGroup \ |
| 88 | + --name myContainerApp \ |
| 89 | + --environment myConnectedEnvironment \ |
| 90 | + --environment-type connected \ |
| 91 | + --image mcr.microsoft.com/azuredocs/container-apps-helloworld:latest \ |
| 92 | + --target-port 80 \ |
| 93 | + --ingress 'external' |
| 94 | +
|
| 95 | +az containerapp browse --resource-group myResourceGroup \ |
| 96 | + --name myContainerApp |
| 97 | +``` |
| 98 | + |
| 99 | +## Get diagnostic logs using Log Analytics |
| 100 | + |
| 101 | +> [!NOTE] |
| 102 | +> A Log Analytics configuration is required as you [install the Container Apps extension](azure-arc-enable-cluster.md) to view diagnostic information. If you installed the extension without Log Analytics, skip this step. |
| 103 | +
|
| 104 | +Navigate to the [Log Analytics workspace that's configured with your Container Apps extension](azure-arc-enable-cluster.md), then select **Logs** in the left navigation. |
| 105 | + |
| 106 | +Run the following sample query to show logs over the past 72 hours. |
| 107 | + |
| 108 | +If there's an error when running a query, try again in 10-15 minutes. There may be a delay for Log Analytics to start receiving logs from your application. |
| 109 | + |
| 110 | +```kusto |
| 111 | +let StartTime = ago(72h); |
| 112 | +let EndTime = now(); |
| 113 | +ContainerAppsConsoleLogs_CL |
| 114 | +| where TimeGenerated between (StartTime .. EndTime) |
| 115 | +| where AppName_s =~ "myContainerApp" |
| 116 | +``` |
| 117 | + |
| 118 | +The application logs for all the apps hosted in your Kubernetes cluster are logged to the Log Analytics workspace in the custom log table named `ContainerAppsConsoleLogs_CL`. |
| 119 | + |
| 120 | +* **Log_s** contains application logs for a given Container Apps extension |
| 121 | +* **AppName_s** contains the Container App app name. In addition to logs you write via your application code, the *Log_s* column also contains logs on container startup and shutdown. |
| 122 | + |
| 123 | +You can learn more about log queries in [getting started with Kusto](../azure-monitor/logs/get-started-queries.md). |
| 124 | + |
| 125 | +## Next steps |
| 126 | + |
| 127 | +- [Communication between microservices](communicate-between-microservices.md) |
0 commit comments