适用于 Service Fabric 网格的 Maven 插件
重要
Azure Service Fabric 网格的预览版已停用。 不允许再通过 Service Fabric 网格 API 进行新的部署。 对现有部署的支持将会持续到 2021 年 4 月 28 日。
有关详细信息,请参阅 Azure Service Fabric 网格预览版停用。
先决条件
- Java SDK
- Maven
- 带有网格扩展的 Azure CLI
- Service Fabric CLI
目标
azure-sfmesh:init
- 创建一个
servicefabric
文件夹,其中包含具有application.yaml
文件的appresources
文件夹。
azure-sfmesh:addservice
- 使用服务名称在
servicefabric
文件夹中创建一个文件夹,并创建服务的 YAML 文件。
azure-sfmesh:addnetwork
- 使用
appresources
文件夹中提供的网络名称生成network
YAML
azure-sfmesh:addgateway
- 使用
appresources
文件夹中提供的网关名称生成gateway
YAML
azure-sfmesh:addvolume
- 使用
appresources
文件夹中提供的卷名生成volume
YAML。
azure-sfmesh:addsecret
- 使用
appresources
文件夹中提供的密钥名称生成secret
YAML
azure-sfmesh:addsecretvalue
- 使用
appresources
文件夹中提供的密钥和密钥值名称生成secretvalue
YAML
azure-sfmesh:deploy
- 合并
servicefabric
文件夹中的 yaml,并在当前文件夹中创建 Azure Resource Manager 模板 JSON。 - 将所有资源部署到 Azure Service Fabric 网格环境
azure-sfmesh:deploytocluster
- 创建一个文件夹 (
meshDeploy
),其中包含从 yaml 生成的部署 JSON,这些 JSON 适用于 Service Fabric 群集 - 将所有资源部署到 Service Fabric 群集
使用情况
若要在 Maven Java 应用中使用 Maven 插件,请将以下代码片段添加到 pom.xml 文件:
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-sfmesh-maven-plugin</artifactId>
<version>0.1.0</version>
</plugin>
</plugins>
</build>
</project>
常见配置
Maven 插件目前不支持适用于 Azure 的 Maven 插件的常见配置。
操作说明
初始化 Azure Service Fabric 网格的 Maven 项目
运行以下命令以创建应用程序资源 YAML 文件。
mvn azure-sfmesh:init -DapplicationName=helloworldserver
- 在根文件夹中创建一个名为
servicefabric->appresources
的文件夹,其中包含名为app_helloworldserver
的应用程序 YAML
向应用程序添加资源
向应用程序添加新网络
运行以下命令以创建网络资源 yaml。
mvn azure-sfmesh:addnetwork -DnetworkName=helloworldservicenetwork -DnetworkAddressPrefix=10.0.0.0/22
- 在名为
network_helloworldservicenetwork
的文件夹servicefabric->appresources
中创建网络 YAML
向应用程序添加新服务
运行以下命令以创建服务 yaml。
mvn azure-sfmesh:addservice -DapplicationName=helloworldserver -DserviceName=helloworldservice -DimageName=helloworldserver:latest -DlistenerPort=8080 -DnetworkRef=helloworldservicenetwork
- 在名为
service_helloworldservice
的文件夹servicefabric->helloworldservice
中创建一个引用helloworldservicenetwork
和helloworldserver
应用的服务 YAML - 该服务将侦听端口 8080
- 该服务将使用 helloworldserver:latest ,因为它是容器映像。
向应用程序添加新网关资源
运行以下命令以创建网关资源 yaml。
mvn azure-sfmesh:addgateway -DapplicationName=helloworldserver -DdestinationNetwork=helloworldservicenetwork -DgatewayName=helloworldgateway -DlistenerName=helloworldserviceListener -DserviceName=helloworldservice -DsourceNetwork=open -DtcpPort=80
- 在名为
gateway_helloworldgateway
的文件夹servicefabric->appresources
中创建新网关 YAML - 引用
helloworldservicelistener
作为侦听来自此网关的调用的服务侦听器。 此外,引用helloworldservice
作为服务,引用helloworldservicenetwork
作为网络,引用helloworldserver
作为应用程序。 - 在端口 80 上侦听请求
向应用程序添加新卷
运行以下命令以创建卷资源 yaml。
mvn azure-sfmesh:addvolume -DvolumeAccountKey=key -DvolumeAccountName=name -DvolumeName=vol1 -DvolumeShareName=share
- 在名为
volume_vol1
的文件夹servicefabric->appresources
中创建卷 YAML - 如上所述设置所需参数
volumeAccountKey
和volumeShareName
的属性 - 有关如何引用此创建的卷的详细信息,请访问以下内容:使用 Azure 文件卷部署应用
向应用程序添加新密钥资源
运行以下命令以创建密钥资源 yaml。
mvn azure-sfmesh:addsecret -DsecretName=secret1
- 在名为
secret_secret1
的文件夹servicefabric->appresources
中创建密钥 YAML - 有关如何引用此创建的密钥的详细信息,请访问以下内容:管理密钥
向应用程序添加新密钥值资源
运行以下命令以创建密钥值资源 yaml。
mvn azure-sfmesh:addsecretvalue -DsecretValue=someVal -DsecretValueName=secret1/v1
- 在名为
secretvalue_secret1_v1
的文件夹servicefabric->appresources
中创建一个密钥值 YAML
在本地运行应用程序
在目标 azure-sfmesh:deploytocluster
的帮助下,可以使用以下命令在本地运行应用程序:
mvn azure-sfmesh:deploytocluster
默认情况下,此目标将资源部署到本地群集。 如果要部署到本地群集,则假定已启动并运行本地 Service Fabric 群集。 当前仅在 Windows 上支持资源的本地 Service Fabric 群集。
- 从 yaml 创建适用于 Service Fabric 群集的 JSON
- 然后,部署到群集终结点
对 Azure Service Fabric 网格部署应用程序
在目标 azure-sfmesh:deploy
的帮助下,可以通过运行以下命令部署到 Service Fabric 网格环境:
mvn azure-sfmesh:deploy -DresourceGroup=todoapprg -Dlocation=eastus
- 如果不存在,则创建名为
todoapprg
的资源组。 - 通过合并 YAML 创建 Azure 资源管理器模板 JSON。
- 将 JSON 部署到 Azure Service Fabric 网格环境。