Kubernetes Ingress with 302 redirect loop

3/24/2021

I have an ingress with role with two paths:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
metadata:
  name: myservice-production
  annotations:
    kubernetes.io/ingress.class: nginx
    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"
    cert-manager.io/cluster-issuer: letsencrypt-prod
    acme.cert-manager.io/http01-edit-in-place: "true"
spec:
  rules:
    - host: ra2.myservice.com.br
      http:
        paths:
          - path: /
            backend:
              serviceName: myservice-production-deployment-nodeport
              servicePort: 80
          - path: /conteudo/
            backend:
              serviceName: seo-production-deployment-nodeport
              servicePort: 80
  tls:
    - hosts:
        - ra2.myservice.com.br
      secretName: ra-production-us2-certmanager-certificate

The SEO deployment is correct:

kind: Service apiVersion: v1 metadata: name: seo-production-deployment-nodeport spec: selector: app: seo-production-deployment ports: - name: http port: 80 targetPort: 3003 protocol: TCP type: NodePort

But when I try to access any route from my conteudo path I'm getting a 302 redirect loop. It's just when using this ingress. If I change, for example, to:

- host: ra2.myservice.com.br
  http:
    paths:
      - path: /
        backend:
          serviceName: seo-production-deployment-nodeport
          servicePort: 80

It starts working normally. I could not find a reasonable motive to be with this behavior.

-- Jonathan Silva
kubernetes

1 Answer

3/24/2021

Remove this annotation : nginx.ingress.kubernetes.io/rewrite-target: / Also the change the annotation : nginx.ingress.kubernetes.io/ssl-redirect: "true" to this one nginx.ingress.kubernetes.io/force-ssl-redirect: "true" Edit the path - path: /conteudo/ to - path: /conteudo

-- Klevi Merkuri
Source: StackOverflow