LoginSignup
1
0

More than 1 year has passed since last update.

パブリックプレビューの Azure Container Apps を試してみた

Posted at

背景と目的

Azure でコンテナーを使うサービスは色々とありますが、新たに Azure Container Apps というサービスが追加されたので Azure CLI で試してみました。

前提条件

コマンドの実施環境は、Mac + Azure CLI です。

$ sw_vers
ProductName:    macOS
ProductVersion: 12.0.1
BuildVersion:   21A559

$ az version
{
  "azure-cli": "2.30.0",
  "azure-cli-core": "2.30.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {}
}

Container Apps 用のエクステンションを Azure CLI に追加

az extension add \
  --source https://workerappscliextension.blob.core.windows.net/azure-cli-extension/containerapp-0.2.0-py2.py3-none-any.whl

エクステンションの追加後は、このようになりました。

az version
{
  "azure-cli": "2.30.0",
  "azure-cli-core": "2.30.0",
  "azure-cli-telemetry": "1.0.6",
  "extensions": {
    "containerapp": "0.2.0"
  }
}

Container Apps を作成

公式ドキュメント内に利用可能なリージョンの記述を見つけられませんでしたが、トライアンドエラーの結果私の環境では以下のリージョンが利用可能なようでした。

  • eastus
  • northeurope
  • canadacentral
# 環境変数をセットします
region=eastus
prefix=mnrcapp

# リソースグループを作成します
az group create \
  --name ${prefix}-rg \
  --location $region

# Log Analytics を作成します
az monitor log-analytics workspace create \
  --resource-group ${prefix}-rg \
  --workspace-name ${prefix}-logs

# Container Apps 環境を作成します
az containerapp env create \
  --name ${prefix}-env \
  --resource-group ${prefix}-rg \
  --logs-workspace-id $(az monitor log-analytics workspace show \
  --resource-group ${prefix}-rg \
  --workspace-name ${prefix}-logs \
  --query customerId \
  --output tsv) \
  --logs-workspace-key $(az monitor log-analytics workspace get-shared-keys \
  --resource-group ${prefix}-rg \
  --workspace-name ${prefix}-logs \
  --query primarySharedKey \
  --output tsv)

# コンテナーを Azure Container Apps にデプロイします
az containerapp create \
  --name ${prefix} \
  --resource-group ${prefix}-rg \
  --environment ${prefix}-env \
  --image mcr.microsoft.com/azuredocs/containerapps-helloworld:latest \
  --target-port 80 \
  --ingress external

ここで以下のメッセージが表示される場合は、コマンドを追加してから再度デプロイします。

MissingRegistrationForLocation: The subscription is not registered for the resource type 'containerApps' in the location 'eastus'. Please re-register for this provider in order to have access to this location.

# containerApps リソースタイプにロケーション情報を登録します
az provider register \
  --namespace Microsoft.Web

コンテナーアプリの FQDN を表示して、ブラウザでアクセスします。

# コンテナーアプリの FQDN を表示します
az containerapp show \
  --name ${prefix} \
  --resource-group ${prefix}-rg \
  --query configuration.ingress.fqdn \
  --output tsv

参考

作成したリソースを削除します。

bash
# リソースグループを削除します
az group delete \
  --name ${prefix}-rg

参考サイトです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0