Disclaimer: The information provided in this technical solution is for general informational purposes only. It is provided "as is" without any warranties of any kind, either express or implied. The use of this solution is at your own risk, and I do not assume any responsibility or liability for any errors, omissions, or results obtained from the use of this information. Additionally, I disclaim any and all responsibility or liability for any damages or losses, including but not limited to, direct, indirect, incidental, special, or consequential damages arising out of or in connection with the use of or reliance on this technical solution. Users are encouraged to verify any information before relying on it and to consult with appropriate professionals or experts as needed.
This is a demo of how the Consul API gateway can be used with Service-Resolvers to route traffic based on headers to different subsets of the same backend service. This is a workaround as this is not supported natively using API Gateway.
- Consul (tested on 1.8.2)
- Supported Envoy Binary
- Fakeservice (https://github.com/nicholasjackson/fake-service)
The consul.hcl
has all the required config-entries and service registrations (with meta).
- Start Consul Agent
consul agent -dev -config-file consul.hcl
- Start Consul API Gateway
consul connect envoy -gateway api -service jeff-apigw0 -register
- Start the
blue
instance of DMZ service
LISTEN_ADDR=127.0.0.1:9090 MESSAGE=BLUE fake-service
- Start the sidecar for
blue
instance of DMZ service
consul connect envoy -sidecar-for dmz-blue -admin-bind localhost:19001
- Start the
green
instance of DMZ service
LISTEN_ADDR=127.0.0.1:9091 MESSAGE=GREEN fake-service
- Start the sidecar for
blue
instance of DMZ service
consul connect envoy -sidecar-for dmz-green -admin-bind localhost:19002
curl -H "color: blue" localhost:8443
{
"name": "Service",
"uri": "/",
"type": "HTTP",
"ip_addresses": [
"192.168.104.6",
"172.17.0.1",
"172.21.0.1"
],
"start_time": "2024-08-29T17:46:56.915651",
"end_time": "2024-08-29T17:46:56.915853",
"duration": "202.629µs",
"body": "BLUE",
"code": 200
}
curl -H "color: green" localhost:8443 17:46:54 [0/0]
{
"name": "Service",
"uri": "/",
"type": "HTTP",
"ip_addresses": [
"192.168.104.6",
"172.17.0.1",
"172.21.0.1"
],
"start_time": "2024-08-29T17:46:51.854916",
"end_time": "2024-08-29T17:46:51.855124",
"duration": "207.396µs",
"body": "GREEN",
"code": 200
}