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

363
Views
Kubernetes Ingress Path

I have nginx-ingress setup for both frontend and backend using below yaml file.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: polls-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/service-upstream: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  tls:
  - hosts:
    - example.com
    secretName: polls-tls
  rules:
  - host: example.com
    http:
      paths:
      - path: /(.*)
        backend:
          serviceName: frontend
          servicePort: 3000
      - path: /graphql/(.*)
        backend:
          serviceName: polls
          servicePort: 8000

Currently, my rewrite-target reroutes as below

example.com  => / of frontend app
example.com/ => / of frontend app
example.com/graphql => / of frontend app
example.com/graphql/post => / of frontend app

example.com/graphql/ => / of backend app
example.com/graphql/post/ => /post of backend app

But I want the backend app to be used for both graphql/post and graphql/post/ as below.

example.com => / of frontend app
example.com/ => / of frontend app
example.com/hello => /hello of frontend app
example.com/test => /test of frontend app

example.com/graphql => / of backend app
example.com/graphql/ => / of backend app
example.com/grpahql/post => /post of backend app
example.com/graphql/post/ => /post of backend app

Could anyone tell me how to achieve it?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to change the regex for graphql path like the following:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: polls-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/service-upstream: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  tls:
  - hosts:
    - example.com
    secretName: polls-tls
  rules:
  - host: example.com
    http:
      paths:
      - path: /(.*)
        backend:
          serviceName: frontend
          servicePort: 3000
      - path: /graphql/?(.*)   # <- HERE add "?"
        backend:
          serviceName: polls
          servicePort: 8000

From docs on regex:

The question mark indicates zero or one occurrences of the preceding element. For example, colou?r matches both "color" and "colour".

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!