<p>In Kubernetes we need a new service to handle the root path, but but still a catch everything else on our current frontend.</p>
<p>Current frontend Ingress</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: current-frontend
  labels:
    app: current-frontend
    tier: frontend
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  tls:
    - hosts:
      - my.domain.com
      secretName: tls-secret
  rules:
    - host: my.domain.com
      http:
        paths:
          - backend:
              service:
                name: current-frontend
                port:
                  number: 80
            path: /
            pathType: Prefix
</code></pre>
<p>New service Ingress</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: new-service
  labels:
    app: new-service
    tier: frontend
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  tls:
  - hosts:
    - my.domain.com
    secretName: tls-secret
  rules:
  - host: my.domain.com
    http:
      paths:
      - backend:
          service:
            name: new-service
            port:
              number: 80
        path: /someendpoint
        pathType: ImplementationSpecific
      - backend:
          service:
            name: new-service
            port:
              number: 80
        path: /
        pathType: Exact
</code></pre>
<p>According to the documentation of Kuberntes Ingress, it should prioritize Exact over Prefix</p>
<blockquote>
<p>If two paths are still equally matched, precedence will be given to paths with an exact path type over prefix path type.</p>
</blockquote>
<p><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#multiple-matches" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/ingress/#multiple-matches</a></p>
<p>The problem is that everything else then my.domain.com/someendpoint goes to the current-frontend, while the expected would be that my.domain.com/ would go to new-service.</p>
<p>How do I achieving this?</p>
<hr />
<p><strong>Solution</strong></p>
<p>I got it working, even If it doesn't seams to be the optimal solution (According to the Documentation)</p>
<p>I Followed Hemanth Kumar's answer and changed the Current Frontend to use Regex, with (.+) instead of (.*) as I wanted at least one char after the slash for it to be hit.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: current-frontend
  labels:
    app: current-frontend
    tier: frontend
  annotations:
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    kubernetes.io/ingress.class: nginx
spec:
  tls:
    - hosts:
      - my.domain.com
      secretName: tls-secret
  rules:
    - host: my.domain.com
      http:
        paths:
          - backend:
              service:
                name: current-frontend
                port:
                  number: 80
            path: /(.+)
            pathType: Prefix
</code></pre>
<p>At the same time I needed to change the New service to use Prefix instead of Exact as it does not work, event if there is no other services to hit.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: new-service
  labels:
    app: new-service
    tier: frontend
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  tls:
  - hosts:
    - my.domain.com
    secretName: tls-secret
  rules:
  - host: my.domain.com
    http:
      paths:
      - backend:
          service:
            name: new-service
            port:
              number: 80
        path: /someendpoint
        pathType: ImplementationSpecific
      - backend:
          service:
            name: new-service
            port:
              number: 80
        path: /
        pathType: Prefix
</code></pre>

IQn
<p>Ingress path matching can be enabled by setting the</p>
<p><code>nginx.ingress.kubernetes.io/use-regex annotation to true</code> .</p>
<p>See the description of the use-regex annotation :</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
spec:
  ingressClassName: nginx
  rules:
  - host: test.com
    http:
      paths:
      - path: /foo/.*
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80
</code></pre>
<p>Refer to this <a href="https://kubernetes.github.io/ingress-nginx/user-guide/ingress-path-matching/" rel="nofollow noreferrer">ingress path matching</a> for more information on path priority</p>
