Examples

Below we will use YAML representation of the config protos and a running example of a service proxying HTTP from 127.0.0.1:10000 to 127.0.0.1:1234.

Static

A minimal fully static bootstrap config is provided below:

  1. admin:
  2. address:
  3. socket_address: { address: 127.0.0.1, port_value: 9901 }
  4. static_resources:
  5. listeners:
  6. - name: listener_0
  7. address:
  8. socket_address: { address: 127.0.0.1, port_value: 10000 }
  9. filter_chains:
  10. - filters:
  11. - name: envoy.filters.network.http_connection_manager
  12. typed_config:
  13. "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
  14. stat_prefix: ingress_http
  15. codec_type: AUTO
  16. route_config:
  17. name: local_route
  18. virtual_hosts:
  19. - name: local_service
  20. domains: ["*"]
  21. routes:
  22. - match: { prefix: "/" }
  23. route: { cluster: some_service }
  24. http_filters:
  25. - name: envoy.filters.http.router
  26. typed_config:
  27. "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  28. clusters:
  29. - name: some_service
  30. connect_timeout: 0.25s
  31. type: STATIC
  32. lb_policy: ROUND_ROBIN
  33. load_assignment:
  34. cluster_name: some_service
  35. endpoints:
  36. - lb_endpoints:
  37. - endpoint:
  38. address:
  39. socket_address:
  40. address: 127.0.0.1
  41. port_value: 1234

Mostly static with dynamic EDS

A bootstrap config that continues from the above example with dynamic endpoint discovery via an EDS gRPC management server listening on 127.0.0.1:5678 is provided below:

  1. admin:
  2. address:
  3. socket_address: { address: 127.0.0.1, port_value: 9901 }
  4. static_resources:
  5. listeners:
  6. - name: listener_0
  7. address:
  8. socket_address: { address: 127.0.0.1, port_value: 10000 }
  9. filter_chains:
  10. - filters:
  11. - name: envoy.filters.network.http_connection_manager
  12. typed_config:
  13. "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
  14. stat_prefix: ingress_http
  15. codec_type: AUTO
  16. route_config:
  17. name: local_route
  18. virtual_hosts:
  19. - name: local_service
  20. domains: ["*"]
  21. routes:
  22. - match: { prefix: "/" }
  23. route: { cluster: some_service }
  24. http_filters:
  25. - name: envoy.filters.http.router
  26. typed_config:
  27. "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  28. clusters:
  29. - name: some_service
  30. connect_timeout: 0.25s
  31. lb_policy: ROUND_ROBIN
  32. type: EDS
  33. eds_cluster_config:
  34. eds_config:
  35. resource_api_version: V3
  36. api_config_source:
  37. api_type: GRPC
  38. transport_api_version: V3
  39. grpc_services:
  40. - envoy_grpc:
  41. cluster_name: xds_cluster
  42. - name: xds_cluster
  43. connect_timeout: 0.25s
  44. type: STATIC
  45. lb_policy: ROUND_ROBIN
  46. typed_extension_protocol_options:
  47. envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
  48. "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
  49. explicit_http_config:
  50. http2_protocol_options:
  51. connection_keepalive:
  52. interval: 30s
  53. timeout: 5s
  54. upstream_connection_options:
  55. # configure a TCP keep-alive to detect and reconnect to the admin
  56. # server in the event of a TCP socket half open connection
  57. tcp_keepalive: {}
  58. load_assignment:
  59. cluster_name: xds_cluster
  60. endpoints:
  61. - lb_endpoints:
  62. - endpoint:
  63. address:
  64. socket_address:
  65. address: 127.0.0.1
  66. port_value: 5678

Notice above that xds_cluster is defined to point Envoy at the management server. Even in an otherwise completely dynamic configurations, some static resources need to be defined to point Envoy at its xDS management server(s).

It’s important to set appropriate TCP Keep-Alive options in the tcp_keepalive block. This will help detect TCP half open connections to the xDS management server and re-establish a full connection.

In the above example, the EDS management server could then return a proto encoding of a DiscoveryResponse:

  1. version_info: "0"
  2. resources:
  3. - "@type": type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment
  4. cluster_name: some_service
  5. endpoints:
  6. - lb_endpoints:
  7. - endpoint:
  8. address:
  9. socket_address:
  10. address: 127.0.0.1
  11. port_value: 1234

The versioning and type URL scheme that appear above are explained in more detail in the streaming gRPC subscription protocol documentation.

Dynamic

A fully dynamic bootstrap configuration, in which all resources other than those belonging to the management server are discovered via xDS is provided below:

  1. admin:
  2. address:
  3. socket_address: { address: 127.0.0.1, port_value: 9901 }
  4. dynamic_resources:
  5. lds_config:
  6. resource_api_version: V3
  7. api_config_source:
  8. api_type: GRPC
  9. transport_api_version: V3
  10. grpc_services:
  11. - envoy_grpc:
  12. cluster_name: xds_cluster
  13. cds_config:
  14. resource_api_version: V3
  15. api_config_source:
  16. api_type: GRPC
  17. transport_api_version: V3
  18. grpc_services:
  19. - envoy_grpc:
  20. cluster_name: xds_cluster
  21. static_resources:
  22. clusters:
  23. - name: xds_cluster
  24. connect_timeout: 0.25s
  25. type: STATIC
  26. lb_policy: ROUND_ROBIN
  27. typed_extension_protocol_options:
  28. envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
  29. "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
  30. explicit_http_config:
  31. http2_protocol_options:
  32. # Configure an HTTP/2 keep-alive to detect connection issues and reconnect
  33. # to the admin server if the connection is no longer responsive.
  34. connection_keepalive:
  35. interval: 30s
  36. timeout: 5s
  37. load_assignment:
  38. cluster_name: xds_cluster
  39. endpoints:
  40. - lb_endpoints:
  41. - endpoint:
  42. address:
  43. socket_address:
  44. address: 127.0.0.1
  45. port_value: 5678

The management server could respond to LDS requests with:

  1. version_info: "0"
  2. resources:
  3. - "@type": type.googleapis.com/envoy.config.listener.v3.Listener
  4. name: listener_0
  5. address:
  6. socket_address:
  7. address: 127.0.0.1
  8. port_value: 10000
  9. filter_chains:
  10. - filters:
  11. - name: envoy.filters.network.http_connection_manager
  12. typed_config:
  13. "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
  14. stat_prefix: ingress_http
  15. codec_type: AUTO
  16. rds:
  17. route_config_name: local_route
  18. config_source:
  19. resource_api_version: V3
  20. api_config_source:
  21. api_type: GRPC
  22. transport_api_version: V3
  23. grpc_services:
  24. - envoy_grpc:
  25. cluster_name: xds_cluster
  26. http_filters:
  27. - name: envoy.filters.http.router
  28. typed_config:
  29. "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

The management server could respond to RDS requests with:

  1. version_info: "0"
  2. resources:
  3. - "@type": type.googleapis.com/envoy.config.route.v3.RouteConfiguration
  4. name: local_route
  5. virtual_hosts:
  6. - name: local_service
  7. domains: ["*"]
  8. routes:
  9. - match: { prefix: "/" }
  10. route: { cluster: some_service }

The management server could respond to CDS requests with:

  1. version_info: "0"
  2. resources:
  3. - "@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
  4. name: some_service
  5. connect_timeout: 0.25s
  6. lb_policy: ROUND_ROBIN
  7. type: EDS
  8. eds_cluster_config:
  9. eds_config:
  10. resource_api_version: V3
  11. api_config_source:
  12. api_type: GRPC
  13. transport_api_version: V3
  14. grpc_services:
  15. - envoy_grpc:
  16. cluster_name: xds_cluster

The management server could respond to EDS requests with:

  1. version_info: "0"
  2. resources:
  3. - "@type": type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment
  4. cluster_name: some_service
  5. endpoints:
  6. - lb_endpoints:
  7. - endpoint:
  8. address:
  9. socket_address:
  10. address: 127.0.0.1
  11. port_value: 1234

Special YAML usage

When loading YAML configuration, the Envoy loader will interpret map keys tagged with !ignore specially, and omit them entirely from the native configuration tree. Ordinarily, the YAML stream must adhere strictly to the proto schemas defined for Envoy configuration. This allows content to be declared that is explicitly handled as a non-represented type.

This lets you split your file into two parts: one in which we have YAML content not subject to parsing according to the schema and another part that is parsed. YAML anchors in the first part may be referenced by aliases in the second part. This mechanism can simplify setups that need to re-use or dynamically generate configuration fragments.

See the following example:

  1. !ignore dynamic_sockets:
  2. - &admin_address {address: 127.0.0.1, port_value: 9901}
  3. - &listener_address {address: 127.0.0.1, port_value: 10000}
  4. - &lb_address {address: 127.0.0.1, port_value: 1234}
  5. admin:
  6. address:
  7. socket_address: *admin_address
  8. static_resources:
  9. listeners:
  10. - name: listener_0
  11. address:
  12. socket_address: *listener_address
  13. filter_chains:
  14. - filters:
  15. - name: envoy.filters.network.http_connection_manager
  16. typed_config:
  17. "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
  18. stat_prefix: ingress_http
  19. codec_type: AUTO
  20. route_config:
  21. name: local_route
  22. virtual_hosts:
  23. - name: local_service
  24. domains: ["*"]
  25. routes:
  26. - match: {prefix: "/"}
  27. route: {cluster: some_service}
  28. http_filters:
  29. - name: envoy.filters.http.router
  30. typed_config:
  31. "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  32. clusters:
  33. - name: some_service
  34. connect_timeout: 0.25s
  35. type: STATIC
  36. lb_policy: ROUND_ROBIN
  37. load_assignment:
  38. cluster_name: some_service
  39. endpoints:
  40. - lb_endpoints:
  41. - endpoint:
  42. address:
  43. socket_address: *lb_address

Warning

If you parse Envoy YAML configuration using external loaders, you may need to inform these loaders about the !ignore tag. Compliant YAML loaders will typically expose an interface to allow you to choose how to handle a custom tag.

For example, this will instruct PyYAML to treat an ignored node as a simple scalar when loading:

  1. yaml.SafeLoader.add_constructor('!ignore', yaml.loader.SafeConstructor.construct_scalar)

Alternatively, this is how Envoy registers the !ignore tag in config validation.