<p>We have a Kubernetes cluster with an nginx controller.
We are using this nginx controller to route different paths to different services. Though,
when a service is on a different namespace, I cannot figure out how to redirect to it.</p>
<p>This is the nginx configuration</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: gateway-ingress
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    kubernetes.io/tls-acme: 'true'
    nginx.ingress.kubernetes.io/proxy-body-size: &quot;0&quot;
    nginx.ingress.kubernetes.io/proxy-read-timeout: &quot;600&quot;
    nginx.ingress.kubernetes.io/proxy-send-timeout: &quot;600&quot;
    nginx.ingress.kubernetes.io/enable-cors: &quot;true&quot;
    nginx.ingress.kubernetes.io/cors-allow-methods: &quot;*&quot;
    nginx.ingress.kubernetes.io/cors-allow-headers: &quot;*&quot;
    nginx.ingress.kubernetes.io/cors-allow-origin: &quot;*&quot;
    nginx.ingress.kubernetes.io/service-upstream: &quot;true&quot;
spec:
  rules:
    - host: MY_BACKEND.MY_DOMAIN.com
      http:
        paths:
          - pathType: Prefix
            path: &quot;/&quot;
            backend:
              service:
                name: my-backend
                port:
                  number: 3001

    - host: MY_FRONTEND.MY_DOMAIN.com
      http:
        paths:
          - pathType: Prefix
            path: &quot;/&quot;
            backend:
              service:
                name: my-frontend
                port:
                  number: 3000
  ...
</code></pre>
<p>The above snippet works perfectly, but it is worth to mention that both services <code>my-backend</code> and <code>my-frontend</code> are running on <code>default</code> namespace.
We have then deployed a Jenkins instance on namespace <code>jenkins</code>. My first attempty was to simply add</p>
<pre class="lang-yaml prettyprint-override"><code>    - host: MY_JENKINS.MY_DOMAIN.com
      http:
        paths:
          - pathType: Prefix
            path: &quot;/&quot;
            backend:
              service:
                name: jenkins-service
                port:
                  number: 8080
</code></pre>
<p>Though when browsing on <code>MY_JENKINS.MY_DOMAIN.com</code> I get a 503 Service Temporary Unavailable. Could it be because it is running on a different namespace? Namely jenkins?</p>
<p>Normally in order to connect on different namespaces I just use the standard <code>service.namespace</code>. Though here when trying I get a standard console error/warning</p>
<p><code>The Ingress &quot;gateway-ingress&quot; is invalid: spec.rules[16].http.paths[0].backend.service.name: Invalid value: &quot;WHATEVER_VALUE_WRITTEN&quot;: a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name',  or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')</code></p>
<p>I tried: service.namespace, namespace.service, namespace/service, service/namespace. All the attempts and up on the same error message.</p>
<p>How can I instruct nginx-controller to connect to a service that is in a specific namespace?</p>

purple_lolakos
<p>You can reach a service from another namespace with: <code>&lt;service&gt;.&lt;namespace&gt;</code>; by bypassing the service you can also reach other pods by their ip address (even in another namespace).</p>
<p><strong>But</strong> afaik all ingress controllers (also nginx) per default do not allow multi-namespace ingress out of security reasons.</p>
<p>For nginx you can configure ingress across multiple namespaces with a master/minion approach. You have to add the <code>nginx.org/mergeable-ingress-type</code>-annotation to your Ingress resources.</p>
<p>A master processes configuration on the host and minions provide the ingress resources.</p>
<p>Find more info here: <a href="https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/cross-namespace-configuration/" rel="nofollow noreferrer">https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/cross-namespace-configuration/</a></p>
<p>And here:
<a href="https://github.com/nginxinc/kubernetes-ingress/tree/v2.2.1/examples/mergeable-ingress-types" rel="nofollow noreferrer">https://github.com/nginxinc/kubernetes-ingress/tree/v2.2.1/examples/mergeable-ingress-types</a></p>
