程序印象

Hello Envoy EDS

2018/06/28 Share

Arch

See alos: https://github.com/DavadDi/envoy_discovery

Start SDS/EDS server

1
2
3
4
5
6
7
8
9
10
$ cd eds_server/

$ virtualenv env --python=python2.7
$ source env/bin/activate
$ pip install -r requirements.txt

# ImportError: No module named enum
# $ pip install enum34

$ python main.py

Start upstream server

Start server 01

1
2
3
4
5
6
7
$ cd upstream/

$ virtualenv env --python=python2.7
$ source env/bin/activate
$ pip install -r requirements.txt

$ python server.py -p 8081

Start server 02

1
2
$ cd upstream/
$ python server.py -p 8082

Register upstream server info to SDS/EDS Server, named “myservice”

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
#  PUT AND Post share the same format
$ curl -XPOST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
"hosts": [
{
"ip_address": "127.0.0.1",
"port": 8081,
"tags": {
"server01": "8081",
"canary": false,
"load_balancing_weight": 50
}
},
{
"ip_address": "127.0.0.1",
"port": 8082,
"tags": {
"server01": "8082",
"canary": false,
"load_balancing_weight": 50
}
}
]
}' http://localhost:8080/edsservice/myservice

# list info
$ curl -XGET http://localhost:8080/edsservice/myservice

Start Envoy

1
2
3
4
5
6
7
8
$ envoy -c envoy_config.yaml --v2-config-only -l debug

# 替换成 docker 启动比较好
# 验证配置文件合法性
# $ docker run --rm -v `pwd`/envoy_config.yaml:/etc/envoy_config.yaml lyft/envoy:latest /usr/local/bin/envoy --mode validate --config-path /etc/envoy_config.yaml -l debug

# 启动
$ docker run --rm -v `pwd`/envoy_config.yaml:/etc/envoy_config.yaml lyft/envoy:latest /usr/local/bin/envoy --config-path /etc/envoy_config.yaml -l debug

envoy_config.yaml likes this:

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
admin:
access_log_path: /dev/null
address:
socket_address:
address: 127.0.0.1
port_value: 9000

node:
cluster: mycluster
id: test-id

static_resources:
listeners:
- name: listener_0

address:
socket_address: { address: 0.0.0.0, port_value: 10000 }

filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
stat_prefix: ingress_http
codec_type: AUTO
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: service_backend }
http_filters:
- name: envoy.router

clusters:
- name: service_backend
type: EDS
connect_timeout: 0.25s
eds_cluster_config:
service_name: myservice
eds_config:
api_config_source:
#api_type: REST_LEGACY # GET /v1/registration/myservice
#api_type: REST # POST /v2/discovery:endpoints
api_type: REST
cluster_names: [eds_cluster]
refresh_delay: 5s
- name: eds_cluster
type: STATIC
connect_timeout: 0.25s
hosts: [{ socket_address: { address: 127.0.0.1, port_value: 8080 }}]

Test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ curl -v http://127.0.0.1:10000/
curl -v http://127.0.0.1:10000/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 10000 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:10000
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< content-type: text/html; charset=utf-8
< content-length: 36
< server: envoy
< date: Thu, 28 Jun 2018 03:50:48 GMT
< x-envoy-upstream-service-time: 1
<
* Connection #0 to host 127.0.0.1 left intact
bc8d7c3f-575b-43fb-beff-dd711d9f0b93

All upstream servers are unavailable,errors like this:

1
2
3
4
5
6
7
8
9
10
$ curl -v  http://localhost:10000/
...
< HTTP/1.1 503 Service Unavailable
< content-length: 19
< content-type: text/plain
< date: Mon, 30 Apr 2018 06:06:20 GMT
< server: envoy
<
* Connection #0 to host localhost left intact
no healthy upstreams

See

  1. envoy-discovery-hello-world
  2. Envoy control plane ‘hello world’
CATALOG
  1. 1. Arch
    1. 1.1. Start SDS/EDS server
    2. 1.2. Start upstream server
    3. 1.3. Start Envoy
    4. 1.4. Test
  2. 2. See