Share via


Azure Container Apps ARM 和 YAML 範本規格

Azure Container Apps 部署是由 Azure Resource Manager (ARM) 範本所提供。 某些 Container Apps CLI 命令也支援使用 YAML 範本來指定資源。

本文說明常用容器應用程式資源的 ARM 和 YAML 組態。 如需容器應用程式資源的完整清單,請參閱 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 環境資源中常用的屬性。 如需屬性的完整清單,請參閱 Azure Container Apps REST API 參考

資源

Container Apps 環境資源包含下列屬性:

屬性 說明 資料類型 唯讀
daprAIInstrumentationKey Dapr 所使用的 Application Insights 檢測金鑰。 string No
appLogsConfiguration 環境的記錄設定。 Object No
peerAuthentication 如何啟用 mTLS 加密。 Object No

範例

下列範例 ARM 範本程式碼片段會部署 Container Apps 環境。

注意

建立容器應用程式環境的命令不支援 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 長時間執行作業的狀態,例如,建立新的容器修訂時。 可能的值包括:布建、布建、失敗。 檢查應用程式是否已啟動並執行。 string Yes
environmentId 容器應用程式的環境識別碼。 這是建立容器應用程式的必要屬性。 如果您使用 YAML,則可以改用 --environment Azure CLI 中的 選項來指定環境識別碼。 string No
latestRevisionName 最新修訂的名稱。 string Yes
latestRevisionFqdn 最新的修訂 URL。 string Yes

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 作業資源中常用的屬性。 如需屬性的完整清單,請參閱 Azure Container Apps REST API 參考

資源

Container Apps 作業資源的 properties 物件包含下列屬性:

屬性 說明 資料類型 唯讀
environmentId 容器應用程式作業的環境識別碼。 建立 Container Apps 作業需要這個屬性。 如果您使用 YAML,則可以改用 --environment Azure CLI 中的 選項來指定環境識別碼。 string No

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 作業的逾時以秒為單位。 整數
replicaRetryLimit 重試 Container Apps 作業的次數。 整數

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"
            }
          ]
        }
      ]
    }
  }
}