0
votes

I have this ingress in my server.

kind: Ingress
metadata:
  name: mycompany-production
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
spec:
  tls:
    - hosts:
        - ra2.mycompany.com.br
      secretName: ra-production-us2-certmanager-certificate
  rules:
    - host: ra2.mycompany.com.br
      http:
        paths:
          - path: /
            backend:
              serviceName: mycompany-production-deployment-nodeport
              servicePort: 80
          - path: /conteudo/
            backend:
              serviceName: seo-production-deployment-nodeport
              servicePort: 80

Actually, I expect that when I call ra2.mycompany.com.br/conteudo/health, for exemple, it touch the seo-production-deployment-nodeport/health, but it is going to seo-production-deployment-nodeport/conteudo/health receiving an 404 answer.

Looking in my ingress it does not seems to have an error. I just do not know why it's not "cleaning" the path as expected. The requests in normal / path is happening as expected.

1

1 Answers

1
votes
      - path: /conteudo/
        backend:
          serviceName: seo-production-deployment-nodeport
          servicePort: 80

You're hitting ra2.mycompany.com.br/conteudo/health so of course it goes to this backend, as defined in the ingress rules.

nginx.ingress.kubernetes.io/rewrite-target: / just means that / in your url is forwarded to / in the backend matching the path set in rules, not matching the rule serving /

To make it easy to understand: when you run a webserver which only serves everything under a base path let's say /mysite but you do not want the people using your ingress to see /mysite/ you set your nginx.ingress.kubernetes.io/rewrite-target: /mysite and if they hit <domain>/foo it actually goes to your backend /mysite/foo