title: Kubernetes nginx route traffic to /api/*
body: <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>