如何在 Azure Service Fabric 集群中为无状态服务 运行 提供文件共享?

How to provide a file share for a stateless service running in Azure Service Fabric cluster?

我正在部署具有文件上传方法的无状态 API。 API 消费者上传文件,文件存储在文件系统(网络共享)中,元数据存储在数据库中。

但是,当它部署到Azure环境时,我真的不知道如何配置该服务才能访问支持SMB的Azure Files。 Service Fabric Mesh 似乎支持文件卷驱动程序,但我没有使用服务网格。只是很好的旧 Service Fabric。

那么您能否推荐一种无需重写我的文件的方法 i/o 以便它在 Azure 中与文件存储一起工作。

谢谢

您可以script 装载到文件共享。使用服务主体来访问存储凭据,或将它们放入配置中。 运行 脚本作为服务的 setup entry point。 确保脚本运行 idempotent.

$resourceGroupName = "<your-resource-group-name>"
$storageAccountName = "<your-storage-account-name>"

# These commands require you to be logged into your Azure account, run Login-AzAccount if you haven't
# already logged in.
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$storageAccountKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName

# The cmdkey utility is a command-line (rather than PowerShell) tool. We use Invoke-Expression to allow us to 
# consume the appropriate values from the storage account variables. The value given to the add parameter of the
# cmdkey utility is the host address for the storage account, <storage-account>.file.core.windows.net for Azure 
# Public Regions. $storageAccount.Context.FileEndpoint is used because non-Public Azure regions, such as sovereign 
# clouds or Azure Stack deployments, will have different hosts for Azure file shares (and other storage resources).
Invoke-Expression -Command ("cmdkey /add:$([System.Uri]::new($storageAccount.Context.FileEndPoint).Host) " + `
    "/user:AZURE$($storageAccount.StorageAccountName) /pass:$($storageAccountKeys[0].Value)")