<p>This might look like a <a href="https://stackoverflow.com/questions/62496338/app-on-path-instead-of-root-not-working-for-kubernetes-ingress">duplicate</a> but it isn't as the solution in the linked thread doesn't work for me.</p>
<p>I have Ingress configured to dispatch requests to different pods based on the path</p>
<p>Desired behavior:</p>
<p>public_ip/app1 -&gt; pod1_ip:container1_port/<br />
public_ip/app2 -&gt; pod2_ip:container2_port/<br />
public_ip/app3 -&gt; pod3_ip:container3_port/</p>
<p>Actual behavior:</p>
<p>public_ip/app1 -&gt; pod1_ip:container1_port/app1<br />
public_ip/app2 -&gt; pod2_ip:container2_port/app2<br />
public_ip/app3 -&gt; pod3_ip:container3_port/app3</p>
<p>So we get 404's on app1, app2, app3</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: some_name
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    acme.cert-manager.io/http01-edit-in-place: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  ingressClassName: &quot;nginx&quot;
  tls:
  - hosts:
    - some.host
    secretName: tls-cafe-ingress
  rules:
  - host: some.host
    http:
      paths:
      - path: /app1(/|$)(.*)
        backend:
          serviceName: app1
          servicePort: 1234
      - path: /app2(/|$)(.*)
        backend:
          serviceName: app2
          servicePort: 2345
      - path: /app3(/|$)(.*)
        backend:
          serviceName: app3
          servicePort: 3456
</code></pre>
<p>The problem is that Ingress igores the path specifications once there are regular expressions in it. This can be seen by checking the logs of Ingress:</p>
<pre><code>k logs -n nginx-ingress ingress-pod-name
</code></pre>
<p>Here we can see hat nginx has requests to /appX in the log and tries to serve them form the local html folder, in other words, the path defined in the yaml are ignored.</p>
<p>If regexes are removed from the path it works but then the path is sent downstream to the target pod which breaks the application</p>

<p>There are two popular K8s Ingress controller that uses Nginx:</p>
<ul>
<li>One is maintained by open source community
(<a href="https://github.com/kubernetes/ingress-nginx" rel="nofollow noreferrer">kubernetes/ingress-nginx</a>)
and we use to call it <code>community ingress controller</code></li>
<li>Second is maintained by NGINX and its called
<a href="https://github.com/nginxinc/kubernetes-ingress" rel="nofollow noreferrer">nginxinc/kubernetes-ingress</a></li>
</ul>
<p>The key difference that apply in this case is the use of annotation. For the community ingress controller you use:</p>
<p><code>nginx.ingress.kubernetes.io/&lt;annotation_type&gt;</code></p>
<p>And for nginxinc uses:</p>
<pre><code>nginx.org/&lt;annoation_type&gt; 
</code></pre>
<p>To check more about  differences please visit <a href="https://github.com/nginxinc/kubernetes-ingress/blob/master/docs/nginx-ingress-controllers.md" rel="nofollow noreferrer">this</a> document.</p>
