skip to Main Content

I am trying to setup my services inside nginx ingress. In this case, I want to have a mail service along the path test.io/mail/. I make a request to test.io/mail/send_mail/ the response comes 404.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  namespace: test-backend
spec:
  ingressClassName: nginx
  rules:
  - host: test.io
    http:
      paths:
      - path: /mail/
        pathType: Exact
        backend:
          service:
            name: email-test
            port:
              number: 80

If I change the settings and remove the prefix, then everything will work.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  namespace: test-backend
spec:
  ingressClassName: nginx
  rules:
  - host: test.io
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: email-test
            port:
              number: 80

How do I properly set the prefix?

2

Answers


  1. Please have ingress yaml as below to use "pathType: Prefix" instead of "pathType: Exact"

     rules:
      - host: test.io
        http:
          paths:
          - path: /mail/
            pathType: Prefix
    

    Please refer official documentation for more details for

    pathType: Prefix

    Login or Signup to reply.
  2. Each path in an Ingress is required to have a corresponding path type. Paths that do not include an explicit pathType will fail validation.
    The only supported wildcard character for the path field of an Ingress is the * character. The * character must follow a forward slash (/) and must be the last character in the pattern. For example, /, /foo/, and /foo/bar/* are valid patterns, but , /foo/bar, and /foo//bar are not.A more specific pattern takes precedence over a less specific pattern. If you have both /foo/ and /foo/bar/, then /foo/bar/bat is taken to match /foo/bar/.For more information about path limitations and pattern matching, see the URL Maps documentation.

    Suggestion :

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: test-ingress
      namespace: test-backend
    spec:
      ingressClassName: nginx
      rules:
      - host: test.io
        http:
          paths:
          - path: /mail/*
            pathType: Exact
            backend:
              service:
                name: email-test
                port:
                  number: 80
          - path: /
            pathType: Prefix
            backend:
              service:
                name: email-test
                port:
                  number: 80
    

    Additional reference doc :
    Refer1
    Refer2

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search