如何使用 envoyloadbalancer 在同一个 public IP 上路由多个域

how to use envoyloadbalancer to route Multiple domains on same public IP

这是我的架构 architecture

我想将多个域绑定到同一个 IP 地址 例如,当我在浏览器中输入 foo.com 时,我看到了 webapp1 当我在浏览器中输入 bar.com 时,我找到了 webapp2 。 为此,我有两个 webapp: webapp1 在 ip 1111:5000

webapp2 在 ip 1111:6000

这是我的特使版本

envoy  version: d362e791eb9e4efa8d87f6d878740e72dc8330ac/1.18.2/clean-getenvoy-76c310e-envoy/RELEASE/BoringSSL

这是我的配置 envoy.yaml :

static_resources:
  listeners:
  - address:
      socket_address:
        address: 0.0.0.0
        port_value: 80
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          codec_type: AUTO
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: foo.com
              domains:
              - "foo.com"
              routes:
              - match:
                  prefix: "/"
                route:
                  cluster: service_foo
            - name: bar.com
              domains:
              - "bar.com"
              routes:
              - match:
                  prefix: "/"
                route:
                  cluster: service_bar
          http_filters:
          - name: envoy.router
            typed_config: {}
  clusters:
  - name: service_foo
    connect_timeout: 1.00s
    type: strict_dns
    lb_policy: round_robin
    load_assignment:
      cluster_name: service_foo
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: 1.1.1.1
                port_value: 5000
                ipv4_compat: true
  - name: service_bar
    connect_timeout: 1.00s
    type: strict_dns
    lb_policy: round_robin
    load_assignment:
      cluster_name: service_bar
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: 1.1.1.1
                port_value: 6000
                ipv4_compat: true
  
admin:
  access_log_path: "/dev/null"
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 8001

当我在我的浏览器中输入时 foo.com 有效,但 bar.com 无效。 有什么问题请帮帮我。

我做了同样的测试,但 YAML 配置文件略有不同。

我认为每个服务端点必须是内部 IP 地址(私有)。 这是一个示例:我在 docker 上有两个 Web 应用程序 运行:端口 3000 上的 start 和端口 8080 上的 blog . docker 图片在这里:https://hub.docker.com/r/ang67/blog and https://hub.docker.com/r/ang67/getting-started

static_resources:
  listeners:
  - address:
      socket_address:
        address: 0.0.0.0
        port_value: 80
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          codec_type: AUTO
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: start.com
              domains:
              - "start.com"
              routes:
              - match:
                  prefix: "/"
                route:
                  cluster: service_start
            - name: blog.com
              domains:
              - "blog.com"
              routes:
              - match:
                  prefix: "/"
                route:
                  cluster: service_blog
          http_filters:
          - name: envoy.filters.http.router
            typed_config: {}
  clusters:
  - name: service_start
    connect_timeout: 1.00s
    type: strict_dns
    lb_policy: round_robin
    load_assignment:
      cluster_name: service_start
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: 172.17.0.1
                port_value: 3000
                ipv4_compat: true
  - name: service_blog
    connect_timeout: 1.00s
    type: strict_dns
    lb_policy: round_robin
    load_assignment:
      cluster_name: service_blog
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: 172.17.0.1
                port_value: 8080
                ipv4_compat: true
  
admin:
  access_log_path: "/dev/null"
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 8001

运行集装箱上的特使:

docker run --rm -it \
    -v $(pwd)/envoy-custom.yaml:/envoy-custom.yaml \
    -p 9901:9901 \
    -p 80:80 \
    envoyproxy/envoy-dev:2e6db8378477a4a63740746c5bfeb264cd76bc34 \
    -c /envoy-custom.yaml

运行:

curl -H "Host: start.com" http://localhost
curl -H "Host: blog.com" http://localhost

或者在您的 etc/hosts 中为 start.com 和 blog.com 进行映射,以便在浏览器中启动