适用于 Service Fabric 的 Azure 文件存储卷驱动程序Azure Files volume driver for Service Fabric

Azure 文件存储卷驱动程序是一个 Docker 卷插件,可为 Docker 容器提供基于 Azure 文件存储的卷。The Azure Files volume driver is a Docker volume plugin that provides Azure Files based volumes for Docker containers. 它将打包为 Service Fabric 应用程序,可以部署到 Service Fabric 群集以为群集内的其他 Service Fabric 容器应用程序提供卷。It is packaged as a Service Fabric application that can be deployed to a Service Fabric cluster to provide volumes for other Service Fabric container applications within the cluster.

备注

Azure 文件存储卷插件版本6.5.661.9590 已正式发布。Version 6.5.661.9590 of the Azure Files volume plugin has been released for general availability.

必备条件Prerequisites

  • Windows 版 Azure 文件卷插件仅适用于 Windows Server 1709 版Windows 10 1709 版或更高版本的操作系统。The Windows version of the Azure Files volume plugin works on Windows Server version 1709, Windows 10 version 1709 or later operating systems only.

  • Linux 版 Azure 文件卷插件适用于 Service Fabric 支持的所有操作系统版本。The Linux version of the Azure Files volume plugin works on all operating system versions supported by Service Fabric.

  • Azure 文件卷插件仅适用于 Service Fabric 6.2 和更高版本。The Azure Files volume plugin only works on Service Fabric version 6.2 and newer.

  • 按照 Azure 文件文档中的说明,为要用作卷的 Service Fabric 容器应用程序创建文件共享。Follow the instructions in the Azure Files documentation to create a file share for the Service Fabric container application to use as volume.

  • 需要具有 Service Fabric 模块的 Powershell 或安装 SFCTLYou will need Powershell with the Service Fabric module or SFCTL installed.

  • 如果使用的是 Hyper-V 容器,则需要在 Azure 资源管理器模板(Azure 群集)或 ClusterConfig.json(独立群集)的 ClusterManifest(本地群集)或 fabricSettings 节中添加以下代码片段。If you are using Hyper-V containers, the following snippets need to be added in the ClusterManifest (local cluster) or fabricSettings section in your Azure Resource Manager template (Azure cluster) or ClusterConfig.json (standalone cluster).

在 ClusterManifest 中,需要在“Hosting”节中添加以下内容。In the ClusterManifest, the following needs to be added in the Hosting section. 在此示例中,卷名为 sfazurefile,它在群集上侦听的端口为 19100In this example, the volume name is sfazurefile and the port it listens to on the cluster is 19100. 请将它们替换为你的群集的正确值。Replace them with the correct values for your cluster.

<Section Name="Hosting">
  <Parameter Name="VolumePluginPorts" Value="sfazurefile:19100" />
</Section>

在 Azure 资源管理器模板(适用于 Azure 部署)或 ClusterConfig.json(适用于独立部署)的 fabricSettings 节中,需要添加以下代码片段。In the fabricSettings section in your Azure Resource Manager template (for Azure deployments) or ClusterConfig.json (for standalone deployments), the following snippet needs to be added. 同样,将卷名和端口值替换为你自己的值。Again, replace the volume name and port values with your own.

"fabricSettings": [
  {
    "name": "Hosting",
    "parameters": [
      {
          "name": "VolumePluginPorts",
          "value": "sfazurefile:19100"
      }
    ]
  }
]

使用 Service Fabric Azure 文件存储卷驱动程序部署示例应用程序Deploy a sample application using Service Fabric Azure Files volume driver

如果群集基于 Azure,建议使用 Azure 资源管理器应用程序资源模型将应用程序部署到群集,既可方便使用,也有助于迁移到将基础结构作为代码进行维护的模型。If your cluster is based in Azure, we recommend deploying applications to it using the Azure Resource Manager application resource model for ease of use and to help move towards the model of maintaining infrastructure as code. 此方法不需跟踪 Azure 文件存储卷驱动程序的应用版本。This approach eliminates the need to keep track of the app version for the Azure Files volume driver. 另外,这样还可以为每个支持的 OS 保留单独的 Azure 资源管理器模板。It also enables you to maintain separate Azure Resource Manager templates for each supported OS. 脚本假设你部署的是最新版 Azure 文件存储应用程序,而且,脚本获取的是 OS 类型、群集订阅 ID 和资源组的参数。The script assumes you are deploying the latest version of the Azure Files application and takes parameters for OS type, cluster subscription ID, and resource group. 可从 Service Fabric 下载站点下载该脚本。You can download the script from the Service Fabric download site. 请注意,这会自动将 ListenPort(Azure 文件存储卷插件从 Docker 守护程序侦听请求的端口)设置为 19100。Note that this automatically sets the ListenPort, which is the port on which the Azure Files volume plugin listens for requests from the Docker daemon, to 19100. 可以通过添加名为“listenPort”的参数来更改它。You can change it by adding parameter named "listenPort". 请确保此端口不与群集或应用程序使用的任何其他端口冲突。Ensure that the port does not conflict with any other port that the cluster or your applications uses.

用于 Windows 的 Azure 资源管理器部署命令:Azure Resource Manager deployment command for Windows:

.\DeployAzureFilesVolumeDriver.ps1 -subscriptionId [subscriptionId] -resourceGroupName [resourceGroupName] -clusterName [clusterName] -windows

用于 Linux 的 Azure 资源管理器部署命令:Azure Resource Manager deployment command for Linux:

.\DeployAzureFilesVolumeDriver.ps1 -subscriptionId [subscriptionId] -resourceGroupName [resourceGroupName] -clusterName [clusterName] -linux

成功运行脚本以后,即可跳到配置应用程序部分。Once you've successfully run the script, you can skip to the configuring your application section.

针对独立群集的手动部署Manual deployment for standalone clusters

可以从 Service Fabric 下载站点下载为容器提供卷的 Service Fabric 应用程序。The Service Fabric application that provides the volumes for your containers can be downloaded from the Service Fabric download site. 可以通过 PowerShellCLIFabricClient API 将应用程序部署到群集。The application can be deployed to the cluster via PowerShell, CLI or FabricClient APIs.

  1. 使用命令行,将目录更改为已下载的应用程序包的根目录。Using the command line, change directory to the root directory of the downloaded application package.

    cd .\AzureFilesVolume\
    
    cd ~/AzureFilesVolume
    
  2. 接下来,使用 [ApplicationPackagePath] 和 [ImageStoreConnectionString] 的相应值将应用程序包复制到映像存储区:Next, copy the application package to the image store with the appropriate values for [ApplicationPackagePath] and [ImageStoreConnectionString]:

    Copy-ServiceFabricApplicationPackage -ApplicationPackagePath [ApplicationPackagePath] -ImageStoreConnectionString [ImageStoreConnectionString] -ApplicationPackagePathInImageStore AzureFilesVolumePlugin
    
    sfctl cluster select --endpoint https://testcluster.chinanorth.cloudapp.chinacloudapi.cn:19080 --pem test.pem --no-verify
    sfctl application upload --path [ApplicationPackagePath] --show-progress
    
  3. 注册应用程序类型Register the application type

    Register-ServiceFabricApplicationType -ApplicationPathInImageStore AzureFilesVolumePlugin
    
    sfctl application provision --application-type-build-path [ApplicationPackagePath]
    
  4. 创建应用程序,密切注意 ListenPort 应用程序参数值。Create the application, paying close attention to the ListenPort application parameter value. 该值是 Azure 文件存储卷插件从 Docker 守护程序侦听请求的端口。This value is the port on which the Azure Files volume plugin listens for requests from the Docker daemon. 请确保提供给应用程序的端口与 ClusterManifest 中的 VolumePluginPorts 匹配,并且不与群集或应用程序使用的任何其他端口冲突。Ensure that the port provided to the application matches the VolumePluginPorts in the ClusterManifest and does not conflict with any other port that the cluster or your applications uses.

    New-ServiceFabricApplication -ApplicationName fabric:/AzureFilesVolumePluginApp -ApplicationTypeName AzureFilesVolumePluginType -ApplicationTypeVersion 6.5.661.9590   -ApplicationParameter @{ListenPort='19100'}
    
    sfctl application create --app-name fabric:/AzureFilesVolumePluginApp --app-type AzureFilesVolumePluginType --app-version 6.5.661.9590  --parameter '{"ListenPort":"19100"}'
    

备注

Windows Server 2016 Datacenter 不支持向容器装载映射 SMB (仅 Windows Server 1709 版支持)。Windows Server 2016 Datacenter does not support mapping SMB mounts to containers (That is only supported on Windows Server version 1709). 这样可以阻止网络卷映射和 Azure 文件卷驱动程序出现在早于 1709 的版本上。This constraint prevents network volume mapping and Azure Files volume drivers on versions older than 1709.

在本地开发群集上部署应用程序Deploy the application on a local development cluster

执行上面的步骤 1-3。Follow steps 1-3 from the above.

Azure 文件卷插件应用程序的默认服务实例计数为 -1,这表示有一个服务实例会部署到群集中的每个节点。The default service instance count for the Azure Files volume plugin application is -1, which means that there is an instance of the service deployed to each node in the cluster. 但在本地开发群集上部署 Azure 文件卷插件应用程序时,服务实例计数应指定为 1。However, when deploying the Azure Files volume plugin application on a local development cluster, the service instance count should be specified as 1. 可以通过 InstanceCount 应用程序参数完成此操作 。This can be done via the InstanceCount application parameter. 因此,在本地开发群集上创建 Azure 文件存储卷插件应用程序的命令为:Therefore, the command for creating the Azure Files volume plugin application on a local development cluster is:

New-ServiceFabricApplication -ApplicationName fabric:/AzureFilesVolumePluginApp -ApplicationTypeName AzureFilesVolumePluginType -ApplicationTypeVersion 6.5.661.9590  -ApplicationParameter @{ListenPort='19100';InstanceCount='1'}
sfctl application create --app-name fabric:/AzureFilesVolumePluginApp --app-type AzureFilesVolumePluginType --app-version 6.5.661.9590  --parameter '{"ListenPort": "19100","InstanceCount": "1"}'

配置应用程序以使用卷Configure your applications to use the volume

以下代码片段演示如何在应用程序清单文件中指定基于 Azure 文件存储的卷。The following snippet shows how an Azure Files based volume can be specified in the application manifest file of your application. 相关特定元素为 Volume 标记 :The specific element of interest is the Volume tag:

?xml version="1.0" encoding="UTF-8"?>
<ApplicationManifest ApplicationTypeName="WinNodeJsApp" ApplicationTypeVersion="1.0" xmlns="http://schemas.microsoft.com/2011/01/fabric" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">
    <Description>Calculator Application</Description>
    <Parameters>
      <Parameter Name="ServiceInstanceCount" DefaultValue="3"></Parameter>
      <Parameter Name="MyCpuShares" DefaultValue="3"></Parameter>
      <Parameter Name="MyStorageVar" DefaultValue="c:\tmp"></Parameter>
    </Parameters>
    <ServiceManifestImport>
        <ServiceManifestRef ServiceManifestName="NodeServicePackage" ServiceManifestVersion="1.0"/>
     <Policies>
       <ContainerHostPolicies CodePackageRef="NodeService.Code" Isolation="hyperv">
            <PortBinding ContainerPort="8905" EndpointRef="Endpoint1"/>
            <RepositoryCredentials PasswordEncrypted="false" Password="****" AccountName="test"/>
            <Volume Source="azfiles" Destination="c:\VolumeTest\Data" Driver="sfazurefile">
                <DriverOption Name="shareName" Value="" />
                <DriverOption Name="storageAccountName" Value="" />
                <DriverOption Name="storageAccountKey" Value="" />
                <DriverOption Name="storageAccountFQDN" Value="" />
            </Volume>
       </ContainerHostPolicies>
   </Policies>
    </ServiceManifestImport>
    <ServiceTemplates>
        <StatelessService ServiceTypeName="StatelessNodeService" InstanceCount="5">
            <SingletonPartition></SingletonPartition>
        </StatelessService>
    </ServiceTemplates>
</ApplicationManifest>

Azure 文件卷插件的驱动程序名称为 sfazurefile 。The driver name for the Azure Files volume plugin is sfazurefile. 此值为应用程序清单中 Volume 标记元素的 Driver 属性而设置 。This value is set for the Driver attribute of the Volume tag element in the application manifest.

在上述代码片段的 Volume 标记中,Azure 文件存储卷插件需要以下属性 :In the Volume tag in the snippet above, the Azure Files volume plugin requires the following attributes:

  • Source - 这是卷的名称。Source - This is the name of the volume. 用户可以为其卷选取任何名称。The user can pick any name for their volume.
  • Destination - 此属性是卷在运行的容器中映射到的位置。Destination - This attribute is the location that the volume is mapped to within the running container. 因此,目标不能为容器中的现有位置Thus, your destination can't be a location that already exists within your container

如上文代码段中的 DriverOption 元素所示,Azure 文件卷插件支持以下驱动程序选项 :As shown in the DriverOption elements in the snippet above, the Azure Files volume plugin supports the following driver options:

  • shareName - 为容器提供卷的“Azure 文件”文件共享的名称。shareName - Name of the Azure Files file share that provides the volume for the container.

  • storageAccountName - 包含“Azure 文件”文件共享的 Azure 存储帐户的名称。storageAccountName - Name of the Azure storage account that contains the Azure Files file share.

  • storageAccountKey - 包含“Azure 文件”文件共享的 Azure 存储帐户的访问密钥。storageAccountKey - Access key for the Azure storage account that contains the Azure Files file share.

  • storageAccountFQDN - 与存储帐户关联的域名。storageAccountFQDN - Domain name associated with the storage account. 如果未指定 storageAccountFQDN,则将使用默认后缀 (.file.core.chinacloudapi.cn) 与 storageAccountName 一起形成域名。If storageAccountFQDN is not specified, domain name will be formed by using the default suffix(.file.core.chinacloudapi.cn) with the storageAccountName.

    - Example1: 
        <DriverOption Name="shareName" Value="myshare1" />
        <DriverOption Name="storageAccountName" Value="myaccount1" />
        <DriverOption Name="storageAccountKey" Value="mykey1" />
        <!-- storageAccountFQDN will be "myaccount1.file.core.chinacloudapi.cn" -->
    
    - Example2: 
        <DriverOption Name="shareName" Value="myshare2" />
        <DriverOption Name="storageAccountName" Value="myaccount2" />
        <DriverOption Name="storageAccountKey" Value="mykey2" />
        <DriverOption Name="storageAccountFQDN" Value="myaccount2.file.core.chinacloudapi.cn" />
    

使用自己的卷或日志记录驱动程序Using your own volume or logging driver

Service Fabric 还允许使用自己的自定义日志记录驱动程序。Service Fabric also allows the usage of your own custom volume or logging drivers. 如果群集上未安装 Docker 卷/日志记录驱动程序,可使用 RDP/SSH 协议手动安装。If the Docker volume/logging driver is not installed on the cluster, you can install it manually by using the RDP/SSH protocols. 还可使用这些协议,通过虚拟机规模集启动脚本SetupEntryPoint 脚本执行安装操作。You can perform the install with these protocols through a virtual machine scale set start-up script or an SetupEntryPoint script.

以下是安装 Azure 的 Docker 卷驱动程序的一个脚本实例:An example of the script to install the Docker volume driver for Azure is as follows:

docker plugin install --alias azure --grant-all-permissions docker4x/cloudstor:17.09.0-ce-azure1  \
    CLOUD_PLATFORM=AZURE \
    AZURE_STORAGE_ACCOUNT="[MY-STORAGE-ACCOUNT-NAME]" \
    AZURE_STORAGE_ACCOUNT_KEY="[MY-STORAGE-ACCOUNT-KEY]" \
    AZURE_STORAGE_ENDPOINT="core.chinacloudapi.cn" \
    DEBUG=1

在应用程序中,要使用已安装的卷或日志记录驱动程序,则必须在应用程序清单中 ContainerHostPolicies 下方的 Volume 和 LogConfig 元素中指定相应的值 。In your applications, to use the volume or logging driver you installed, you would have to specify the appropriate values in the Volume and LogConfig elements under ContainerHostPolicies in your application manifest.

<ContainerHostPolicies CodePackageRef="NodeService.Code" Isolation="hyperv">
    <PortBinding ContainerPort="8905" EndpointRef="Endpoint1"/>
    <RepositoryCredentials PasswordEncrypted="false" Password="****" AccountName="test"/>
    <LogConfig Driver="[YOUR_LOG_DRIVER]" >
        <DriverOption Name="test" Value="vale"/>
    </LogConfig>
    <Volume Source="c:\workspace" Destination="c:\testmountlocation1" IsReadOnly="false"></Volume>
    <Volume Source="[MyStorageVar]" Destination="c:\testmountlocation2" IsReadOnly="true"> </Volume>
    <Volume Source="myvolume1" Destination="c:\testmountlocation2" Driver="[YOUR_VOLUME_DRIVER]" IsReadOnly="true">
        <DriverOption Name="[name]" Value="[value]"/>
    </Volume>
</ContainerHostPolicies>

指定卷插件时,Service Fabric 使用指定的参数自动创建卷。When specifying a volume plug-in, Service Fabric automatically creates the volume by using the specified parameters. “Volume”元素的“Source”标记是卷的名称,“Driver”标记指定卷驱动程序插件 。The Source tag for the Volume element is the name of the volume and the Driver tag specifies the volume driver plug-in. “Destination”标记是“Source”在运行的容器中映射到的位置 。The Destination tag is the location that the Source is mapped to within the running container. 因此,目标不能为容器中的现有位置。Thus, your destination can't be a location that already exists within your container. 使用 DriverOption 标记可指定选项,如下所示 :Options can be specified by using the DriverOption tag as follows:

<Volume Source="myvolume1" Destination="c:\testmountlocation4" Driver="azure" IsReadOnly="true">
    <DriverOption Name="share" Value="models"/>
</Volume>

应用程序支持参数卷中前面的清单代码段所示(查找 MyStorageVar 有关用法示例)。Application parameters are supported for volumes as shown in the preceding manifest snippet (look for MyStorageVar for an example use).

如果指定了 Docker 日志记录驱动程序,则需要部署代理(或容器)以处理群集中的日志。If a Docker log driver is specified, you have to deploy agents (or containers) to handle the logs in the cluster. DriverOption 标记可用于指定日志记录驱动程序的选项 。The DriverOption tag can be used to specify options for the log driver.

后续步骤Next steps