<p>I have a kubernetes cluster with configured nginx to port traffic to my angular application.
It is working fine, however when I access the <code>myipaddress/api/v1</code> - I want nginx to port the traffic to my express application which is listening on port 3000 and the angular application not to look the <code>myipaddress/api/v1</code> as a route component in angular as it doesn't exist.</p>
<p>Here's my kubernetes nginx ingress for express</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: backend
spec:
  type: ClusterIP
  ports:
  - port: 3000
    targetPort: 3000
  selector:
    app: backend

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: backend-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /api/?(.*)
        pathType: Prefix
        backend:
          service:
            name: backend
            port:
              number: 3000
</code></pre>
<p>Here's my ingress for angular</p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: webapp
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: webapp

--- 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: webapp-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: webapp
            port:
              number: 80
</code></pre>
<p>What I am trying to achieve for angular</p>
<pre><code>myipaddres.com        -&gt; serve angular application`
myipaddress.com/users -&gt; serve angular router for /users

</code></pre>
<p>What I am trying to achieve for express:</p>
<pre><code>myipaddress.com/api/v1/users -&gt; call the users v1 endpoint in express
myipaddress.com/api/v2/users -&gt; call the users v2 endpoint in express
</code></pre>

<p>Ok I managed to find the solution myself, posting this in case someone needs it.
The newest api for kubernetes (up to date of posting this) supports regex but you should explicitly enable it with annotation.</p>
<pre><code>---
# ingress traffic
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: backend-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot; # enabling regex annotation
spec:
  rules:
  - http:
      paths:
      - path: /api/*      # works fine with regex enabled
        pathType: Prefix
        backend:
          service:
            name: backend
            port:
              number: 3000
</code></pre>
<p>The same applies for any other ingress path you need to reverse proxy.</p>
