<p>I would like to route certain paths of my host to a different backend.</p>
<p>Assuming I have 2 backend services:</p>
<ul>
<li>backend-one</li>
<li>backend-two</li>
</ul>
<p>All of the requests were routed to <code>backend-one</code> initially, like in the example below.</p>
<pre><code>rules:
    - host: example.com
      http:
        paths:
          - path: /
            backend:
              serviceName: backend-one
              servicePort: 3000
</code></pre>
<p>Now, I have <code>backend-two</code> as the new service, which should be serving content for specific paths, but most importantly the <code>/</code> (root) page as well.</p>
<p>So, my goal would be the following:</p>
<ul>
<li>Paths <code>/</code>, <code>/abc</code>, <code>/xyz</code>, <code>/12345</code> to be served by ====&gt; <code>backend-two</code> (the new service).</li>
<li>Everything else to be served by <code>backend-one</code> the old service.</li>
</ul>
<p>What would be the simplest approach for achieving this?</p>

Andrei Gaspar
<p>As per Kubernetes <a href="https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.18.md#extending-ingress-with-and-replacing-a-deprecated-annotation-with-ingressclass" rel="noreferrer">CHANGELOG-1.18.md</a>:</p>
<blockquote>
<p>In Kubernetes 1.18, there are two significant additions to Ingress: A
new <code>pathType</code> field and a new <code>IngressClass</code> resource. The <code>pathType</code>
field allows specifying how paths should be matched. In addition to
the default <code>ImplementationSpecific</code> type, there are new <code>Exact</code> and
<code>Prefix</code> path types.</p>
</blockquote>
<p>You can use Kubernetes 1.18+ with <a href="https://v1-18.docs.kubernetes.io/docs/concepts/services-networking/ingress/#path-types" rel="noreferrer">Path types</a> to achieve what you want. Use the following config:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
  - host: example.com
    http:
      paths:
      # Proxy to backend-two when the request is EXACT the root path
      - path: /
        pathType: Exact
        backend:
          serviceName: backend-two
          servicePort: 3000
      # Proxy specic paths (including subpaths) to backend-two
      - path: /abc
        pathType: Prefix
        backend:
          serviceName: backend-two
          servicePort: 3000
      - path: /xyz
        pathType: Prefix
        backend:
          serviceName: backend-two
          servicePort: 3000
      - path: /12345
        pathType: Prefix
        backend:
          serviceName: backend-two
          servicePort: 3000
      # If no rules above match, Proxy to backend-one
      - path: /
        pathType: Prefix
        backend:
          serviceName: backend-one
          servicePort: 3000
</code></pre>
<p>Remember that you can also use <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/#regular-expression-support" rel="noreferrer">Regular Expressions</a> to improve your Ingress config in case you have multiple paths to handle.</p>
