在Service Fabric Mesh中公开多个服务

时间:2018-12-04 18:40:41

标签: azure azure-service-fabric azure-service-fabric-mesh

我正在尝试公开两个服务(Web API和Chat Bot),它们通过 Service Fabric Mesh 网络的入口控制器在内部打开相同的端口。

运行下面的定义总是使两个服务之一失败。

我不清楚的是什么

  1. 是因为它们都在内部打开相同的端口(80和443)吗?
  2. 通常这是个坏主意,我应该使用像NGINX这样的反向代理吗?
  3. 我可以从两项服务中获得两个不同的IP地址吗?

文件:

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "apiVersion": "2018-07-01-preview",
      "name": "contosomaintenance",
      "type": "Microsoft.ServiceFabricMesh/applications",
      "location": "westeurope",
      "dependsOn": [
        "Microsoft.ServiceFabricMesh/networks/contosomaintenance-network"
      ],
      "properties": {
        "services": [
          {
            "name": "contosomaintenance-api",
            "properties": {
              "description": "Contoso Maintenance REST API",
              "osType": "Linux",
              "codePackages": [
                {
                  "name": "contosomaintenance-api",
                  "image": "robinmanuelthiel/contosomaintenance-api:latest",
                  "endpoints": [
                    {
                      "name": "http",
                      "port": 80
                    },
                    {
                      "name": "https",
                      "port": 443
                    }
                  ],
                  "resources": {
                    "requests": {
                      "cpu": "0.5",
                      "memoryInGB": "1"
                    }
                  }
                }
              ],
              "replicaCount": "1",
              "networkRefs": [
                {
                  "name": "[resourceId('Microsoft.ServiceFabricMesh/networks', 'contosomaintenance-network')]"
                }
              ]
            }
          },
          {
            "name": "contosomaintenance-bot",
            "properties": {
              "description": "Contoso Maintenance Chat Bot",
              "osType": "Linux",
              "codePackages": [
                {
                  "name": "contosomaintenance-bot",
                  "image": "robinmanuelthiel/contosomaintenance-bot:latest",
                  "endpoints": [
                    {
                      "name": "http",
                      "port": 80
                    },
                    {
                      "name": "https",
                      "port": 443
                    }
                  ],
                  "resources": {
                    "requests": {
                      "cpu": "0.5",
                      "memoryInGB": "1"
                    }
                  }
                }
              ],
              "replicaCount": "1",
              "networkRefs": [
                {
                  "name": "[resourceId('Microsoft.ServiceFabricMesh/networks', 'contosomaintenance-network')]"
                }
              ]
            }
          }
        ]
      }
    },
    {
      "apiVersion": "2018-07-01-preview",
      "name": "contosomaintenance-network",
      "type": "Microsoft.ServiceFabricMesh/networks",
      "location": "westeurope",
      "dependsOn": [],
      "properties": {
        "description": "Contoso Maintenance Network",
        "addressPrefix": "10.0.0.0/22",
        "ingressConfig": {
          "layer4": [
            {
              "name": "contosomaintenance-api-ingress-http",
              "publicPort": "20001",
              "applicationName": "contosomaintenance",
              "serviceName": "contosomaintenance-api",
              "endpointName": "http"
            },
            {
              "name": "contosomaintenance-api-ingress-bot",
              "publicPort": "20002",
              "applicationName": "contosomaintenance",
              "serviceName": "contosomaintenance-bot",
              "endpointName": "http"
            }
          ]
        }
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:2)

更新2018-12-10

新的ApiVersion已发布(2018-09-01-preview),公开服务的新方法是使用网关资源。可以在this github线程和this文档上找到更多信息。

这是网关(仅)的片段,它公开了同一应用程序中的两个服务:

{
  "apiVersion": "2018-09-01-preview",
  "name": "helloWorldGateway",
  "type": "Microsoft.ServiceFabricMesh/gateways",
  "location": "[parameters('location')]",
  "dependsOn": [
    "Microsoft.ServiceFabricMesh/networks/helloWorldNetwork"
  ],
  "properties": {
    "description": "Service Fabric Mesh Gateway for HelloWorld sample.",
    "sourceNetwork": {
      "name": "Open"
    },
    "destinationNetwork": {
      "name": "[resourceId('Microsoft.ServiceFabricMesh/networks', 'helloWorldNetwork')]"
    },
    "http": [
      {
        "name": "web",
        "port": 81,
        "hosts": [
          {
            "name": "*",
            "routes": [
              {
                "name":  "helloRoute",
                "match": {
                  "path": {
                    "value": "/",
                    "rewrite": "/",
                    "type": "Prefix"
                  }
                },
                "destination": {
                  "applicationName": "helloWorldApp",
                  "serviceName": "helloWorldService",
                  "endpointName": "helloWorldListener"
                }
              }
            ]
          }
        ]
      },
      {
        "name": "kuard",
        "port": 82,
        "hosts": [
          {
            "name": "*",
            "routes": [
              {
                "name":  "kuardRoute",
                "match": {
                  "path": {
                    "value": "/",
                    "rewrite": "/",
                    "type": "Prefix"
                  }
                },
                "destination": {
                  "applicationName": "helloWorldApp",
                  "serviceName": "kuardService",
                  "endpointName": "kuardListener"
                }
              }
            ]
          }
        ]
      }
    ],
    "tcp": [
      {
        "name": "web",
        "port": 80,
        "destination": {
          "applicationName": "helloWorldApp",
          "serviceName": "helloWorldService",
          "endpointName": "helloWorldListener"
        }
      },
      {
        "name": "kuard",
        "port": 8080,
        "destination": {
          "applicationName": "helloWorldApp",
          "serviceName": "kuardService",
          "endpointName": "kuardListener"
        }
      }
    ]
  }
}

注意:

  • 该应用程序是相同的helloWorld示例,具有额外的服务
  • 网关已被修改为通过TCP和HTTP公开不同的端口
  • 无法再通过网络公开服务(如原始答案中所述)

原始答案

当前,网络有两个大限制:

  • 每个应用程序一个网络:两个网络中不能有一个应用程序。 source
  • 每个服务一个网络入口:当您使用针对多个服务的多个规则定义入口时,即使其中的大多数部署在没有警告的情况下成功进行,也只能使用其中一个规则。 source

这些是公开预览的限制,可能在GA上已解决。

在这种情况下,如果您需要公开两项服务,则可以选择以下替代方法:

  • 创建两个网络和两个应用程序:每个具有单独服务的应用程序都部署在自己的网络上,每个服务将具有不同的IP。
  • 创建代理服务:使用NGINX之类的解决方案来接收所有连接并将请求在内部路由到适当的服务。
  • 使用gateway资源:SF Mesh很快将发布基于envoy的网关服务,当可用时将是此方案的最佳解决方案,它将与NGINX方法非常相似以上版本,但由Azure管理,尚不可用,但即将发布。