kubernetes nginx-ingress always redirecting to 404 default backen ignoring path rules

9/20/2019

After setting TLS succesfully, i'm not able to reach my web application through the ingress, since it is always redirecting to 404 default backend

This is my ingress configuration:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: 'letsencrypt-prod'
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
  tls:
    - hosts:
        - xxxx.com
        - www.xxxx.com
      secretName: xxxx-com
  rules:
    - host: xxxx.com
    - http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000
    - host: www.xxxx.com
    - http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000

Removing TLS options make it work fine (thought is not using TLS anymore):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000
-- Tizio Fittizio
kubernetes
nginx
nginx-ingress

1 Answer

9/21/2019

Nevermid, after many hours i found that my configuration has an error:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: 'letsencrypt-prod'
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
spec:
  tls:
    - hosts:
        - xxxx.com
        - www.xxxx.com
      secretName: xxxx-com
  rules:
    - host: xxxx.com
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000
    - host: www.xxxx.com
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: web-cluster-ip-service
              servicePort: 3000

Hypens should be removed before http in each host block

That was... hard to find, a warning message when applying a possible weird/wrong configuration would not have hurt anyone

-- Tizio Fittizio
Source: StackOverflow