Envoy clusters配置

环境说明

envoy:Front Proxy, 地址为 172.31.4.2

webserver01:后端服务,地址为 172.31.4.11

webserver01:后端服务,地址为 172.31.4.12

clusters 类型为STRICT_DNS

envoy配置文件

查看代码
static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address: { address: 127.0.0.1, 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
          stat_prefix: ingress_http
          codec_type: AUTO
          route_config:
            name: local_route
            virtual_hosts:
            - name: web_service_1
              domains: ["*"]
              routes:
              - match: { prefix: "/" }
                route: { cluster: web_cluster }
          http_filters:
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

  clusters:
  - name: web_cluster
    connect_timeout: 0.25s
    type: STRICT_DNS     # 严格DNS
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: web_cluster
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address: { address: webserver, port_value: 80 }  # address: webserver

docker-compose.yaml

查看代码
version: '3.3'

services:
  envoy:
    image: envoyproxy/envoy:v1.23-latest
    volumes:
    - ./envoy.yaml:/etc/envoy/envoy.yaml
    environment:
      - ENVOY_UID=0
      - ENVOY_GID=0
    networks:
      envoymesh:
        ipv4_address: 172.31.4.2
        aliases:
        - front-proxy
    depends_on:
    - webserver01
    - webserver02

  client:
    image: ikubernetes/admin-toolbox:v1.0
    network_mode: "service:envoy"
    depends_on:
    - envoy

  webserver01:
    image: ikubernetes/demoapp:v1.0
    hostname: webserver01
    networks:
      envoymesh:
        ipv4_address: 172.31.4.11
        aliases:
        - webserver01
        - webserver     # docker 内部DNS解析

  webserver02:
    image: ikubernetes/demoapp:v1.0
    hostname: webserver02
    networks:
      envoymesh:
        ipv4_address: 172.31.4.12
        aliases:
        - webserver02
        - webserver     # docker 内部DNS解析

networks:
  envoymesh:
    driver: bridge
    ipam:
      config:
        - subnet: 172.31.4.0/24

运行envoy

docker-compose up -d

测试envoy

# docker-compose exec client bash
[root@c3f2cc207ac9 /]$ ping webserver
PING webserver (172.31.4.12): 56 data bytes
64 bytes from 172.31.4.12: seq=0 ttl=64 time=0.076 ms

[root@c3f2cc207ac9 /]$ ping webserver
PING webserver (172.31.4.11): 56 data bytes
64 bytes from 172.31.4.11: seq=0 ttl=64 time=0.058 ms

[root@c3f2cc207ac9 /]$ curl http://127.0.0.1:80
iKubernetes demoapp v1.0 !! ClientIP: 172.31.4.2, ServerName: webserver02, ServerIP: 172.31.4.12!

[root@c3f2cc207ac9 /]$ curl http://127.0.0.1:80
iKubernetes demoapp v1.0 !! ClientIP: 172.31.4.2, ServerName: webserver01, ServerIP: 172.31.4.11!

[root@c3f2cc207ac9 /]$ curl http://127.0.0.1:80
iKubernetes demoapp v1.0 !! ClientIP: 172.31.4.2, ServerName: webserver02, ServerIP: 172.31.4.12!

[root@c3f2cc207ac9 /]$ curl http://127.0.0.1:80
iKubernetes demoapp v1.0 !! ClientIP: 172.31.4.2, ServerName: webserver01, ServerIP: 172.31.4.11!

清理envoy

docker-compose  down

 

posted @ 2022-08-12 17:17  小吉猫  阅读(149)  评论(0编辑  收藏  举报