重要说明
本页包含使用 Kubernetes 部署清单(目前为预览版)管理 Azure IoT 操作组件的说明。 此功能存在若干限制,不应该用于生产工作负载。
有关适用于 Beta 版、预览版或尚未正式发布的 Azure 功能的法律条款,请参阅 Microsoft Azure 预览版补充使用条款。
若要在 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 。 |
身份验证方法 |
用于身份验证的方法。 选择系统分配的托管标识或用户分配的托管标识。 |
客户端 ID |
用户分配的托管标识的客户端 ID。 如果使用的是“用户分配的托管标识”,则为必需。 |
租户 ID |
用户分配的托管标识的租户 ID。 如果使用的是“用户分配的托管标识”,则为必需。 |
选择“应用”来预配终结点。
创建或替换
使用 az iot ops 数据流终结点 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 数据流终结点 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 数据流终结点 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>"
}
}
下面是一个示例命令,用于创建新的 Azure 数据资源管理器数据流终结点,名为 adx-endpoint
:
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 门户中,转到数据资源管理器数据库(而不是群集),在“概述”下,依次选择“权限”“添加”,然后选择适当的角色。>
- 搜索用户分配的托管标识的名称。
- 选择“选择”。
然后,使用用户分配的托管标识设置配置数据流终结点。
在操作体验数据流终结点设置页中,选择“基本”选项卡,然后选择“身份验证方法”“用户分配的托管标识”。>
在相应的字段中输入用户分配的托管标识客户端 ID 和租户 ID。
创建或替换
使用 az iot ops 数据流终结点 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
参数分别指定用户分配的托管标识客户端 ID、租户 ID 和作用域。
下面是用于创建或替换名为 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>"
}
}
下面是一个示例命令,用于创建新的 Azure 数据资源管理器数据流终结点,名为 adx-endpoint
:
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
后续步骤
若要了解有关数据流的详细信息,请参阅创建数据流。