HI have been playing around with the learn-consul-canary repo from hashicorp education. I extended this and created a service router for the frontend. The service router uses query parameter to decide to route to V1 or V2 front end. This all works fine and i can seamlessly hit either version of my choosing using this. The flow in the hashicups is,
api-gateway → nginx - > front-end
ubuntu@cdoyle-consul:~/learn-consul-canary-deployments$ curl -s http://localhost:32321/?version=v1 | sed -n 's/.*\(HashiCups-v[0-9]\+\).*/\1/p'; echo
HashiCups-v1
ubuntu@cdoyle-consul:~/learn-consul-canary-deployments$ curl -s http://localhost:32321/?version=v2 | sed -n 's/.*\(HashiCups-v[0-9]\+\).*/\1/p'; echo
HashiCups-v2
I then wanted to try removing nginx for the routing and instead just use API gateway to route to the frontend service. However when i do this the gateway doesnt setup the route when there is a service router applied on the service, if i remove the service router then gateway will start routing.
Is there a way to define a route in api-gateway that will use the service router logic to decide which service instance to route too?
config files are
ubuntu@cdoyle-consul:~/learn-consul-canary-deployments$ cat k8s-yamls/frontend-resolver.yaml
apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceResolver
metadata:
name: frontend
spec:
defaultSubset: v1
subsets:
v1:
filter: 'Service.Meta.version == 1'
v2:
filter: 'Service.Meta.version == 2'
ubuntu@cdoyle-consul:~/learn-consul-canary-deployments$ cat k8s-yamls/frontend-router.yaml
apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceRouter
metadata:
name: frontend
spec:
routes:
- match:
http:
queryParam:
- name: "version"
exact: "v1"
destination:
service: frontend
serviceSubset: v1
- match:
http:
queryParam:
- name: "version"
exact: "v2"
destination:
service: frontend
serviceSubset: v2
ubuntu@cdoyle-consul:~/learn-consul-canary-deployments$ cat temp_http_route.yaml
---
apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceIntentions
metadata:
name: api-gateway-hashicups-2
spec:
destination:
name: frontend
sources:
- name: api-gateway
action: allow
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: route-root2
namespace: default
spec:
parentRefs:
- name: api-gateway
namespace: consul
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- kind: Service
name: frontend
port: 3000