<p>Im struggling with the ingress configuration that will allow accessibility from two <strong>different paths</strong> to services which are deployed on <strong>different namespaces</strong>.</p>

<p>1# Ingress:</p>

<pre><code>    # Source: deployment/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: portal-api
  labels:
    helm.sh/chart: deployment-0.1.0
    app.kubernetes.io/name: deployment
    app.kubernetes.io/instance: portal-api
    app.kubernetes.io/version: "0.0.1"
    app.kubernetes.io/managed-by: Helm
  annotations:
    certmanager.k8s.io/acme-challenge-type: http01
    certmanager.k8s.io/cluster-issuer: letsencrypt-prod
    kuberentes.io/tls-acme: "true"
    kubernetes.io/ingress.class: nginx
spec:
  tls:
    - hosts:
        - "example.com"
      secretName: portal-certificate
  rules:
    - host: "example.com"
      http:
        paths:
          - path: /api/rest/(.*)
            backend:
              serviceName: portal-api
              servicePort: 80
</code></pre>

<h1>2 Ingress</h1>

<pre><code># Source: deployment/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: portal-ui
  labels:
    helm.sh/chart: deployment-0.1.0
    app.kubernetes.io/name: deployment
    app.kubernetes.io/instance: portal-ui
    app.kubernetes.io/version: "0.0.1"
    app.kubernetes.io/managed-by: Helm
  annotations:
    certmanager.k8s.io/acme-challenge-type: http01
    certmanager.k8s.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  tls:
    - hosts:
        - "example.com"
      secretName: portal-certificate
  rules:
    - host: "example.com"
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: portal-ui
              servicePort: 80
</code></pre>

<p>Routing for path example.com - works, its redirect to portal-ui.
Routing for path example.com/api/rest/(something) - doesnt works, its redirect to portal-ui service.</p>

<p>I think that It will works on the same namespace... But i need two namespaces for each service.</p>

TeK
<p>As @Arghya Sadhu mentioned</p>
<blockquote>
<p>Ingress and its corresponding service need to be in same namespace otherwise ingress cannot discover endpoints from the service.</p>
</blockquote>
<p>There is a <a href="https://github.com/kubernetes/kubernetes/issues/17088" rel="nofollow noreferrer">github issue</a> opened since 2015 and there is still discuss how to make it work.</p>
<p>For now it´s <strong>either to create ingress in the same namespace</strong></p>
<p><strong>Example made by github issue member @aledbf</strong></p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: component1
  namespace: component1
spec:
  rules:
  - host: domain.com
    http:
      paths:
      - backend:
          serviceName: component1
          servicePort: 80
        path: /component1
apiVersion: extensions/v1beta1


kind: Ingress
metadata:
  name: component2
  namespace: component2
spec:
  rules:
  - host: domain.com
    http:
      paths:
      - backend:
          serviceName: component2
          servicePort: 80
        path: /component2
</code></pre>
<hr />
<p><strong>OR</strong></p>
<hr />
<p><strong>You could try <a href="https://github.com/kubernetes/kubernetes/issues/17088#issuecomment-394313647" rel="nofollow noreferrer">workaround</a> made by github issue member @chestack</strong></p>
<blockquote>
<p>my workaround:</p>
<p>serviceA in namespaceA</p>
<p>create serviceB in namespaceB</p>
</blockquote>
<pre><code>spec:
    ...
    type: ExtertalName
    externalName: serviceA.namespaceA.svc.cluster.local
</code></pre>
<blockquote>
<p>add ingress rule into ingressB in namespaceB</p>
</blockquote>
<pre><code>- path: /****
        backend:
          serviceName: serviceB
          servicePort: ***
</code></pre>
