Ingress-Nginx on Azure Kubernetes Cluster always routes to a 404 page

Manel Castro 30 Reputation points
2023-07-24T11:05:36.56+00:00

When applying the yaml file to the ingress services a load balancer is created. I pointed my DNS domain to that load balancer IP and it reaches the nginx server. However when routing to https://www.mydomain.com/api/users/ or https://www.mydomain.com/api/users/currentuser/ it returns a 404 page. Here is the Ingress-Nginx yaml file I'm using:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: www.mydomain.com
      http:
        paths:
          - path: /api/users/
            pathType: Prefix
            backend:
              service:
                name: be-auth-srv
                port:
                  number: 9001
          - path: /auth/
            pathType: Prefix
            backend:
              service:
                name: be-contact-form-srv
                port:
                  number: 9000



Anybody can shed light on this topic? Thanks

Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,447 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andriy Bilous 11,821 Reputation points MVP Volunteer Moderator
    2023-07-25T04:39:26.0466667+00:00

    Hello @Manel Castro

    There could many reasons why your Ingress does not work as expected

    1. Make sure your services are listening on the ports specified in your ingress (9001 and 9000 respectively).
      Examples for Service be-auth-srv
    apiVersion: v1
    kind: Service
    metadata:
      name: be-auth-srv
    spec:
      selector:
        app: be-auth-app
      ports:
        - protocol: TCP
          port: 9001
          targetPort: 8080
    
    1. Make sure that services be-auth-srv and be-contact-form-srv exist in the same namespace as your Ingress controller
    2. You may need to verify Nginx Ingress Controller logs kubectl logs <ingress-controller-pod-name>
    3. Check if you really need annotation **nginx.ingress.kubernetes.io/use-regex: "true" **as your paths seem to be static
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.