-
-
Save cicorias/476ad84e0356ed9d2759893a97f94752 to your computer and use it in GitHub Desktop.
Deploy an Azure Container App with NVIDIA CUDA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| LOCATION=westus3 | |
| WORKLOAD_PROFILE_TYPE="Consumption-GPU-NC24-A100" | |
| WORKLOAD_PROFILE_NAME="nc24-a100-profile" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ############################################################################### | |
| # Azure Container Apps — Serverless GPU Quick Test | |
| # Source: https://learn.microsoft.com/en-us/azure/container-apps/gpu-image-generation | |
| # | |
| # Prerequisites: | |
| # - Azure CLI installed (az --version) | |
| # - Logged in (az login) | |
| # - Container Apps extension installed | |
| # - GPU quota approved (EA and pay-as-you-go customers have it by default) | |
| # | |
| # What this does: | |
| # Deploys Microsoft's GPU quickstart image on a T4 GPU workload profile, | |
| # exposes it publicly, and prints the URL. | |
| # | |
| # Estimated cost: T4 GPU billed per-second while running. DELETE when done! | |
| ############################################################################### | |
| set -euo pipefail | |
| # read a .env file if it exists | |
| if [ -f ".env" ]; then | |
| export $(grep -v '^#' .env | xargs) | |
| fi | |
| # ---------- configuration ---------- | |
| RESOURCE_GROUP="${RESOURCE_GROUP:-gpu-test-rg}" | |
| LOCATION="${LOCATION:-swedencentral}" # Must support T4 — see supported regions | |
| ENVIRONMENT_NAME="${ENVIRONMENT_NAME:-gpu-test-env}" | |
| CONTAINER_APP_NAME="${CONTAINER_APP_NAME:-gpu-quickstart}" | |
| CONTAINER_IMAGE="${CONTAINER_IMAGE:-mcr.microsoft.com/k8se/gpu-quickstart:latest}" | |
| # Workload profile for T4 GPU | |
| WORKLOAD_PROFILE_NAME="${WORKLOAD_PROFILE_NAME:-NC8as-T4}" | |
| WORKLOAD_PROFILE_TYPE="${WORKLOAD_PROFILE_TYPE:-Consumption-GPU-NC8as-T4}" | |
| # ----- | |
| # | Profile | GPU | Typical VRAM | Intended class | | |
| # |------|---|---|---| | |
| # | **Consumption-GPU-NC24-A100** | NVIDIA **A100** | ~80 GB (HBM2e) | **Training + large models** | | |
| # | **Consumption-GPU-NC8as-T4** | NVIDIA **T4** | 16 GB (GDDR6) | **Inference / light compute** | | |
| # ---------- 0. ensure CLI extensions are current ---------- | |
| echo ">>> Updating Azure CLI extensions..." | |
| az extension add --name containerapp --upgrade --allow-preview true -y 2>/dev/null || true | |
| # ---------- 1. create resource group ---------- | |
| echo ">>> Creating resource group: $RESOURCE_GROUP in $LOCATION..." | |
| az group create \ | |
| --name "$RESOURCE_GROUP" \ | |
| --location "$LOCATION" \ | |
| --query "properties.provisioningState" \ | |
| --output tsv | |
| # ---------- 2. create Container Apps environment ---------- | |
| echo ">>> Creating Container Apps environment: $ENVIRONMENT_NAME..." | |
| az containerapp env create \ | |
| --name "$ENVIRONMENT_NAME" \ | |
| --resource-group "$RESOURCE_GROUP" \ | |
| --location "$LOCATION" \ | |
| --query "properties.provisioningState" \ | |
| --output tsv | |
| # ---------- 3. add GPU workload profile ---------- | |
| echo ">>> Adding GPU workload profile ($WORKLOAD_PROFILE_TYPE)..." | |
| az containerapp env workload-profile add \ | |
| --name "$ENVIRONMENT_NAME" \ | |
| --resource-group "$RESOURCE_GROUP" \ | |
| --workload-profile-name "$WORKLOAD_PROFILE_NAME" \ | |
| --workload-profile-type "$WORKLOAD_PROFILE_TYPE" | |
| # ---------- 4. deploy the container app ---------- | |
| echo ">>> Deploying container app: $CONTAINER_APP_NAME..." | |
| APP_FQDN=$(az containerapp create \ | |
| --name "$CONTAINER_APP_NAME" \ | |
| --resource-group "$RESOURCE_GROUP" \ | |
| --environment "$ENVIRONMENT_NAME" \ | |
| --image "$CONTAINER_IMAGE" \ | |
| --target-port 80 \ | |
| --ingress external \ | |
| --cpu 8.0 \ | |
| --memory 56.0Gi \ | |
| --workload-profile-name "$WORKLOAD_PROFILE_NAME" \ | |
| --query "properties.configuration.ingress.fqdn" \ | |
| --output tsv) | |
| echo "" | |
| echo "============================================" | |
| echo " Deployment complete!" | |
| echo " App URL: https://$APP_FQDN" | |
| echo "============================================" | |
| echo "" | |
| echo "NOTE: First startup may take up to 5 minutes while the GPU initializes." | |
| echo "" | |
| # ---------- 5. (optional) verify GPU inside the container ---------- | |
| echo ">>> To verify GPU access, run:" | |
| echo " az containerapp exec \\" | |
| echo " --name $CONTAINER_APP_NAME \\" | |
| echo " --resource-group $RESOURCE_GROUP \\" | |
| echo " --command nvidia-smi" | |
| echo "" | |
| # ---------- cleanup instructions ---------- | |
| echo ">>> TO AVOID ONGOING CHARGES, delete when finished:" | |
| echo " az group delete --name $RESOURCE_GROUP --yes --no-wait" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment