Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: Add dynamic configuration (control plane) sandbox #13746

Merged
merged 48 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
16da2b0
examples: Add wait_for utility function
phlax Oct 25, 2020
441b4f7
add docs
phlax Oct 25, 2020
e687cea
examples: Add dynamic configuration example
phlax Oct 24, 2020
c03da09
verify
phlax Oct 24, 2020
c1e8b45
add resource.go
phlax Oct 24, 2020
0b787c3
docs/
phlax Oct 24, 2020
7bab9e9
examples/
phlax Oct 24, 2020
daca281
docs/
phlax Oct 24, 2020
2b333ec
docs/
phlax Oct 24, 2020
56e539f
example
phlax Oct 25, 2020
034e547
example
phlax Oct 25, 2020
8ee1637
examples/
phlax Oct 25, 2020
0e98260
examples/
phlax Oct 25, 2020
7af06c9
docs/
phlax Oct 25, 2020
e785cc4
docs/
phlax Oct 25, 2020
7f23b70
docs/
phlax Oct 26, 2020
90f2b67
docs/
phlax Oct 26, 2020
25c44b7
docs/
phlax Oct 26, 2020
e299084
docs/
phlax Oct 26, 2020
e2eccd1
examples/
phlax Oct 26, 2020
c403196
docs/
phlax Oct 26, 2020
151b4c7
docs/
phlax Oct 26, 2020
c487ca9
docs/
phlax Oct 26, 2020
42985e7
examples/
phlax Oct 26, 2020
c1ae8d2
resource.go
phlax Oct 26, 2020
983ea43
examples/
phlax Oct 26, 2020
cfbae81
examples
phlax Oct 26, 2020
6d6d066
docs/
phlax Oct 26, 2020
8b09bce
envoy.yaml
phlax Oct 26, 2020
63048d4
rename dynamic-configuration -> dynamic-config-cp
phlax Oct 27, 2020
a1da617
docs/
phlax Oct 27, 2020
5da4d84
Merge branch 'master' into examples-dynamic-configuration
phlax Oct 27, 2020
dcb9756
Merge branch 'master' into examples-dynamic-configuration
phlax Oct 27, 2020
8cf7656
docs/
phlax Oct 27, 2020
bd31689
docs/
phlax Oct 27, 2020
78ea83f
examples/
phlax Oct 27, 2020
cff56c2
examples/
phlax Oct 27, 2020
1c21269
docs/
phlax Oct 27, 2020
2d3795e
docs/
phlax Oct 27, 2020
4661f92
docs/
phlax Oct 27, 2020
61e289e
docs/
phlax Oct 27, 2020
3fb94c1
examples/
phlax Oct 27, 2020
eefc0ad
docs/
phlax Oct 27, 2020
cf714f0
docs/
phlax Oct 27, 2020
e0cab03
docs/
phlax Oct 27, 2020
3d582e8
remove host rewrite
phlax Oct 27, 2020
5f9d732
docs/
phlax Oct 27, 2020
328c40f
docs/
phlax Oct 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"version_info": "1",
"cluster": {
"@type": "type.googleapis.com/envoy.config.cluster.v3.Cluster",
"name": "example_proxy_cluster",
"type": "LOGICAL_DNS",
"connect_timeout": "5s",
"dns_lookup_family": "V4_ONLY",
"load_assignment": {
"cluster_name": "example_proxy_cluster",
"endpoints": [
{
"lb_endpoints": [
{
"endpoint": {
"address": {
"socket_address": {
"address": "service1",
"port_value": 8080
}
}
}
}
]
}
]
}
},
"last_updated": "2020-10-25T20:37:05.838Z"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"cluster": {
"@type": "type.googleapis.com/envoy.api.v2.Cluster",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the wrong response - update to v3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm - seems like this is the response you get back from the go-control-plane

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this must be what is configured in static_resources - im surprised its not an api.v3.Cluster

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I would update to v3 if possible. cc @htuch @kyessenov for guidance here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like an issue with go-control-plane - (at least the example i based this on)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, i reckon its not gcp thats returning this, its what you get from config above, when you do config_dump in envoy - its the static part

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK not sure what the issue is without digging in more detail. It's possible this is a config dump issue. I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me open a ticket - and we can thrash it out there...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phlax Can you help me with the gcp samples you followed? From the initial pass looks like gcp example uses v3 https://github.com/envoyproxy/go-control-plane/blob/master/internal/example/README.md

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyotimahapatra i think its not a problem with go-control-plane

i opened a ticket here #13817 to raise it

"name": "xds_cluster",
"type": "STRICT_DNS",
"connect_timeout": "1s",
"http2_protocol_options": {},
"load_assignment": {
"cluster_name": "xds_cluster",
"endpoints": [
{
"lb_endpoints": [
{
"endpoint": {
"address": {
"socket_address": {
"address": "go-control-plane",
"port_value": 18000
}
}
}
}
]
}
]
}
},
"last_updated": "2020-10-25T20:20:54.897Z"
}
]
175 changes: 175 additions & 0 deletions docs/root/start/sandboxes/dynamic-configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
.. _install_sandboxes_dynamic_configuration:

Dynamic configuration
=====================

.. include:: _include/docker-env-setup.rst


Step 3: Take a look at the proxy config
***************************************
phlax marked this conversation as resolved.
Show resolved Hide resolved

.. literalinclude:: _include/dynamic-configuration/envoy.yaml
:language: yaml

Step 4: Start the proxy container
*********************************

First lets build our containers and start the proxy container, and two backend HTTP echo servers.

The go-control-plane has not yet been started.

.. code-block:: console

$ pwd
envoy/examples/dynamic-configuration
$ docker-compose build --pull
$ docker-compose up -d proxy
$ docker-compose ps

Name Command State Ports
------------------------------------------------------------------------------------------------------------------------------
dynamic-configuration_proxy_1 /docker-entrypoint.sh /usr ... Up 0.0.0.0:10000->10000/tcp, 0.0.0.0:19000->19000/tcp
dynamic-configuration_service1_1 /bin/echo-server Up 8080/tcp
dynamic-configuration_service2_1 /bin/echo-server Up 8080/tcp

Step 4: Check web response
**************************

Nothing is responding on port 10000

.. code-block:: console

$ curl http://localhost:10000
curl: (56) Recv failure: Connection reset by peer

If we config dump the ``static_clusters`` we should see the ``xds_cluster`` we configured for the control
plane:

.. code-block:: console

$ curl -s http://localhost:19000/config_dump | jq '.configs[1].static_clusters'

.. literalinclude:: _include/dynamic-configuration/response-config-cluster.json
:language: json

Step 5: Start the go-control-plane
**********************************

Let's start up the go-control-plane.

You may need to wait a moment or two for the service to become ``healthy``.

.. code-block:: console

$ docker-compose up --build -d go-control-plane
$ docker-compose ps

Name Command State Ports
-----------------------------------------------------------------------------------------------------------------------------------------
dynamic-configuration_go-control-plane_1 bin/example -debug Up (healthy)
dynamic-configuration_proxy_1 /docker-entrypoint.sh /usr ... Up 0.0.0.0:10000->10000/tcp, 0.0.0.0:19000->19000/tcp
dynamic-configuration_service1_1 /bin/echo-server Up 8080/tcp
dynamic-configuration_service2_1 /bin/echo-server Up 8080/tcp

Step 5: Query the proxy
***********************

Once the control plane has started, we should be able to make a request to port ``10000``, which will be
served by ``service1``.

.. code-block:: console

$ curl http://localhost:10000
Request served by service1

HTTP/1.1 GET /

Host: service1
Accept: */*
X-Forwarded-Proto: http
X-Request-Id: 1d93050e-f39c-4602-90f8-a124d6e78d26
X-Envoy-Expected-Rq-Timeout-Ms: 15000
Content-Length: 0
User-Agent: curl/7.72.0

Step 5: Dump the proxy config again
***********************************

If we now ``config_dump`` the ``dynamic_active_clusters`` we should see the endpoint pointing
to ``service1``

.. code-block:: console

$ curl -s http://localhost:19000/config_dump | jq '.configs[1].dynamic_active_clusters'

.. literalinclude:: _include/dynamic-configuration/response-config-active-clusters.json
:language: json

Step 5: Stop the go-control-plane
*********************************

Let's stop the go-control-plane:

.. code-block:: console

$ docker-compose stop go-control-plane

The Envoy proxy should continue proxying responses from ``service1``

.. code-block:: console

$ curl http://localhost:10000 | grep "served by"
Request served by service1

Step 5: Edit resource.go and restart the go-control-plane
*********************************************************

The example go-control-plane is started with a custom resource.go file which
specifies the configuration provided to Envoy.

If you edit this file and change the ``UpstreamHost`` from ``service1`` to ``service2``:

.. literalinclude:: _include/dynamic-configuration/resource.go
:language: go
:lines: 33-40
:emphasize-lines: 6
:linenos:

Further down in this file you must also change the configuration snapshot
version number from ``"1"`` to ``"2"``:

.. literalinclude:: _include/dynamic-configuration/resource.go
:language: go
:lineno-start: 167
:lines: 167-177
:emphasize-lines: 3
:linenos:

Now rebuild and restart the go-control-plane:

.. code-block:: console

$ docker-compose up --build -d go-control-plane

You may need to wait a moment or two for the go-control-plane to become ``healthy``.

Step 5: Query the proxy
***********************

When you make

.. code-block:: console

$ curl http://localhost:10000
Request served by service2

HTTP/1.1 GET /

Host: service1
phlax marked this conversation as resolved.
Show resolved Hide resolved
Accept: */*
X-Forwarded-Proto: http
X-Request-Id: 1d93050e-f39c-4602-90f8-a124d6e78d26
X-Envoy-Expected-Rq-Timeout-Ms: 15000
Content-Length: 0
User-Agent: curl/7.72.0
1 change: 1 addition & 0 deletions docs/root/start/sandboxes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ features. The following sandboxes are available:
cache
cors
csrf
dynamic-configuration
ext_authz
fault_injection
front_proxy
Expand Down
11 changes: 11 additions & 0 deletions examples/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ responds_without_header \

`responds_without_header` can accept additional curl arguments like `responds_with`

#### Utility functions: `wait_for`

You can wait for some amount of time for a command to return 0

The following example will wait for 20 seconds for a service ``my-service`` to become
healthy.

```bash
wait_for 20 sh -c "docker-compose ps my-service | grep healthy | grep -v unhealthy"
```

### Slow starting `docker` compositions

Unless your example provides a way for ensuring that all containers are healthy by
Expand Down
7 changes: 7 additions & 0 deletions examples/dynamic-configuration/Dockerfile-control-plane
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang

RUN apt-get -y update && apt-get install -y -qq --no-install-recommends netcat
RUN git clone https://github.com/envoyproxy/go-control-plane
ADD ./resource.go /go/go-control-plane/internal/example/resource.go
RUN cd go-control-plane && make bin/example
WORKDIR /go/go-control-plane
6 changes: 6 additions & 0 deletions examples/dynamic-configuration/Dockerfile-proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM envoyproxy/envoy-dev:latest

RUN apt-get -y update && apt-get install -y -qq --no-install-recommends netcat
COPY ./envoy.yaml /etc/envoy.yaml
RUN chmod go+r /etc/envoy.yaml
CMD ["/usr/local/bin/envoy", "-c /etc/envoy.yaml", "-l", "debug"]
2 changes: 2 additions & 0 deletions examples/dynamic-configuration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To learn about this sandbox and for instructions on how to run it please head over
to the [Envoy docs](https://www.envoyproxy.io/docs/envoy/latest/start/sandboxes/postgres.html).
phlax marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions examples/dynamic-configuration/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3.7"
services:

proxy:
build:
context: .
dockerfile: Dockerfile-proxy
depends_on:
- service1
- service2
ports:
- 10000:10000
- 19000:19000

service1:
image: jmalloc/echo-server
hostname: service1

service2:
image: jmalloc/echo-server
hostname: service2

go-control-plane:
build:
context: .
dockerfile: Dockerfile-control-plane
command: bin/example -debug
healthcheck:
test: nc -zv localhost 18000
53 changes: 53 additions & 0 deletions examples/dynamic-configuration/envoy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
admin:
access_log_path: /dev/null
address:
socket_address:
address: 0.0.0.0
port_value: 19000

dynamic_resources:
ads_config:
api_type: GRPC
transport_api_version: V3
grpc_services:
- envoy_grpc:
cluster_name: xds_cluster
set_node_on_first_message_only: false
phlax marked this conversation as resolved.
Show resolved Hide resolved
cds_config:
resource_api_version: V3
ads: {}
lds_config:
resource_api_version: V3
ads: {}
node:
cluster: test-cluster
id: test-id
static_resources:
clusters:
- connect_timeout: 1s
type: strict_dns
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: go-control-plane
port_value: 18000
http2_protocol_options: {}
name: xds_cluster
layered_runtime:
layers:
- name: runtime-0
rtds_layer:
rtds_config:
resource_api_version: V3
ads: {}
name: runtime-0
- name: runtime-1
rtds_layer:
rtds_config:
resource_api_version: V3
ads: {}
name: runtime-1
Loading