Azure Container Apps の ARM と YAML テンプレートの仕様

Azure Container Apps のデプロイでは、Azure Resource Manager (ARM) テンプレートが使われます。 一部の Container Apps CLI コマンドでは、YAML テンプレートを使用したリソースの指定もサポートされています。

この記事では、頻繁に使用される Container Apps リソースの ARM と YAML の構成について説明します。 Container Apps リソースの完全な一覧については、Container Apps 用の Azure Resource Manager テンプレートを参照してください

API のバージョン

Azure Container Apps の最新の管理 API バージョンは次のとおりです。

API バージョン間の違いについては、「Microsoft.App 変更ログ」を参照してください。

API バージョンの更新

ARM または Bicep で特定の API バージョンを使用するには、テンプレートで参照されているバージョンを更新します。 Azure CLI または Azure PowerShell で最新の API バージョンを使用するには、最新バージョンに更新します。

次のコマンドを実行して、Azure CLI と Azure Container Apps 拡張機能を更新します。

az upgrade
az extension add -n containerapp --upgrade

Azure PowerShell を更新するには、「Azure PowerShell をインストールする方法」を参照してください

最新の API バージョンで Azure Container Apps をプログラムで管理するには、最新バージョンの管理 SDK を使用します。

Container Apps 環境

次の表では、Container Apps 環境リソースで使用できる一般的に使用されるプロパティについて説明します。 プロパティの完全な一覧については、Azure Container Apps REST API リファレンスを参照してください

リソース

Container Apps 環境リソースには、次のプロパティが含まれています。

プロパティ 説明 データ型 読み取り専用
daprAIInstrumentationKey Dapr が使用する Application Insights のインストルメンテーション キー。 string いいえ
appLogsConfiguration 環境のログ構成。 オブジェクト いいえ
peerAuthentication mTLS 暗号化を有効にする方法。 オブジェクト いいえ

次の ARM テンプレート スニペットの例では、Container Apps 環境をデプロイします。

Note

コンテナー アプリ環境を作成するコマンドは、YAML 構成入力をサポートしていません。

{
  "location": "East US",
  "properties": {
    "daprAIConnectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://northcentralus-0.in.applicationinsights.azure.com/",
    "appLogsConfiguration": {
      "logAnalyticsConfiguration": {
        "customerId": "string",
        "sharedKey": "string"
      }
    },
    "zoneRedundant": true,
    "vnetConfiguration": {
      "infrastructureSubnetId": "/subscriptions/<subscription_id>/resourceGroups/RGName/providers/Microsoft.Network/virtualNetworks/VNetName/subnets/subnetName1"
    },
    "customDomainConfiguration": {
      "dnsSuffix": "www.my-name.com",
      "certificateValue": "Y2VydA==",
      "certificatePassword": "1234"
    },
    "workloadProfiles": [
      {
        "name": "My-GP-01",
        "workloadProfileType": "GeneralPurpose",
        "minimumCount": 3,
        "maximumCount": 12
      },
      {
        "name": "My-MO-01",
        "workloadProfileType": "MemoryOptimized",
        "minimumCount": 3,
        "maximumCount": 6
      },
      {
        "name": "My-CO-01",
        "workloadProfileType": "ComputeOptimized",
        "minimumCount": 3,
        "maximumCount": 6
      },
      {
        "name": "My-consumption-01",
        "workloadProfileType": "Consumption"
      }
    ],
    "infrastructureResourceGroup": "myInfrastructureRgName"
  }
}

コンテナー アプリ

次の表では、コンテナー アプリ リソースで一般的に使用されるプロパティについて説明します。 プロパティの完全な一覧については、Azure Container Apps REST API リファレンスを参照してください

リソース

コンテナー アプリ リソースの properties オブジェクトには、次のプロパティが含まれています。

プロパティ 説明 データ型 読み取り専用
provisioningState 新しいコンテナー リビジョンが作成されるときなど、実行時間の長い操作の状態。 設定される可能性のある値は、provisioning、provisioned、failed です。 アプリが稼働しているかどうかを調べます。 string はい
environmentId コンテナー アプリの環境 ID。 これは、コンテナー アプリを作成するために必要なプロパティです。 YAML を使用している場合は、代わりに Azure CLI のオプションを --environment 使用して環境 ID を指定できます。 string いいえ
latestRevisionName 最新のリビジョンの名前。 string はい
latestRevisionFqdn 最新のリビジョンの URL。 string はい

environmentId の値の形式は次のとおりです。

/subscriptions/<SUBSCRIPTION_ID>/resourcegroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.App/environmentId/<ENVIRONMENT_NAME>

この例では、<> 角かっこで囲まれたプレースホルダー トークンの代わりに値を指定します。

properties.configuration

リソースの properties.configuration オブジェクトには、次のプロパティが含まれています。

プロパティ 説明 データ型
activeRevisionsMode single に設定すると、古いリビジョンは自動的に非アクティブにされ、最新のリビジョンのみがアクティブになります。 multiple に設定すると、複数のリビジョンを保持できます。 string
secrets コンテナー アプリでのシークレットの値を定義します。 object
ingress コンテナー アプリのパブリック アクセス可能性の構成を定義するオブジェクト。 object
registries プライベート コンテナー レジストリの資格情報を参照する構成オブジェクト。 secretref で定義されるエントリでは、シークレット構成オブジェクトが参照されます。 object
dapr コンテナー アプリの Dapr の設定を定義する構成オブジェクト。 object

configuration セクションの変更はアプリケーション スコープの変更であり、新しいリビジョンはトリガーされません。

properties.template

リソースの properties.template オブジェクトには、次のプロパティが含まれています。

プロパティ 説明 データ型
revisionSuffix リビジョンのフレンドリ名。 既存のリビジョン名のサフィックス値と競合するとランタイムによって拒否されるので、この値は一意である必要があります。 string
containers コンテナー アプリに含まれるコンテナー イメージを定義する構成オブジェクト。 object
scale コンテナー アプリのスケーリング ルールを定義する構成オブジェクト。 object

template セクションの変更はリビジョン スコープの変更であり、新しいリビジョンがトリガーされます。

正常性プローブの詳細については、「Azure Container Apps の正常性プローブ」を参照してください。

次の ARM テンプレート スニペットの例では、コンテナー アプリをデプロイします。

{
  "identity": {
    "userAssignedIdentities": {
      "/subscriptions/<subscription_id>/resourcegroups/my-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-user": {
      }
    },
    "type": "UserAssigned"
  },
  "properties": {
    "environmentId": "/subscriptions/<subscription_id>/resourceGroups/rg/providers/Microsoft.App/managedEnvironments/demokube",
    "workloadProfileName": "My-GP-01",
    "configuration": {
      "ingress": {
        "external": true,
        "targetPort": 3000,
        "customDomains": [
          {
            "name": "www.my-name.com",
            "bindingType": "SniEnabled",
            "certificateId": "/subscriptions/<subscription_id>/resourceGroups/rg/providers/Microsoft.App/managedEnvironments/demokube/certificates/my-certificate-for-my-name-dot-com"
          },
          {
            "name": "www.my-other-name.com",
            "bindingType": "SniEnabled",
            "certificateId": "/subscriptions/<subscription_id>/resourceGroups/rg/providers/Microsoft.App/managedEnvironments/demokube/certificates/my-certificate-for-my-other-name-dot-com"
          }
        ],
        "traffic": [
          {
            "weight": 100,
            "revisionName": "testcontainerApp0-ab1234",
            "label": "production"
          }
        ],
        "ipSecurityRestrictions": [
          {
            "name": "Allow work IP A subnet",
            "description": "Allowing all IP's within the subnet below to access containerapp",
            "ipAddressRange": "192.168.1.1/32",
            "action": "Allow"
          },
          {
            "name": "Allow work IP B subnet",
            "description": "Allowing all IP's within the subnet below to access containerapp",
            "ipAddressRange": "192.168.1.1/8",
            "action": "Allow"
          }
        ],
        "stickySessions": {
          "affinity": "sticky"
        },
        "clientCertificateMode": "accept",
        "corsPolicy": {
          "allowedOrigins": [
            "https://a.test.com",
            "https://b.test.com"
          ],
          "allowedMethods": [
            "GET",
            "POST"
          ],
          "allowedHeaders": [
            "HEADER1",
            "HEADER2"
          ],
          "exposeHeaders": [
            "HEADER3",
            "HEADER4"
          ],
          "maxAge": 1234,
          "allowCredentials": true
        }
      },
      "dapr": {
        "enabled": true,
        "appPort": 3000,
        "appProtocol": "http",
        "httpReadBufferSize": 30,
        "httpMaxRequestSize": 10,
        "logLevel": "debug",
        "enableApiLogging": true
      },
      "maxInactiveRevisions": 10,
      "service": {
        "type": "redis"
      }
    },
    "template": {
      "containers": [
        {
          "image": "repo/testcontainerApp0:v1",
          "name": "testcontainerApp0",
          "probes": [
            {
              "type": "Liveness",
              "httpGet": {
                "path": "/health",
                "port": 8080,
                "httpHeaders": [
                  {
                    "name": "Custom-Header",
                    "value": "Awesome"
                  }
                ]
              },
              "initialDelaySeconds": 3,
              "periodSeconds": 3
            }
          ],
          "volumeMounts": [
            {
              "mountPath": "/myempty",
              "volumeName": "myempty"
            },
            {
              "mountPath": "/myfiles",
              "volumeName": "azure-files-volume"
            },
            {
              "mountPath": "/mysecrets",
              "volumeName": "mysecrets"
            }
              ]
        }
      ],
      "initContainers": [
        {
          "image": "repo/testcontainerApp0:v4",
          "name": "testinitcontainerApp0",
          "resources": {
            "cpu": 0.2,
            "memory": "100Mi"
          },
          "command": [
            "/bin/sh"
          ],
          "args": [
            "-c",
            "while true; do echo hello; sleep 10;done"
          ]
        }
      ],
      "scale": {
        "minReplicas": 1,
        "maxReplicas": 5,
        "rules": [
          {
            "name": "httpscalingrule",
            "custom": {
              "type": "http",
              "metadata": {
                "concurrentRequests": "50"
              }
            }
          }
        ]
      },
      "volumes": [
        {
          "name": "myempty",
          "storageType": "EmptyDir"
        },
        {
          "name": "azure-files-volume",
          "storageType": "AzureFile",
          "storageName": "myazurefiles"
        },
        {
          "name": "mysecrets",
          "storageType": "Secret",
          "secrets": [
            {
              "secretRef": "mysecret",
              "path": "mysecret.txt"
            }
          ]
        }
      ],
      "serviceBinds": [
        {
          "serviceId": "/subscriptions/<subscription_id>/resourceGroups/rg/providers/Microsoft.App/containerApps/redisService",
          "name": "redisService"
        }
      ]
    }
  }
}

Container Apps ジョブ

次の表では、Container Apps ジョブ リソースで一般的に使用されるプロパティについて説明します。 プロパティの完全な一覧については、Azure Container Apps REST API リファレンスを参照してください

リソース

Container Apps ジョブ リソースの properties オブジェクトには、次のプロパティが含まれています。

プロパティ 説明 データ型 読み取り専用
environmentId Container Apps ジョブの環境 ID。 このプロパティは、Container Apps ジョブを作成するために必要です。 YAML を使用している場合は、代わりに Azure CLI のオプションを --environment 使用して環境 ID を指定できます。 string いいえ

environmentId の値の形式は次のとおりです。

/subscriptions/<SUBSCRIPTION_ID>/resourcegroups/<RESOURCE_GROUP_NAME>/providers/Microsoft.App/environmentId/<ENVIRONMENT_NAME>

この例では、<> 角かっこで囲まれたプレースホルダー トークンの代わりに値を指定します。

properties.configuration

リソースの properties.configuration オブジェクトには、次のプロパティが含まれています。

プロパティ 説明 データの種類
triggerType Container Apps ジョブのトリガーの種類。 トリガーの種類ごとに特定の構成については、「ジョブ トリガーの種類」を参照してください string
replicaTimeout Container Apps ジョブのタイムアウト (秒単位)。 integer
replicaRetryLimit Container Apps ジョブを再試行する回数。 integer

properties.template

リソースの properties.template オブジェクトには、次のプロパティが含まれています。

プロパティ 説明 データの種類
containers ジョブに含めるコンテナー イメージを定義する構成オブジェクト。 object
scale ジョブのスケール ルールを定義する構成オブジェクト。 object

次の ARM テンプレート スニペットの例では、Container Apps ジョブをデプロイします。

{
  "identity": {
    "userAssignedIdentities": {
      "/subscriptions/<subscription_id>/resourcegroups/my-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-user": {
      }
    },
    "type": "UserAssigned"
  },
  "properties": {
    "environmentId": "/subscriptions/<subscription_id>/resourceGroups/rg/providers/Microsoft.App/managedEnvironments/demokube",
    "configuration": {
      "replicaTimeout": 10,
      "replicaRetryLimit": 10,
      "manualTriggerConfig": {
        "replicaCompletionCount": 1,
        "parallelism": 4
      },
      "triggerType": "Manual"
    },
    "template": {
      "containers": [
        {
          "image": "repo/testcontainerAppsJob0:v1",
          "name": "testcontainerAppsJob0",
          "probes": [
            {
              "type": "Liveness",
              "httpGet": {
                "path": "/health",
                "port": 8080,
                "httpHeaders": [
                  {
                    "name": "Custom-Header",
                    "value": "Awesome"
                  }
                ]
              },
              "initialDelaySeconds": 5,
              "periodSeconds": 3
            }
          ],
          "volumeMounts": [
            {
              "mountPath": "/myempty",
              "volumeName": "myempty"
            },
            {
              "mountPath": "/myfiles",
              "volumeName": "azure-files-volume"
            },
            {
              "mountPath": "/mysecrets",
              "volumeName": "mysecrets"
            }
          ]
        }
      ],
      "initContainers": [
        {
          "image": "repo/testcontainerAppsJob0:v4",
          "name": "testinitcontainerAppsJob0",
          "resources": {
            "cpu": 0.2,
            "memory": "100Mi"
          },
          "command": [
            "/bin/sh"
          ],
          "args": [
            "-c",
            "while true; do echo hello; sleep 10;done"
          ]
        }
      ],
      "volumes": [
        {
          "name": "myempty",
          "storageType": "EmptyDir"
        },
        {
          "name": "azure-files-volume",
          "storageType": "AzureFile",
          "storageName": "myazurefiles"
        },
        {
          "name": "mysecrets",
          "storageType": "Secret",
          "secrets": [
            {
              "secretRef": "mysecret",
              "path": "mysecret.txt"
            }
          ]
        }
      ]
    }
  }
}