共用方式為


搭配 Batch 集區使用延伸模組

延伸模組是小型應用程式,可協助在 Batch 計算節點上進行佈建後的設定及安裝。 你可以選擇任何允許的擴充功能,並在運算節點配置完成時安裝它們。 之後,延伸模組就可以執行預定的作業。

您可以檢查您使用之延伸模組的即時狀態,並擷取其所傳回的資訊,以執行任何偵測、更正或診斷功能。

先決條件

  • 具有延伸模組的集區必須使用虛擬機器設定 (部分機器翻譯)。
  • CustomScript 延伸模組類型會保留給 Azure Batch 服務,且無法覆寫。
  • 某些延伸模組可能需要在計算節點的內容中存取集區層級受控識別,才能正常運作。 請參閱在 Batch 集區中設定受控識別,以確認是否適用於延伸模組。

秘訣

擴充功能無法新增到現有的池子裡。 必須重新建立集區才能新增、移除或更新延伸模組。

支援的延伸模組

建立 Batch 集區時,目前可以安裝下列延伸模組:

您可以建立支援要求,以要求支援其他發行者和/或延伸模組類型。

建立具有延伸模組的集區

下列範例會建立使用 Azure Key Vault 延伸模組的 Linux/Windows 節點 Batch 集區。

REST API URI

 PUT https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.Batch/batchAccounts/<batchaccountName>/pools/<batchpoolName>?api-version=2021-01-01

Linux 節點的要求本文

{
  "name": "test1",
  "type": "Microsoft.Batch/batchAccounts/pools",
  "properties": {
    "vmSize": "STANDARD_D2S_V5",
    "taskSchedulingPolicy": {
      "nodeFillType": "Pack"
    },
    "deploymentConfiguration": {
      "virtualMachineConfiguration": {
        "imageReference": {
          "publisher": "Canonical",
          "offer": "ubuntu-24_04-lts",
          "sku": "server",
          "version": "latest"
        },
        "nodeAgentSkuId": "batch.node.ubuntu 24.04",
        "extensions": [
          {
            "name": "secretext",
            "type": "KeyVaultForLinux",
            "publisher": "Microsoft.Azure.KeyVault",
            "typeHandlerVersion": "3.0",
            "autoUpgradeMinorVersion": true,
            "settings": {
              "secretsManagementSettings": {
                "pollingIntervalInS": "300",
                "certificateStoreLocation": "/var/lib/waagent/Microsoft.Azure.KeyVault",
                "requireInitialSync": true,
                "observedCertificates": [
                  "https://testkvwestus2.vault.azure.net/secrets/authsecreat"
                ]
              },
              "authenticationSettings": {
                "msiEndpoint": "http://169.254.169.254/metadata/identity",
                "msiClientId": "885b1a3d-f13c-4030-afcf-9f05044d78dc"
              }
            },
            "protectedSettings": {}
          }
        ]
      }
    },
    "scaleSettings": {
      "fixedScale": {
        "targetDedicatedNodes": 1,
        "targetLowPriorityNodes": 0,
        "resizeTimeout": "PT15M"
      }
    }
  },
  "identity": {
    "type": "UserAssigned",
    "userAssignedIdentities": {
      "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ACR/providers/Microsoft.ManagedIdentity/userAssignedIdentities/testumaforpools": {}
    }
  }
}

Windows 節點的要求本文

{
    "name": "test1",
    "type": "Microsoft.Batch/batchAccounts/pools",
    "properties": {
        "vmSize": "STANDARD_D4S_V5",
        "taskSchedulingPolicy": {
            "nodeFillType": "Pack"
        },
        "deploymentConfiguration": {
            "virtualMachineConfiguration": {
                "imageReference": {
                    "publisher": "microsoftwindowsserver",
                    "offer": "windowsserver",
                    "sku": "2025-datacenter",
                    "version": "latest"
                },
                "nodeAgentSkuId": "batch.node.windows amd64",
                "extensions": [
                    {
                        "name": "secretext",
                        "type": "KeyVaultForWindows",
                        "publisher": "Microsoft.Azure.KeyVault",
                        "typeHandlerVersion": "3.0",
                        "autoUpgradeMinorVersion": true,
                        "settings": {
                            "secretsManagementSettings": {
                                "pollingIntervalInS": "300",
                                "requireInitialSync": true,
                                "observedCertificates": [
                                    {
                                        "https://testkvwestus2.vault.azure.net/secrets/authsecreat"
                                        "certificateStoreLocation": "LocalMachine",
                                        "keyExportable": true
                                    }
                                ]
                            },
                            "authenticationSettings": {
                                "msiEndpoint": "http://169.254.169.254/metadata/identity",
                                "msiClientId": "885b1a3d-f13c-4030-afcf-9f05044d78dc"
                            }
                        },
                        "protectedSettings":{}
                    }
                ]
            }
        },
        "scaleSettings": {
            "fixedScale": {
                "targetDedicatedNodes": 1,
                "targetLowPriorityNodes": 0,
                "resizeTimeout": "PT15M"
            }
        }
    },
    "identity": {
        "type": "UserAssigned",
        "userAssignedIdentities": {
            "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/ACR/providers/Microsoft.ManagedIdentity/userAssignedIdentities/testumaforpools": {}
        }
    }
}

從集區取得延伸模組資料

下列範例會從 Azure Key Vault 延伸模組擷取資料。

REST API URI

 GET https://<accountName>.<region>.batch.azure.com/pools/<poolName>/nodes/<tvmNodeName>/extensions/secretext?api-version=2010-01-01

回應本文

{
  "odata.metadata": "https://testwestus2batch.westus2.batch.azure.com/$metadata#extensions/@Element",
  "instanceView": {
    "name": "secretext",
    "statuses": [
      {
        "code": "ProvisioningState/succeeded",
        "level": 0,
        "displayStatus": "Provisioning succeeded",
        "message": "Successfully started Key Vault extension service. 2021-02-08T19:49:39Z"
      }
    ]
  },
  "vmExtension": {
    "name": "KVExtensions",
    "publisher": "Microsoft.Azure.KeyVault",
    "type": "KeyVaultForLinux",
    "typeHandlerVersion": "1.0",
    "autoUpgradeMinorVersion": true,
    "settings": "{\r\n  \"secretsManagementSettings\": {\r\n    \"pollingIntervalInS\": \"300\",\r\n    \"certificateStoreLocation\": \"/var/lib/waagent/Microsoft.Azure.KeyVault\",\r\n    \"requireInitialSync\": true,\r\n    \"observedCertificates\": [\r\n      \"https://testkvwestus2.vault.azure.net/secrets/testumi\"\r\n    ]\r\n  },\r\n  \"authenticationSettings\": {\r\n    \"msiEndpoint\": \"http://169.254.169.254/metadata/identity\",\r\n    \"msiClientId\": \"885b1a3d-f13c-4030-afcf-922f05044d78dc\"\r\n  }\r\n}"
  }
}

針對 Key Vault 延伸模組進行疑難排解

如果 Key Vault 延伸模組的設定不正確,則計算節點可能處於可用狀態。 要排除金鑰保存庫擴充失敗的問題,你可以暫時將 requireInitialSync 設定為 false,然後重新部署你的池。 當運算節點進入閒置狀態後,你可以登入該運算節點,檢查 KeyVault 擴充日誌是否有錯誤並修正設定問題。 欲了解更多資訊,請造訪以下 Key Vault 擴充文件連結。

應用程式健康擴充功能的考慮事項

節點上執行的批次節點代理總是會啟動一個 HTTP 伺服器,回傳代理的健康狀態。 此 HTTP 伺服器監聽本機 IP 位址 127.0.0.1 及連接埠 29879。 其一律會傳回 200 狀態,但回應本文狀況良好或狀況不良。 任何其他回應(或缺乏回應)都被視為「未知」狀態。 此設置符合官方「Application Health extension」文件中提供「全面健康狀態」的 HTTP 伺服器運行指引。

如果您設定自己的健康情況伺服器,請確定 HTTP 伺服器在唯一的連接埠監聽。 你的健康伺服器應該查詢批次節點代理伺服器,並融合你的健康訊號以生成綜合健康結果。 否則你可能會得到一個「健康」的節點,但其批次代理卻無法正常運作。

後續步驟