mcpField
C
container-apps-gpu-2025

container-apps-gpu-2025

github.com/josiahsiegelクラウド・DevOps59158 回インストール19 週間前に更新
リポジトリ

container-apps-gpu-2025 について

Azure Container AppsでのGPU利用を扱うデプロイ・運用向けスキルです。AI/MLサービスを構築するチーム向けに、サーバーレスおよび専用GPU、Dapr、モデルホスティング、監視などを解説します。

主な機能

  1. 01サーバーレス・専用GPUのデプロイ
  2. 02GPUスケーリングとゼロスケール
  3. 03Daprのサービス・状態管理連携
  4. 04AIモデルのホスティングパターン
  5. 05監視とセキュリティのガイダンス

活用シーン

  1. 01GPUによるモデル推論のデプロイ
  2. 02GPUバッチ処理や学習の実行
  3. 03Daprを使ったコンテナマイクロサービス連携

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/josiahsiegel/claude-plugin-marketplace --skill container-apps-gpu-2025

インストール後、Claude Code で/container-apps-gpu-2025を入力して読み込まれたか確認します。

詳細

Azure Container Apps の GPU サポート - 2025 年の機能

GPU サポート、サーバーレス機能、Dapr 統合を備えた Azure Container Apps の包括的なナレッジベース(2025 年 GA 機能)です。

概要

Azure Container Apps は、ネイティブの GPU サポート、Dapr 統合、ゼロへのスケール機能を備えたサーバーレスコンテナプラットフォームであり、コスト効率の高い AI/ML ワークロードを実現します。

2025 年の主な機能(Build での発表)

1. サーバーレス GPU(GA)
  • 自動スケーリング:需要に応じて GPU ワークロードをスケールします
  • ゼロへのスケール:GPU が実際に使用されている場合にのみ料金が発生します
  • 秒単位の課金:きめ細かなコスト管理が可能です
  • 最適化されたコールドスタート:AI モデルをすばやく初期化します
  • 運用負荷の軽減:インフラストラクチャ管理が不要です
2. 専用 GPU(GA)
  • 安定したパフォーマンス:専用 GPU リソースを利用できます
  • AI のデプロイを簡素化:モデルを簡単にホストできます
  • 長時間実行されるワークロード:トレーニングや継続的な推論に最適です
  • 複数の GPU タイプ:NVIDIA A100、T4 など
3. GPU を使用した動的セッション(早期アクセス)
  • サンドボックスでの実行:信頼できない AI 生成コードを実行します
  • Hyper-V 分離:セキュリティを強化します
  • GPU 対応 Python インタープリター:計算負荷の高い AI ワークロードに対応します
  • 実行時のスケール:リソースを動的に割り当てます
4. Foundry Models の統合
  • AI モデルを直接デプロイ:コンテナアプリの作成時にデプロイできます
  • すぐに使えるモデル:事前構成済みの推論エンドポイントを利用できます
  • Azure AI Foundry:シームレスに統合できます
5. Durable Task Scheduler を使用したワークフロー(プレビュー)
  • 長時間実行されるワークフロー:信頼性の高いオーケストレーションを実現します
  • 状態管理:状態を自動的に永続化します
  • イベント駆動型:イベントからワークフローをトリガーします
6. Azure Functions のネイティブサポート
  • Functions ランタイム:Container Apps で Azure Functions を実行します
  • 一貫性のある開発:同じコードでサーバーレス実行できます
  • イベントトリガー:すべての Functions トリガーをサポートします
7. Dapr 統合(GA)
  • サービス検出:DNS ベースの検出機能が組み込まれています
  • 状態管理:分散状態ストアを利用できます
  • Pub/sub メッセージング:信頼性の高いメッセージングパターンを利用できます
  • サービス呼び出し:回復性の高いサービス間呼び出しを実現します
  • 可観測性:トレースとメトリックを統合できます

GPU を使用した Container Apps の作成

サーバーレス GPU を使用した基本的な Container App
# Create Container Apps environment
az containerapp env create \
  --name myenv \
  --resource-group MyRG \
  --location eastus \
  --logs-workspace-id <workspace-id> \
  --logs-workspace-key <workspace-key>

# Create Container App with GPU
az containerapp create \
  --name myapp-gpu \
  --resource-group MyRG \
  --environment myenv \
  --image myregistry.azurecr.io/ai-model:latest \
  --cpu 4 \
  --memory 8Gi \
  --gpu-type nvidia-a100 \
  --gpu-count 1 \
  --min-replicas 0 \
  --max-replicas 10 \
  --ingress external \
  --target-port 8080
GPU を使用した本番環境対応の Container App
az containerapp create \
  --name myapp-gpu-prod \
  --resource-group MyRG \
  --environment myenv \
  \
  # Container configuration
  --image myregistry.azurecr.io/ai-model:latest \
  --registry-server myregistry.azurecr.io \
  --registry-identity system \
  \
  # Resources
  --cpu 4 \
  --memory 8Gi \
  --gpu-type nvidia-a100 \
  --gpu-count 1 \
  \
  # Scaling
  --min-replicas 0 \
  --max-replicas 20 \
  --scale-rule-name http-scaling \
  --scale-rule-type http \
  --scale-rule-http-concurrency 10 \
  \
  # Networking
  --ingress external \
  --target-port 8080 \
  --transport http2 \
  --exposed-port 8080 \
  \
  # Security
  --registry-identity system \
  --env-vars "AZURE_CLIENT_ID=secretref:client-id" \
  \
  # Monitoring
  --dapr-app-id myapp \
  --dapr-app-port 8080 \
  --dapr-app-protocol http \
  --enable-dapr \
  \
  # Identity
  --system-assigned

Container Apps 環境の構成

ゾーン冗長性を備えた環境
az containerapp env create \
  --name myenv-prod \
  --resource-group MyRG \
  --location eastus \
  --logs-workspace-id <workspace-id> \
  --logs-workspace-key <workspace-key> \
  --zone-redundant true \
  --enable-workload-profiles true
ワークロードプロファイル(専用 GPU)
# Create environment with workload profiles
az containerapp env create \
  --name myenv-gpu \
  --resource-group MyRG \
  --location eastus \
  --enable-workload-profiles true

# Add GPU workload profile
az containerapp env workload-profile add \
  --name myenv-gpu \
  --resource-group MyRG \
  --workload-profile-name gpu-profile \
  --workload-profile-type GPU-A100 \
  --min-nodes 0 \
  --max-nodes 10

# Create container app with GPU profile
az containerapp create \
  --name myapp-dedicated-gpu \
  --resource-group MyRG \
  --environment myenv-gpu \
  --workload-profile-name gpu-profile \
  --image myregistry.azurecr.io/training-job:latest \
  --cpu 8 \
  --memory 16Gi \
  --min-replicas 1 \
  --max-replicas 5

GPU スケーリングルール

カスタム Prometheus スケーリング
az containerapp create \
  --name myapp-gpu-prometheus \
  --resource-group MyRG \
  --environment myenv \
  --image myregistry.azurecr.io/ai-model:latest \
  --cpu 4 \
  --memory 8Gi \
  --gpu-type nvidia-a100 \
  --gpu-count 1 \
  --min-replicas 0 \
  --max-replicas 10 \
  --scale-rule-name gpu-utilization \
  --scale-rule-type custom \
  --scale-rule-custom-type prometheus \
  --scale-rule-metadata \
    serverAddress=http://prometheus.monitoring.svc.cluster.local:9090 \
    metricName=gpu_utilization \
    threshold=80 \
    query="avg(nvidia_gpu_utilization{app='myapp'})"
キューベースのスケーリング(Azure Service Bus)
az containerapp create \
  --name myapp-queue-processor \
  --resource-group MyRG \
  --environment myenv \
  --image myregistry.azurecr.io/batch-processor:latest \
  --cpu 4 \
  --memory 8Gi \
  --gpu-type nvidia-t4 \
  --gpu-count 1 \
  --min-replicas 0 \
  --max-replicas 50 \
  --scale-rule-name queue-scaling \
  --scale-rule-type azure-servicebus \
  --scale-rule-metadata \
    queueName=ai-jobs \
    namespace=myservicebus \
    messageCount=5 \
  --scale-rule-auth connection=servicebus-connection

Dapr の統合

Container App で Dapr を有効化する
az containerapp create \
  --name myapp-dapr \
  --resource-group MyRG \
  --environment myenv \
  --image myregistry.azurecr.io/myapp:latest \
  --enable-dapr \
  --dapr-app-id myapp \
  --dapr-app-port 8080 \
  --dapr-app-protocol http \
  --dapr-http-max-request-size 4 \
  --dapr-http-read-buffer-size 4 \
  --dapr-log-level info \
  --dapr-enable-api-logging true
Dapr の状態ストア(Azure Cosmos DB)
# Create Dapr component for state store
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: statestore
spec:
  type: state.azure.cosmosdb
  version: v1
  metadata:
    - name: url
      value: "https://mycosmosdb.documents.azure.com:443/"
    - name: masterKey
      secretRef: cosmosdb-key
    - name: database
      value: "mydb"
    - name: collection
      value: "state"
# Create the component
az containerapp env dapr-component set \
  --name myenv \
  --resource-group MyRG \
  --dapr-component-name statestore \
  --yaml component.yaml
Dapr Pub/Sub(Azure Service Bus)
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
spec:
  type: pubsub.azure.servicebus.topics
  version: v1
  metadata:
    - name: connectionString
      secretRef: servicebus-connection
    - name: consumerID
      value: "myapp"
サービス間呼び出し
# Python example using Dapr SDK
from dapr.clients import DaprClient

with DaprClient() as client:
    # Invoke another service
    response = client.invoke_method(
        app_id='other-service',
        method_name='process',
        data='{"input": "data"}'
    )

    # Save state
    client.save_state(
        store_name='statestore',
        key='mykey',
        value='myvalue'
    )

    # Publish message
    client.publish_event(
        pubsub_name='pubsub',
        topic_name='orders',
        data='{"orderId": "123"}'
    )

AI モデルのデプロイパターン

OpenAI 互換エンドポイント
# Dockerfile for vLLM model serving
FROM vllm/vllm-openai:latest

ENV MODEL_NAME="meta-llama/Llama-3.1-8B-Instruct"
ENV GPU_MEMORY_UTILIZATION=0.9
ENV MAX_MODEL_LEN=4096

CMD ["--model", "${MODEL_NAME}", \
     "--gpu-memory-utilization", "${GPU_MEMORY_UTILIZATION}", \
     "--max-model-len", "${MAX_MODEL_LEN}", \
     "--port", "8080"]
# Deploy vLLM model
az containerapp create \
  --name llama-inference \
  --resource-group MyRG \
  --environment myenv \
  --image vllm/vllm-openai:latest \
  --cpu 8 \
  --memory 32Gi \
  --gpu-type nvidia-a100 \
  --gpu-count 1 \
  --min-replicas 1 \
  --max-replicas 5 \
  --target-port 8080 \
  --ingress external \
  --env-vars \
    MODEL_NAME="meta-llama/Llama-3.1-8B-Instruct" \
    GPU_MEMORY_UTILIZATION="0.9" \
    HF_TOKEN=secretref:huggingface-token
Stable Diffusion による画像生成
az containerapp create \
  --name stable-diffusion \
  --resource-group MyRG \
  --environment myenv \
  --image myregistry.azurecr.io/stable-diffusion:latest \
  --cpu 4 \
  --memory 16Gi \
  --gpu-type nvidia-a100 \
  --gpu-count 1 \
  --min-replicas 0 \
  --max-replicas 10 \
  --target-port 7860 \
  --ingress external \
  --scale-rule-name http-scaling \
  --scale-rule-type http \
  --scale-rule-http-concurrency 1
バッチ処理ジョブ
az containerapp job create \
  --name batch-training-job \
  --resource-group MyRG \
  --environment myenv \
  --trigger-type Manual \
  --image myregistry.azurecr.io/training:latest \
  --cpu 8 \
  --memory 32Gi \
  --gpu-type nvidia-a100 \
  --gpu-count 2 \
  --parallelism 1 \
  --replica-timeout 7200 \
  --replica-retry-limit 3 \
  --env-vars \
    DATASET_URL="https://mystorage.blob.core.windows.net/datasets/train.csv" \
    MODEL_OUTPUT="https://mystorage.blob.core.windows.net/models/" \
    EPOCHS="100"

# Execute job
az containerapp job start \
  --name batch-training-job \
  --resource-group MyRG

監視と可観測性

Application Insights の統合
az containerapp create \
  --name myapp-monitored \
  --resource-group MyRG \
  --environment myenv \
  --image myregistry.azurecr.io/myapp:latest \
  --env-vars \
    APPLICATIONINSIGHTS_CONNECTION_STRING=secretref:appinsights-connection
ログのクエリ
# Stream logs
az containerapp logs show \
  --name myapp-gpu \
  --resource-group MyRG \
  --follow

# Query with Log Analytics
az monitor log-analytics query \
  --workspace <workspace-id> \
  --analytics-query "ContainerAppConsoleLogs_CL | where ContainerAppName_s == 'myapp-gpu' | take 100"
メトリックとアラート
# Create metric alert for GPU usage
az monitor metrics alert create \
  --name high-gpu-usage \
  --resource-group MyRG \
  --scopes $(az containerapp show -g MyRG -n myapp-gpu --query id -o tsv) \
  --condition "avg Requests > 100" \
  --window-size 5m \
  --evaluation-frequency 1m \
  --action <action-group-id>

セキュリティのベストプラクティス

マネージド ID
# Create with system-assigned identity
az containerapp create \
  --name myapp-identity \
  --resource-group MyRG \
  --environment myenv \
  --system-assigned \
  --image myregistry.azurecr.io/myapp:latest

# Get identity principal ID
IDENTITY_ID=$(az containerapp show -g MyRG -n myapp-identity --query identity.principalId -o tsv)

# Assign role to access Key Vault
az role assignment create \
  --assignee $IDENTITY_ID \
  --role "Key Vault Secrets User" \
  --scope /subscriptions/<sub-id>/resourceGroups/MyRG/providers/Microsoft.KeyVault/vaults/mykeyvault

# Use user-assigned identity
az identity create --name myapp-identity --resource-group MyRG
IDENTITY_RESOURCE_ID=$(az identity show -g MyRG -n myapp-identity --query id -o tsv)

az containerapp create \
  --name myapp-user-identity \
  --resource-group MyRG \
  --environment myenv \
  --user-assigned $IDENTITY_RESOURCE_ID \
  --image myregistry.azurecr.io/myapp:latest
シークレット管理
# Add secrets
az containerapp secret set \
  --name myapp-gpu \
  --resource-group MyRG \
  --secrets \
    huggingface-token="<token>" \
    api-key="<key>"

# Reference secrets in environment variables
az containerapp update \
  --name myapp-gpu \
  --resource-group MyRG \
  --set-env-vars \
    HF_TOKEN=secretref:huggingface-token \
    API_KEY=secretref:api-key

コストの最適化

ゼロへのスケールの構成
az containerapp create \
  --name myapp-scale-zero \
  --resource-group MyRG \
  --environment myenv \
  --image myregistry.azurecr.io/myapp:latest \
  --min-replicas 0 \
  --max-replicas 10 \
  --scale-rule-name http-scaling \
  --scale-rule-type http \
  --scale-rule-http-concurrency 10

コスト削減:リクエストの処理中にのみ料金が発生します。GPU の料金は、アクティブな場合に秒単位で課金されます。

リソースの適正化
# Start with minimal resources
--cpu 2 --memory 4Gi --gpu-count 1

# Monitor and adjust based on actual usage
az monitor metrics list \
  --resource $(az containerapp show -g MyRG -n myapp-gpu --query id -o tsv) \
  --metric "CpuPercentage,MemoryPercentage"
Spot/プリエンプティブル GPU の使用(将来の機能)

利用可能になったら、重要度の低いワークロードでスポットインスタンスを構成すると、GPU コストを最大 80% 削減できます。

トラブルシューティング

リビジョンの状態を確認する
az containerapp revision list \
  --name myapp-gpu \
  --resource-group MyRG \
  --output table
リビジョンの詳細を表示する
az containerapp revision show \
  --name <revision-name> \
  --app myapp-gpu \
  --resource-group MyRG
Container App を再起動する
az containerapp update \
  --name myapp-gpu \
  --resource-group MyRG \
  --force-restart
GPU を利用できない

GPU がプロビジョニングされない場合:

  1. リージョンの利用可否を確認します:すべてのリージョンが GPU をサポートしているわけではありません
  2. クォータを確認します:必要に応じてクォータの引き上げを申請します
  3. ワークロードプロファイルを確認します:GPU ワークロードプロファイルが作成されていることを確認します

ベストプラクティス

✓ 間欠的なワークロードにはスケール・トゥ・ゼロを使用します ✓ ヘルスプローブ(ライブネスとレディネス)を実装します ✓ 認証にはマネージド ID を使用します ✓ シークレットは Azure Key Vault に保存します ✓ マイクロサービスのパターンには Dapr を有効にします ✓ 適切なスケーリングルールを構成します ✓ GPU の使用率を監視し、リソースを調整します ✓ バッチ処理には Container Apps のジョブを使用します ✓ 一時的な障害に備えて再試行ロジックを実装します ✓ 可観測性には Application Insights を使用します

参考資料

GPU をサポートする Azure Container Apps は、AI/ML ワークロードに最適なサーバーレスプラットフォームです!

コメント