I want to use the same hostname e.g. example.com in two different namespaces with different paths. e.g. in namespace A I want example.com/clientA and in namespace B I want example.com/clientB. Any ideas on how to achieve this?
-
1that very much depends on the implementation of your ingress controller. – Markus Dresch Sep 22 '20 at 08:30
-
my ingress-controller is in the default namespace – devcloud Sep 22 '20 at 08:59
-
1that's alright, but ingress-controllers behave very differently. i for example rolled my own based on ProxyKit and i pull all ingress rules and route accordingly. depending on which ingress-controller you use, the behaviour may be very different. some may have this out of the box, some may need an `ExternalService` to talk to a different namespace. – Markus Dresch Sep 22 '20 at 09:02
-
i see. i am using nginx-inress controller. the app runs fine in one namespace e.g example.com but in the other namespace i want same host name but different path like example.com/clientname – devcloud Sep 22 '20 at 09:08
2 Answers
nginxinc has Cross-Namespace Configuration feature that allows you do exactly what you described. You can also find there prepared examples with deployments, services, etc.
The only thing you most probably wont like..nginxinc is not free..
Also look here
Cross-namespace Configuration You can spread the Ingress configuration for a common host across multiple Ingress resources using Mergeable Ingress resources. Such resources can belong to the same or different namespaces. This enables easier management when using a large number of paths. See the Mergeable Ingress Resources example on our GitHub.
As an alternative to Mergeable Ingress resources, you can use VirtualServer and VirtualServerRoute resources for cross-namespace configuration. See the Cross-Namespace Configuration example on our GitHub.

- 7,740
- 15
- 40
If you do not want to change your default ingress controller (nginx-ingress), another option is to define a service of type ExternalName
in your default namespace that points to the full internal service name of the service in the other namespace.
Something like this:
apiVersion: v1
kind: Service
metadata:
labels:
app: my-svc
name: webapp
namespace: default
spec:
externalName: my-svc.my-namespace.svc # <-- put your service name with namespace here
type: ExternalName

- 5,290
- 3
- 20
- 40