Nginx 404 error after conifiguring nginx-ingress

Cluster information:

Kubernetes version: 1.26.6
Cloud being used: aks public cloud
Installation method: deployment and yaml file via kubectl

I have a dns mapped to an external ip of my aks load balancer, below the load balancer there is a nginx ingress controller that commicate with an ingress for the services in my cluster.

When I try to access to my dns like: mydns/post/test I receive the nginx 404 error. Seems that nginx answer correctly but doesn’found the internal routing mapping.

Below I rewrite all the step for this implementation.

Installation of nginx by this command:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/deploy/static/provider/cloud/deploy.yaml

with command:

kubectl get all -n ingress-nginx

I see this result: enter image description here

I create the ingress controlled by nginx with this yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: service-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: post-service
                port:
                  number: 8080

And the post-service:

apiVersion: v1
kind: Service
metadata:
  name: post-service
spec:
  selector:
    app.kubernetes.io/name: post
  ports:
    - port: 8080
      targetPort: 8080



The service communicate with a pod that containt a test endpoint(spring boot app, works
correctly tested via forward port):

@RestController
@Slf4j
public class PostController {
    

    @GetMapping("/test")
    String all() {
       
        return "Hello!";
    }

}

The dns is type A.

Why I receive the error nginx 404 error ?

thanks

Hi,
Make sure your default ingress class is set to nginx, otherwise you should specify it in your ingress resource.
Not sure whether annotation still works: Ingress | Kubernetes
Also worth checking pod logs to make sure traffic is being routed to the nginx controller.