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

376
Views
ingress multiple path mismatch

I have two service serviceOld serviceNew

I want to achieve the following effect

http://host/any         => http://serviceOld/any
http://host/any/aaa     => http://serviceOld/any/aaa
http://host/feature     => http://serviceNew/feature
http://host/feature/bbb => http://serviceNew/feature/bbb
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-by-header: new
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: v2
  namespace: api
spec:
  rules:
  - host: xxx.com
    http:
      paths:
      - path: /
        backend:
          serviceName: serviceOld
          servicePort: 80
      - path: /feature/*
        backend:
          serviceName: serviceNew
          servicePort: 8080

I tried multiple methods and failed to achieve the goal. Can anyone help me?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

All you need about rewrite annotation and path can be found in Ingress Rewrite Docs.

As per example on the site:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)

It will redirect:

rewrite.bar.com/something rewrites to rewrite.bar.com/
rewrite.bar.com/something/ rewrites to rewrite.bar.com/
rewrite.bar.com/something/new rewrites to rewrite.bar.com/new

In your case it should looks like:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: v2
  namespace: api
spec:
  rules:
  - host: xxx.com
    http:
      paths:
      - path: /any(/|$)(.*)
        backend:
          serviceName: serviceOld
          servicePort: 80
      - path: /feature(/|$)(.*)
        backend:
          serviceName: serviceNew
          servicePort: 8080
over 4 years ago · Santiago Trujillo Report

0

I found that my version is relatively old. Under the old version, if the ports are different, it will not work properly. Change to the same port or upgrade the ingress version

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!