Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

364
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda