本文发布于Cylon的收藏册,转载请著名原文链接~

实验文件

docker-compose

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
version: '3'
services:
  envoy:
    image: envoyproxy/envoy-alpine:v1.15-latest
    environment: 
    - ENVOY_UID=0
    - HEALTHY=ok
    ports:
    - 80:80
    - 443:443
    - 82:9901
    volumes:
    - ./envoy.yaml:/etc/envoy/envoy.yaml
    - ./certs:/etc/envoy/certs
    networks:
      envoymesh:
        aliases:
        - envoy
    depends_on:
    - webserver1
    - webserver2
  
  webserver1:
    image: cylonchau/envoy-end:latest
    environment: 
    - COLORFUL=blue
    - HEALTHY=ok
    networks:
      envoymesh:
        aliases:
        - myservice
        - webservice
    expose:
    - 90
  webserver2:
    image: cylonchau/envoy-end:latest
    environment: 
    - COLORFUL=blue
    networks:
      envoymesh:
        aliases:
        - myservice
        - webservice
    expose:
    - 90 
networks:
  envoymesh: {}

envoy配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
admin:
  access_log_path: /dev/null
  address:
    socket_address: { address: 0.0.0.0, port_value: 9901 }

static_resources:
  listeners:
  - name: listener_0
    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
          stat_prefix: ingress_http
          codec_type: AUTO
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: [ "*" ]
              routes:
              - match: { prefix: "/" }
                route: { cluster: local_service }
          http_filters:
          - name: envoy.filters.http.router

  clusters:
  - name: local_service
    connect_timeout: 0.25s
    type: STRICT_DNS
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: local_service
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address: { address: webservice, port_value: 90 }
    health_checks:
      timeout: 1s
      interval: 10s
      unhealthy_threshold: 5
      healthy_threshold: 5
      http_health_check:
        path: "/ping"
        expected_statuses:
          start: 200
          end: 201

路由

/ping 健康监测的路由 /ping/ok 手动将节点设置为有效节点 /ping/fail 手动将节点设置为失效

测试结论

1
2
3
$ curl -s 127.0.0.1:82/clusters|grep health
local_service::172.22.0.2:90::health_flags::healthy
local_service::172.22.0.3:90::health_flags::healthy

当在集群启动时,所有节点默认为健康状态,在没有流量进入时,默认的间隔时间为1分钟。

当有外部流量进入后,在结束上个默认间隔1分钟之后,会成为配置文件设置的默认10s

手动设置一个节点为不健康状态,

日志中可以看出,在手动设置为失效时,请求是不会到达后端失效节点,并且第一次请求时间明显长,在设置为成功时,后端节点判定为健康是在4次健康监测而非正常请求

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
webserver1_1  | [GIN] 2020/09/13 - 02:00:48 | 200 |     110.706µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:00:48 | 200 |       47.29µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:00:49 | 200 |      14.909µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:01:18 | 200 |       58.53µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:01:19 | 200 |      15.988µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:01:42 | 200 |      20.844µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:01:42 | 200 |      12.247µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:01:52 | 200 |      38.892µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:01:52 | 200 |      32.254µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:01:54 | 200 |      33.689µs |             ::1 | GET      "/ping/fail"
webserver2_1  | [GIN] 2020/09/13 - 02:01:59 | 200 |       82.86µs |             ::1 | GET      "/ping/fail"
webserver1_1  | [GIN] 2020/09/13 - 02:02:02 | 200 |     155.202µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:02:02 | 502 |       26.73µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:02:07 | 200 |      19.193µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:08 | 200 |      14.651µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:09 | 200 |      15.101µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:09 | 200 |      15.294µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:10 | 200 |       26.45µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:10 | 200 |      17.679µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:11 | 200 |      14.703µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:11 | 200 |      14.546µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:02:12 | 502 |        8.37µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:02:12 | 200 |      14.214µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:02:22 | 502 |       8.998µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:02:22 | 200 |      13.489µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:02:30 | 200 |     119.326µs |             ::1 | GET      "/ping/ok"
webserver1_1  | [GIN] 2020/09/13 - 02:02:32 | 200 |       8.864µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:02:32 | 200 |      14.679µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:02:38 | 200 |      14.781µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:39 | 200 |      15.452µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:39 | 200 |      14.825µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:40 | 200 |      14.784µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:40 | 200 |      14.788µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:41 | 200 |      72.985µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:02:42 | 200 |       8.523µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:02:42 | 200 |      14.497µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:02:42 | 200 |      15.611µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:47 | 200 |      46.065µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:47 | 200 |      19.455µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:47 | 200 |      15.079µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:02:48 | 200 |      22.208µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:02:52 | 200 |      39.693µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:02:52 | 200 |      32.376µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:03:02 | 200 |      19.476µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:03:02 | 200 |      11.041µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:03:12 | 200 |      14.292µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:03:12 | 200 |       8.215µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:03:22 | 200 |      16.145µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:03:22 | 200 |      11.455µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:03:29 | 200 |       15.02µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:03:30 | 200 |      34.405µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:03:30 | 200 |      14.647µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:03:30 | 200 |      15.039µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:03:31 | 200 |      16.706µs |      172.22.0.4 | GET      "/"
webserver2_1  | [GIN] 2020/09/13 - 02:03:31 | 200 |      15.667µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:03:31 | 200 |      15.025µs |      172.22.0.4 | GET      "/"
webserver1_1  | [GIN] 2020/09/13 - 02:03:32 | 200 |      15.085µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:03:32 | 200 |      13.446µs |      172.22.0.4 | GET      "/ping"
webserver2_1  | [GIN] 2020/09/13 - 02:03:42 | 200 |      14.702µs |      172.22.0.4 | GET      "/ping"
webserver1_1  | [GIN] 2020/09/13 - 02:03:42 | 200 |       9.262µs |      172.22.0.4 | GET      "/ping"

无外部流量时的请求间隔设置 官方参考

1
no_traffic_interval

本文发布于Cylon的收藏册,转载请著名原文链接~

链接:Envoy的主动健康监测

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」 许可协议进行许可。