<p>I want to use the same hostname let's say <code>example.com</code> with multiple Ingress resources running in different namespaces i.e <code>monitoring</code> and <code>myapp</code>. I'm using <strong>Kubernetes nginx-ingress</strong> controller.</p>
<p><strong>haproxy-ingress.yaml</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: haproxy-ingress
  namespace: myapp
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;  
spec:
  tls:
  - hosts:
    # fill in host here
    - example.com
    
  rules:
    - host: example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: haproxy
                port:
                  number: 80

</code></pre>
<p><strong>grafana-ingress.yaml</strong></p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana-ingress
  namespace: monitoring
  annotations:
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  tls:
  - hosts:
    - example.com
    
  rules:
    - host: example.com
      http:
        paths:
          # only match /grafana and paths under /grafana/
          - path: /grafana(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: grafana
                port:
                  number: 3000

</code></pre>
<p>When I'm doing <code>curl example.com</code> then it is redirecting me to the deployment running in namespace one(as expected) but when I'm doing <code>curl example.com/grafana</code> then still it is redirecting me to namespace one deployment.</p>
<p>Please help.</p>

metadata
<p>Yes it is possible.</p>
<p>There can be two issues in your case.</p>
<p>One is you don't need the regex path for grafana ingress. Simple <code>/grafana</code> path will be fine with path type <code>Prefix</code> as with path type <code>Prefix</code> any <code>/grafana/...</code> will be redirected associated service. So the manifest file will be:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana-ingress
  namespace: monitoring
spec:
  tls:
  - hosts:
    - example.com
    
  rules:
    - host: example.com
      http:
        paths:
          - path: /grafana
            pathType: Prefix
            backend:
              service:
                name: grafana
                port:
                  number: 3000

</code></pre>
<p>And the second issue can be the related service or deployment might not be the under same namespace <code>monitoring</code>. Please make sure the deployment/service/secret or other resources needed for grafana remains under the same namespace <code>monitoring</code>.</p>
