重要事項
本頁包含使用 Kubernetes 部署清單管理 Azure IoT Operations 元件的說明,該清單已在預覽中。 此功能以數項限制提供,不應用於生產工作負載。
請參閱 Microsoft Azure 預覽版增補使用規定,以了解適用於 Azure 功能 (搶鮮版 (Beta)、預覽版,或尚未正式發行的版本) 的法律條款。
若要將資料傳送至 Azure IoT 操作中的 Azure 資料總管,您可以設定資料流端點。 此設定可讓您指定目的地端點、驗證方法、資料表和其他設定。
先決條件
-
Azure IoT 操作的執行個體
-
Azure 資料總管叢集。 遵循快速入門:建立 Azure 資料總管叢集和資料庫中的完整叢集步驟。 「免費叢集」選項不適用於此案例。
建立 Azure 資料總管資料庫
在 Azure 入口網站中,在 Azure 資料總管「完整」叢集中建立資料庫。
在資料庫中為資料建立資料表。 您可以使用 Azure 入口網站並手動建立資料行,也可以在查詢索引標籤中使用 KQL。例如,若要建立範例控溫器資料的資料表,請執行下列命令:
.create table thermostat (
externalAssetId: string,
assetName: string,
CurrentTemperature: real,
Pressure: real,
MqttTopic: string,
Timestamp: datetime
)
在您的資料表和資料庫上啟用串流擷取。 在 [查詢] 索引標籤中,執行下列命令,並以您的資料庫名稱取代 <DATABASE_NAME>:
.alter database ['<DATABASE_NAME>'] policy streamingingestion enable
或者,啟用整個叢集上的串流擷取。 請參閱在現有的叢集上啟用串流擷取。
將權限指派給受控識別
若要設定 Azure 資料總管的資料流端點,建議您使用使用者指派或系統指派的受控識別。 這種方法是安全的,而且不需要手動管理認證。
建立 Azure 資料總管資料庫之後,您必須將角色指派給 Azure IoT 操作受控識別,以授與寫入資料庫的權限。
如果使用系統指派的受控識別,請在 Azure 入口網站中移至您的 Azure IoT 操作執行個體,然後選取 [概觀]。 複製 Azure IoT 操作Arc 延伸模組之後所列的延伸模組名稱。 例如,azure-iot-operations-xxxx7。 使用 Azure IoT 操作Arc 延伸模組的相同名稱,即可找到系統指派的受控識別。
- 在 Azure 資料總管資料庫 (非叢集) 的 [概觀] 下,選取 [權限]>[新增],然後選取 [擷取器] 作為角色。 這可讓受控識別具備寫入 Azure 資料總管資料庫的必要權限。 若要深入了解,請參閱角色型存取控制。
- 搜尋針對雲端連線所設定的使用者指派受控識別或系統指派的受控識別的名稱。 例如,azure-iot-operations-xxxx7。
- 然後,選取 [選取]。
建立 Azure 資料總管的資料流端點
在操作體驗中,選取 [資料流端點] 索引標籤。
在 [建立新的資料流端點] 下,選取 [Azure 資料總管]>[新增]。
輸入端點的下列設定:
| 設定 |
描述 |
| 名稱 |
資料流端點的名稱。 |
| 主辦人 |
Azure 資料總管端點的主機名稱,格式為 <cluster>.<region>.kusto.windows.net。 |
| 驗證方法 |
用於驗證的方法。 選擇系統指派的受控識別或使用者指派的受控識別。 |
| 用戶端識別碼 |
使用者指派之受控識別的用戶端識別碼。 如果使用「使用者指派的受控識別」,則為必要項目。 |
| 租用戶識別碼 |
使用者指派之受控識別的租用戶識別碼。 如果使用「使用者指派的受控識別」,則為必要項目。 |
選取 [套用] 以佈建端點。
建立或取代
使用 az iot ops dataflow endpoint create adls 命令來建立或取代 Azure 數據總管數據流端點。
az iot ops dataflow endpoint create adx --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --host <ClusterName> --database <DatabaseName>
參數 --host 是 Azure 資料總管叢集的主機名,格式為 <cluster>.<region>.kusto.windows.net。 參數 --database 是 Azure 數據總管資料庫的名稱。
以下是建立或取代名為 adx-endpoint 的 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint create adx --resource-group myResourceGroup --instance myAioInstance --name adx-endpoint --host myadxcluster.eastus.kusto.windows.net --database mydatabase
建立或變更
使用 az iot ops dataflow endpoint apply 命令來建立或變更 Azure 數據總管數據流端點。
az iot ops dataflow endpoint apply --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --config-file <ConfigFilePathAndName>
參數 --config-file 是 JSON 組態檔的路徑和檔名,其中包含資源屬性。
在此範例中,假設名為 adx-endpoint.json 的組態檔,其中包含儲存在使用者主目錄中的下列內容:
{
"endpointType": "DataExplorer",
"dataExplorerSettings": {
"authentication": {
"method": "SystemAssignedManagedIdentity",
"systemAssignedManagedIdentitySettings": {}
},
"batching": {
"latencySeconds": 60,
"maxMessages": 100000
},
"host": "https://<cluster>.<region>.kusto.windows.net",
"database": "<DatabaseName>"
}
}
以下是建立名為 adx-endpoint 的新 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint apply --resource-group myResourceGroupName --instance myAioInstanceName --name adx-endpoint --config-file ~/adx-endpoint.json
使用下列內容建立 Bicep .bicep 檔案。
param aioInstanceName string = '<AIO_INSTANCE_NAME>'
param customLocationName string = '<CUSTOM_LOCATION_NAME>'
param endpointName string = '<ENDPOINT_NAME>'
param hostName string = 'https://<cluster>.<region>.kusto.windows.net'
param databaseName string = '<DATABASE_NAME>'
resource aioInstance 'Microsoft.IoTOperations/instances@2024-11-01' existing = {
name: aioInstanceName
}
resource customLocation 'Microsoft.ExtendedLocation/customLocations@2021-08-31-preview' existing = {
name: customLocationName
}
resource adxEndpoint 'Microsoft.IoTOperations/instances/dataflowEndpoints@2024-11-01' = {
parent: aioInstance
name: endpointName
extendedLocation: {
name: customLocation.id
type: 'CustomLocation'
}
properties: {
endpointType: 'DataExplorer'
dataExplorerSettings: {
host: hostName
database: databaseName
authentication: {
// See available authentication methods section for method types
// method: <METHOD_TYPE>
}
}
}
}
然後,透過 Azure CLI 進行部署。
az deployment group create --resource-group <RESOURCE_GROUP> --template-file <FILE>.bicep
使用下列內容建立 Kubernetes 資訊清單 .yaml 檔案。
apiVersion: connectivity.iotoperations.azure.com/v1
kind: DataflowEndpoint
metadata:
name: <ENDPOINT_NAME>
namespace: azure-iot-operations
spec:
endpointType: DataExplorer
dataExplorerSettings:
host: 'https://<cluster>.<region>.kusto.windows.net'
database: <DATABASE_NAME>
authentication:
# See available authentication methods section for method types
# method: <METHOD_TYPE>
然後將資訊清單檔套用至 Kubernetes 叢集。
kubectl apply -f <FILE>.yaml
可用的驗證方法
下列驗證方法適用於 Azure 資料總管端點。
系統指派的受控識別
設定資料流端點之前,請先將角色指派給 Azure IoT 操作受控識別,以授與寫入 Azure 資料總管資料庫的權限:
- 在 Azure 入口網站中,移至您的 Azure IoT 操作執行個體,然後選取 [概觀]。
- 複製 Azure IoT 操作Arc 延伸模組之後所列的延伸模組名稱。 例如,azure-iot-operations-xxxx7。
- 移至 Azure 資料總管資料庫 (非叢集),在 [概觀] 底下,選取 [權限]>[新增],然後選取適當的角色。
- 搜尋系統指派的受控識別名稱。 例如,azure-iot-operations-xxxx7。
- 選取 [選取] 。
然後,使用系統指派的受控識別設定來設定資料流端點。
在 [操作體驗資料流端點設定] 頁面中,選取 [基本] 索引標籤,然後選擇 [驗證方法]>[系統指派的受控識別]。
建立或取代
使用 az iot ops dataflow endpoint create adls 命令來建立或取代 Azure 數據總管數據流端點。
az iot ops dataflow endpoint create adx --auth-type SystemAssignedManagedIdentity --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --host <ClusterName> --database <DatabaseName>
參數 --host 是 Azure 資料總管叢集的主機名,格式為 <cluster>.<region>.kusto.windows.net。 參數 --database 是 Azure 數據總管資料庫的名稱。
以下是建立或取代名為 adx-endpoint 的 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint create adx --auth-type SystemAssignedManagedIdentity --resource-group myResourceGroup --instance myAioInstance --name adx-endpoint --host myadxcluster.eastus.kusto.windows.net --database mydatabase
建立或變更
使用 az iot ops dataflow endpoint apply 命令來建立或變更 Azure 數據總管數據流端點。
az iot ops dataflow endpoint apply --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --config-file <ConfigFilePathAndName>
參數 --config-file 是 JSON 組態檔的路徑和檔名,其中包含資源屬性。
在此範例中,假設名為 adx-endpoint.json 的組態檔,其中包含儲存在使用者主目錄中的下列內容:
{
"endpointType": "DataExplorer",
"dataExplorerSettings": {
"authentication": {
"method": "SystemAssignedManagedIdentity",
"systemAssignedManagedIdentitySettings": {}
},
"batching": {
"latencySeconds": 60,
"maxMessages": 100000
},
"host": "https://<cluster>.<region>.kusto.windows.net",
"database": "<DatabaseName>"
}
}
以下是建立名為 adx-endpoint 的新 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint apply --resource-group myResourceGroupName --instance myAioInstanceName --name adx-endpoint --config-file ~/adx-endpoint.json
dataExplorerSettings: {
authentication: {
method: 'SystemAssignedManagedIdentity'
systemAssignedManagedIdentitySettings: {}
}
}
dataExplorerSettings:
authentication:
method: SystemAssignedManagedIdentity
systemAssignedManagedIdentitySettings: {}
如果您需要覆寫系統指派的受控識別對象,您可以指定 audience 設定。
在大部分情況下,您不需要指定其他設定。 此設定會建立具有預設對象 https://api.kusto.windows.net 的受控識別。
建立或取代
使用 az iot ops dataflow endpoint create adls 命令,以系統指派的受控識別來建立或取代 Azure 數據總管數據流端點。
az iot ops dataflow endpoint create adx --auth-type SystemAssignedManagedIdentity --audience https://<cluster>.<region>.kusto.windows.net --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --host <cluster>.<region>.kusto.windows.net --database <DatabaseName>
參數 --host 是 Azure 資料總管叢集的主機名,格式為 <cluster>.<region>.kusto.windows.net。 參數 --database 是 Azure 數據總管資料庫的名稱。
--audience 參數是受控識別針對 Azure 資料總管進行驗證的對象 URL。
以下是建立或取代名為 adx-endpoint的 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint create adx --auth-type SystemAssignedManagedIdentity --audience https://myadxcluster.eastus.kusto.windows.net --resource-group myResourceGroup --instance myAioInstance --name adx-endpoint --host myadxcluster.eastus.kusto.windows.net --database mydatabase
建立或變更
使用 az iot ops dataflow endpoint apply 命令來建立或變更具有系統指派受控識別的 Azure 數據總管數據流端點。
az iot ops dataflow endpoint apply --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --config-file <ConfigFilePathAndName>
參數 --config-file 是 JSON 組態檔的路徑和檔名,其中包含資源屬性。
在此範例中,假設名為 adx-endpoint.json 的組態檔,其中包含儲存在使用者主目錄中的下列內容:
{
"endpointType": "DataExplorer",
"dataExplorerSettings": {
"authentication": {
"method": "SystemAssignedManagedIdentity",
"systemAssignedManagedIdentitySettings": {
"audience": "https://<cluster>.<region>.kusto.windows.net"
}
},
"batching": {
"latencySeconds": 60,
"maxMessages": 100000
},
"host": "https://<cluster>.<region>.kusto.windows.net",
"database": "<DatabaseName>"
}
}
以下是建立名為 adx-endpoint的新 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint apply --resource-group myResourceGroupName --instance myAioInstanceName --name adx-endpoint --config-file ~/adx-endpoint.json
dataExplorerSettings: {
authentication: {
method: 'SystemAssignedManagedIdentity'
systemAssignedManagedIdentitySettings: {
audience: 'https://<AUDIENCE_URL>'
}
}
}
dataExplorerSettings:
authentication:
method: SystemAssignedManagedIdentity
systemAssignedManagedIdentitySettings:
audience: https://<AUDIENCE_URL>
使用者指派的受控識別
若要將使用者指派的受控識別用於驗證,您必須先部署已啟用安全設定的 Azure IoT 操作。 然後,您必須為雲端連線設定使用者指派的受控識別。 若要深入了解,請參閱在 Azure IoT 操作部署中啟用安全設定。
設定資料流端點之前,請先將角色指派給使用者指派的受控識別,以授與寫入 Azure 資料總管資料庫的權限:
- 在 Azure 入口網站中,移至 Azure 資料總管資料庫 (非叢集),在 [概觀] 底下,選取 [權限]>[新增],然後選取適當的角色。
- 搜尋使用者指派的受控識別名稱。
- 選取 [選取] 。
然後,使用使用者指派的受控識別設定來設定資料流端點。
在 [操作體驗資料流端點設定] 頁面中,選取 [基本] 索引標籤,然後選擇 [驗證方法]>[使用者指派的受控識別]。
在適當的欄位中輸入使用者指派的受控識別用戶端識別碼和租用戶識別碼。
建立或取代
使用 az iot ops dataflow endpoint create adls 命令,以使用者指派的受控識別來建立或取代 Azure 數據總管數據流端點。
az iot ops dataflow endpoint create adx --auth-type UserAssignedManagedIdentity --client-id <ClientId> --tenant-id <TenantId> --scope <Scope> --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --host <cluster>.<region>.kusto.windows.net --database <DatabaseName>
參數 --host 是 Azure 資料總管叢集的主機名,格式為 <cluster>.<region>.kusto.windows.net。 參數 --database 是 Azure 數據總管資料庫的名稱。 參數 --auth-type 會指定驗證方法,在此案例中為 UserAssignedManagedIdentity 。
--client-id、 --tenant-id和 --scope 參數分別指定使用者指派的受控識別用戶端標識碼、租使用者標識碼和範圍。
以下是建立或取代名為 adx-endpoint的 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint create adx --auth-type UserAssignedManagedIdentity --client-id ClientId --tenant-id TenantId --scope https://api.kusto.windows.net/.default --resource-group myResourceGroup --instance myAioInstance --name adx-endpoint --host myadxcluster.eastus.kusto.windows.net --database mydatabase
建立或變更
使用 az iot ops dataflow endpoint apply 命令來建立或變更具有使用者指派受控識別的 Azure 數據總管數據流端點。
az iot ops dataflow endpoint apply --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --config-file <ConfigFilePathAndName>
參數 --config-file 是 JSON 組態檔的路徑和檔名,其中包含資源屬性。
在此範例中,假設名為 adx-endpoint.json 的組態檔,其中包含儲存在使用者主目錄中的下列內容:
{
"endpointType": "DataExplorer",
"dataExplorerSettings": {
"authentication": {
"method": "UserAssignedManagedIdentity",
"userAssignedManagedIdentitySettings": {
"clientId": "<ClientId>",
"scope": "<Scope>",
"tenantId": "<TenantId>"
}
},
"batching": {
"latencySeconds": 60,
"maxMessages": 100000
},
"host": "https://<cluster>.<region>.kusto.windows.net",
"database": "<DatabaseName>"
}
}
以下是建立名為 adx-endpoint的新 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint apply --resource-group myResourceGroupName --instance myAioInstanceName --name adx-endpoint --config-file ~/adx-endpoint.json
dataExplorerSettings: {
authentication: {
method: 'UserAssignedManagedIdentity'
userAssignedManagedIdentitySettings: {
clientId: '<ID>'
tenantId: '<ID>'
// Optional, defaults to 'https://api.kusto.windows.net/.default'
// scope: 'https://<SCOPE_URL>'
}
}
}
dataExplorerSettings:
authentication:
method: UserAssignedManagedIdentity
userAssignedManagedIdentitySettings:
clientId: <ID>
tenantId: <ID>
# Optional, defaults to 'https://api.kusto.windows.net/.default'
# scope: https://<SCOPE_URL>
在這裡,範圍是選擇性的,預設為 https://api.kusto.windows.net/.default。 如果您需要覆寫預設範圍,請透過 Bicep 或 Kubernetes 指定 scope 設定。
進階設定
您可以設定 Azure 資料總管端點的進階設定,例如批次處理延遲和訊息計數。
使用 batching 設定來設定訊息數目上限,以及訊息傳送至目的地之前的最大延遲。 當您想要針對網路頻寬進行最佳化,並減少對目的地的要求數目時,此設定很有用。
| 欄位 |
描述 |
必要 |
latencySeconds |
將訊息傳送至目的地之前要等候的最大秒數。 預設值為 60 秒。 |
否 |
maxMessages |
要傳送至目的地的訊息數目上限。 預設值為 100000 則訊息。 |
否 |
例如,若要將訊息數目上限設定為 1000,以及延遲上限為 100 秒,請使用下列設定:
在操作體驗中,選取資料流端點的 [進階] 索引標籤。
使用 az iot ops dataflow endpoint apply 命令來建立或變更具有進階設定的 Azure 數據總管數據流端點。
az iot ops dataflow endpoint apply --resource-group <ResourceGroupName> --instance <AioInstanceName> --name <EndpointName> --config-file <ConfigFilePathAndName>
參數 --config-file 是 JSON 組態檔的路徑和檔名,其中包含資源屬性。
在此範例中,假設名為 adx-endpoint.json 的組態檔,其中包含儲存在使用者主目錄中的下列內容:
{
"endpointType": "DataExplorer",
"dataExplorerSettings": {
"authentication": {
"method": "SystemAssignedManagedIdentity",
"systemAssignedManagedIdentitySettings": {}
},
"batching": {
"latencySeconds": 100,
"maxMessages": 1000
},
"host": "https://<cluster>.<region>.kusto.windows.net",
"database": "<DatabaseName>"
}
}
以下是建立名為 adx-endpoint 的新 Azure 數據總管數據流端點的範例命令:
az iot ops dataflow endpoint apply --resource-group myResourceGroupName --instance myAioInstanceName --name adx-endpoint --config-file ~/adx-endpoint.json
dataExplorerSettings: {
batching: {
latencySeconds: 100
maxMessages: 1000
}
}
dataExplorerSettings:
batching:
latencySeconds: 100
maxMessages: 1000
後續步驟
若要深入了解資料流,請參閱建立資料流。