3

I'd like to define in Openshift one route with multiple paths, each path forwarding to a different service. For example /pathA would forward requests to ServiceA , whilst /pathB would forward requests to ServiceB.

Is this possible in OpenShift? If not, what would be the recommended approach?

I have also read about route sharding, however I cannot say that I've grasped the concept clearly.

Thanks.

theAsker
  • 385
  • 2
  • 11

1 Answers1

4

You need to create multiple routes per each path. But it can add multiple paths to same hostname. It's a same result of one route with multiple path you said. Refer Path Based Routes for more details.

For ServiceA,

apiVersion: v1
kind: Route
metadata:
  name: route-path-a
spec:
  host: www.example.com
  path: "/patha"   
  to:
    kind: Service
    name: service-a

For ServiceB,

apiVersion: v1
kind: Route
metadata:
  name: route-path-b
spec:
  host: www.example.com
  path: "/pathb"   
  to:
    kind: Service
    name: service-b
Daein Park
  • 3,601
  • 2
  • 7
  • 16
  • Does this work even if the Services have multiple paths for different apis? For example for ServiceA: www.example.com/patha/apiA and www.example.com/patha/apiB – theAsker May 16 '19 at 14:35
  • 1
    `Routes` doe not aware whether or not the `Services` have multiple paths, it just forward the request to them through the path rules. – Daein Park May 16 '19 at 14:40
  • Thank you for your help. I implemented the routing using your approach, however I have come across a new problem. When sending the request to www.example.com/patha/apiA , the ServiceA will receive a request to /patha/apiA instead of just /apiA . – theAsker May 16 '19 at 14:47
  • Do you expect the just `/apiA` , when `/patha/apiA` is requested ? – Daein Park May 16 '19 at 15:11
  • Exactly, my service expects only /apiA .I consider /patha as being part of the service selector – theAsker May 16 '19 at 16:14
  • Unfortunately, as I mentioned above, `Routes` just forward the requests to `Services` with the path requested as it is. – Daein Park May 16 '19 at 20:41