It is possible to use same host in different namespaces on Openshift Origin?

2.5k views Asked by At

I have some projects that respond on same host but different path. I want to keep them separated in Openshift. Ie.:

First service

apiVersion: v1
kind: Route
metadata:
  name: first-api
  namespace: first-api
  labels:
    app: first-api
spec:
  host: api.com.br
  path: /first
  to:
    kind: Service
    name: first-api
  port:
    targetPort: tcp-8080

Second setvice

apiVersion: v1
kind: Route
metadata:
  name: second-api
  namespace: second-api
  labels:
    app: second-api
spec:
  host: api.com.br
  path: /second
  to:
    kind: Service
    name: second-api
  port:
    targetPort: tcp-8080
3

There are 3 answers

0
Clayton On

There are security restrictions enforced in the OpenShift router that prevent hosts in different namespaces from overlapping (the oldest route "claims" the name). We'd like to add more flexibility to disable this check in the future.

0
mirekphd On

This HostAlreadyClaimed error occurs usually in manually specified host names (defined using spec.host in Route configs). If you let host names to be created automatically, HAProxy will never create such name collisions.

0
jpm290 On

You should be able to do this by setting "InterNamespaceAllowed" on the ingresscontroller. This is done by running the following command:

oc -n openshift-ingress-operator patch ingresscontroller/default --patch '{"spec":{"routeAdmission":{"namespaceOwnership":"InterNamespaceAllowed"}}}' --type=merge

For more info, see: https://docs.openshift.com/container-platform/4.10/networking/routes/route-configuration.html#nw-route-admission-policy_route-configuration