Unspecified URLs or paths not included in the ingress configuration are directed to the main backend service

I have created an ingress configuration as follows:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-example
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  ingressClassName: nginx
  rules:
    - host: "exampleapp.com"
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: primary-svc
                port:
                  number: 80
    - host: "exampleapp.com"
      http:
        paths:
          - path: "/images"
            pathType: Prefix
            backend:
              service:
                name: images-svc
                port:
                  number: 80
          - path: "/clips"
            pathType: Prefix
            backend:
              service:
                name: clips-svc
                port:
                  number: 80

The expected behavior is as follows:

  • exampleapp.com routes to primary-svc
  • exampleapp.com/images routes to images-svc
  • exampleapp.com/clips routes to clips-svc
  • However, URLs like exampleapp.com/blog or exampleapp.com/xyz are not defined in my ingress rules. To handle these, I set up a separate service called error-svc and aim to redirect those requests to error-svc through the default backend service in the ingress controller deployment:
--default-backend-service=default/error-svc

The issue I’m encountering is that these requests are incorrectly directed to primary-svc instead. Can anyone provide insight into what might be causing this problem? I am operating within a kind cluster that contains two nodes.

It could be possible that the default backend config isn’t being recognized, make sure the --default-backend-service is correctly configured and the default service is deployd in the right namespace. Also, double-check that there’s no other global ingress settings overriding your rules!