Skip to content

Commit 68472cd

Browse files
committedDec 17, 2020
initial commit
1 parent 89818fc commit 68472cd

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed
 

‎README.md

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# `example-envoy-xds`
2+
3+
[![Apache License](https://img.shields.io/github/license/octu0/example-envoy-xds)](https://github.com/octu0/example-envoy-xds/blob/master/LICENSE)
4+
[![GoDoc](https://godoc.org/github.com/octu0/example-envoy-xds?status.svg)](https://godoc.org/github.com/octu0/example-envoy-xds)
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/octu0/example-envoy-xds)](https://goreportcard.com/report/github.com/octu0/example-envoy-xds)
6+
[![Releases](https://img.shields.io/github/v/release/octu0/example-envoy-xds)](https://github.com/octu0/example-envoy-xds/releases)
7+
8+
`example-envoy-xds` is an example of implementation of [envoy](https://www.envoyproxy.io/) and [control-plane](https://github.com/envoyproxy/go-control-plane/) using [v3 xDS](https://www.envoyproxy.io/docs/envoy/v1.15.3/api-docs/xds_protocol) API.
9+
10+
Features:
11+
- xDS (EDS/CDS/LDS/RDS/ALS)
12+
- Dynamic update of yaml files (using [fsnotify](github.com/fsnotify/fsnotify))
13+
- Access log storage using ALS
14+
- Configuration examples of various settings
15+
- Configuration of Weighted Round Robin LoadBalancer
16+
17+
## Bootstraping
18+
19+
As bootstrap, in [envoy/envoy.yaml](https://github.com/octu0/example-envoy-xds/blob/master/envoy/envoy.yaml), specify `example-envoy-xds` in `xds_cluster` and `als_cluster`
20+
This will allow xDS communication with grpc.
21+
22+
For general use, `envoy.yaml` is used as a template file and replaced by `sed` in [docker-entrypoint.sh](https://github.com/octu0/example-envoy-xds/blob/master/envoy/docker-entrypoint.sh).
23+
24+
```yaml
25+
node:
26+
cluster: @ENVOY_XDS_CLUSTER@
27+
id: @ENVOY_XDS_NODE_ID@
28+
locality:
29+
region: @ENVOY_XDS_LOCALITY_REGION@
30+
zone: @ENVOY_XDS_LOCALITY_ZONE@
31+
32+
admin:
33+
access_log_path: /dev/null
34+
address:
35+
socket_address: { protocol: TCP, address: @ENVOY_ADMIN_LISTEN_HOST@, port_value: @ENVOY_ADMIN_LISTEN_PORT@ }
36+
37+
dynamic_resources:
38+
lds_config:
39+
resource_api_version: V3
40+
api_config_source:
41+
api_type: GRPC
42+
transport_api_version: V3
43+
grpc_services:
44+
- envoy_grpc: { cluster_name: xds_cluster }
45+
set_node_on_first_message_only: true
46+
cds_config:
47+
resource_api_version: V3
48+
api_config_source:
49+
api_type: GRPC
50+
transport_api_version: V3
51+
grpc_services:
52+
- envoy_grpc: { cluster_name: xds_cluster }
53+
set_node_on_first_message_only: true
54+
55+
static_resources:
56+
clusters:
57+
- name: xds_cluster
58+
connect_timeout: 1s
59+
type: STATIC
60+
lb_policy: ROUND_ROBIN
61+
http2_protocol_options: {}
62+
load_assignment:
63+
cluster_name: xds_cluster
64+
endpoints:
65+
- lb_endpoints:
66+
- endpoint:
67+
address:
68+
socket_address: { protocol: TCP, address: @ENVOY_XDS_HOST@, port_value: @ENVOY_XDS_PORT@ }
69+
- name: als_cluster
70+
connect_timeout: 1s
71+
type: STATIC
72+
lb_policy: ROUND_ROBIN
73+
http2_protocol_options: {}
74+
upstream_connection_options:
75+
tcp_keepalive: {}
76+
load_assignment:
77+
cluster_name: als_cluster
78+
endpoints:
79+
- lb_endpoints:
80+
- endpoint:
81+
address:
82+
socket_address: { protocol: TCP, address: @ENVOY_ALS_HOST@, port_value: @ENVOY_ALS_PORT@ }
83+
84+
layered_runtime:
85+
layers:
86+
- name: runtime0
87+
rtds_layer:
88+
rtds_config:
89+
resource_api_version: V3
90+
api_config_source:
91+
transport_api_version: V3
92+
api_type: GRPC
93+
grpc_services:
94+
envoy_grpc:
95+
cluster_name: xds_cluster
96+
name: runtime0
97+
```
98+
99+
When you start envoy with docker, you can specify the IP and port of `example-envoy-xds` with environment variables.
100+
101+
```shell
102+
$ docker run --net=host \
103+
-e ENVOY_XDS_CLUSTER=example0 \
104+
-e ENVOY_XDS_NODE_ID=envoy-node1 \
105+
-e ENVOY_XDS_HOST=10.10.0.101 \
106+
-e ENVOY_XDS_PORT=5000 \
107+
-e ENVOY_XDS_LOCALITY_REGION=asia-northeast1 \
108+
-e ENVOY_XDS_LOCALITY_ZONE=asia-northeast1-a \
109+
-e ENVOY_ALS_HOST=10.10.0.101 \
110+
-e ENVOY_ALS_PORT=5001 \
111+
docker.pkg.github.com/octu0/example-envoy-xds/envoy:1.15.3
112+
```
113+
114+
Configure xDS with grpc, `example-envoy-xds` will be started so that envoy can communicate with it.
115+
At this time, the node.id of envoy (specified by `ENVOY_XDS_NODE_ID`) must be the same value to start, otherwise the snapshot will not be changed.
116+
117+
```shell
118+
$ example-envoy-xds server \
119+
--node-id envoy-node1 \
120+
--xds-listen-addr 0.0.0.0:5000 \
121+
--als-listen-addr 0.0.0.0:5001 \
122+
```
123+
124+
## Execution example
125+
126+
Using docker-compose to check the behavior.
127+
128+
```shell
129+
$ docker-compose up -d
130+
```
131+
132+
and curl it.
133+
134+
```shell
135+
$ curl -H 'Host:example.com' localhost:8080
136+
legacy node-003
137+
138+
$ curl -H 'Host:example.com' localhost:8080
139+
new node-102
140+
```
141+
142+
## License
143+
144+
Apache 2.0, see LICENSE file for details.

0 commit comments

Comments
 (0)
Please sign in to comment.