<p>I'm currently in the process of setting up a Kubernetes AKS cluster, mostly for learning purposes for myself and as a proof of concept. My goal is like this:</p>
<ul>
<li>CI / CD with Azure DevOps
<ul>
<li>Every commit to the master-branch triggers an automated release to Kubernetes in the namespace &quot;production&quot;</li>
<li>Every commit to a non-master-branch triggers an automated release to Kubernetes in the namespace &quot;development&quot;</li>
</ul>
</li>
<li>Kubernetes management
<ul>
<li>Resources are created via Helm</li>
<li>Azure DevOps task is used to deploy these resources in combination with variable-groups per environment</li>
</ul>
</li>
<li>Application
<ul>
<li>Simple MVC app</li>
<li>Real database outside of Kubernetes, Azure SQL Server</li>
</ul>
</li>
</ul>
<p>Now, everything works smoothly, but I really struggle with the logical concept of &quot;namespaces as environments&quot;. I know, this isn't a great idea in the first place, as for example, the development-environment could use up all the resources. But as I'm hosting stuff myself, I didn't want to create multiple clusters and I think for starters, having namespaces as environments is reasonable.
My problem comes with the routing: my pretty naive approach is explained here <a href="https://stackoverflow.com/questions/51878195/kubernetes-cross-namespace-ingress-network/51899301#51899301.">Kubernetes Cross Namespace Ingress Network</a>:</p>
<ul>
<li>One ingress in the default namespace</li>
<li>Per environment, one ExternalName-Service in the default namespace with a suffix, targetting the CNAME of the service in the other namespaces</li>
<li>Per environment namespace, one ClusterIP service</li>
</ul>
<p>The ingress looks like this:</p>
<pre class="lang-yaml prettyprint-override"><code>  rules:
    - host: 09ab799fd5674c4594a5.centralus.aksapp.io
      http:
        paths:
          - path: /dev
            pathType: Prefix
            backend:
              service:
                name: {{include &quot;helmakskubernetespoc-chart.fullname&quot; .}}external{{ .Values.namespaces.development }}
                port:
                  number: {{ .Values.externalService.port }}
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{ include &quot;helmakskubernetespoc-chart.fullname&quot; .}}external{{ .Values.namespaces.production }}
                port:
                  number: {{ .Values.externalService.port }}
</code></pre>
<p>My goal being, that no subroute targets production and the subroute /dev targeting development.</p>
<p>This works as long as there isn't a subroute aka for production. But as I've learned here <a href="https://stackoverflow.com/questions/52021925/kubernetes-ingress-non-root-path-404-not-found">Kubernetes Ingress non-root path 404 Not Found</a>, the ingress takes the route and passes it 1:1 to the internal service. As my little MVC app doesn't know &quot;/dev&quot;, I get a 404.
So far so good, I can change this via annotation:</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target: /
</code></pre>
<p>Now, every call to /dev does in fact route to the correct app, BUT every click on a button routes back to production, as the initially added /dev is lost. Also, trying this one <a href="https://stackoverflow.com/questions/72775105/ingress-dont-load-the-website-assets-css-files-and-javascript-files/72776490">Ingress don&#39;t load the website assets (Css files and Javascript files)</a>, I have the same problem.</p>
<p>I'm wondering if I'm conceptually making a mistake: Ingress rules are, as far as I know, only working with subroutes, therefore I can't for example use a port. Is possibly ingress the wrong way to split the environments? As the MVC app either never receives the /dev or doesn't know what to do with it, I don't see an elegant solution for this problem?</p>

Matthias Müller
<p>You probably wanna use different hosts per environment. Something like:</p>
<pre><code>rules:
    - host: dev.09ab799fd5674c4594a5.centralus.aksapp.io
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{include &quot;helmakskubernetespoc-chart.fullname&quot; .}}external{{ .Values.namespaces.development }}
                port:
                  number: {{ .Values.externalService.port }}
    - host: 09ab799fd5674c4594a5.centralus.aksapp.io
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{ include &quot;helmakskubernetespoc-chart.fullname&quot; .}}external{{ .Values.namespaces.production }}
                port:
                  number: {{ .Values.externalService.port }}
</code></pre>
