Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

532
Views
Kubernetes Ingress path priority (ingress-nginx)

I deployed 2 front-end applications that are based on angular. I use ingress-nginx (k8s.gcr.io/ingress-nginx/controller:v0.44.0) with the following configurations to route the requests to these applications:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: portal-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - http:
      paths:
      - path: /?(.*)
        backend:
          serviceName: app1
          servicePort: 80
      - path: /app2
        backend:
          serviceName: app2
          servicePort: 80

When I hit the <ip-address>/ it is routing to app1, but when I hit <ip-address>/app2 it is routing back to app1.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

According to the ingress-nginx documentation, the first step it follows is to order the paths in descending length, then it transforms these paths into nginx location blocks. nginx follows a first-match policy on these blocks.

In your case, you can provide both paths, and as /app2 is longer than /, it will be written first in the nginx configuration. Meaning /app2 will have a chance to be matched first (and send the traffic to app2), while everything else will go to app1. You don't need regexes to achieve this.

Code:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: portal-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: app1
          servicePort: 80
      - path: /app2
        backend:
          serviceName: app2
          servicePort: 80
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!