skip to Main Content

recently I deployed my Spring boot API in local kubernetes(K3D), all works fine until I specify an ingress with path: /api/user. That ingress path localhost:9080/api/user returns Spring boots 404, so not nginx 404. When reducing the path to /user it works.

not working ingress yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: user-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: localhost
    http:
      paths:
      - path: /api/user
        pathType: Prefix
        backend:
          service:
            name: user-service
            port:
              number: 8094

the yaml above gives the Whitelabel error page from Spring boot. So it does get through but not with the right path for Spring boot?

working ingress yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: user-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: localhost
    http:
      paths:
      - path: /user
        pathType: Prefix
        backend:
          service:
            name: user-service
            port:
              number: 8094

Above works.

Why does it break when adding /api in path?

I have searched for related problems/solutions but found none.

According to docs it should work:https://kubernetes.io/docs/concepts/services-networking/ingress/

2

Answers


  1. Chosen as BEST ANSWER

    Like @YvanG. said, there was something wrong with my configuration in Spring Boot. I had to set the request mapping to: RequestMapping("/api/user") in my controller. Then it worked.


  2. Hi, just to add on this concern for other users to see. Providing /api/user to your ingress yaml will route your traffic to a different folder that is why from this path we are having a different result from just providing /user.

    Mapping /api/user is what we found out that will solve this concern. Also I just want to share that spring boot error message with code of 404 is that the handlers are not properly defined that is why when we use /api/user in path this resource is not found.

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