I have an ingress service where I can curl to "/" to the UI of the project, but everything but the slash is not routing properly. Below is my last ingress service I tried.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
meta.helm.sh/release-name: ingress
meta.helm.sh/release-namespace: default
creationTimestamp: "2022-11-26T15:57:15Z"
generation: 1
labels:
app.kubernetes.io/managed-by: Helm
name: ingress-service
namespace: default
resourceVersion: "53584"
uid: fccbcc20-e365-42cd-be29-0fff80611ddc
spec:
rules:
- host: project.k8s.com
http:
paths:
- backend:
service:
name: project-backend
port:
number: 8080
path: /api/
pathType: Prefix
- backend:
service:
name: project-backend
port:
number: 8080
path: /api/general/details/
pathType: Prefix
- backend:
service:
name: project-backend
port:
number: 8080
path: /api/general/
pathType: Prefix
- backend:
service:
name: project-ui
port:
number: 8080
path: /
pathType: Prefix
status:
loadBalancer:
ingress:
- ip: xxx.xxx.xx.x
The curls I try
curl http://xx.xxx.xxx.xx/api/general/detail -H "Host: project.k8s.com"
{"timestamp":"2022-11-27T14:29:31.899 00:00","status":404,"error":"Not Found","path":"/api/general/detail"}
curl http://xx.xxx.xxx.xx/ -H "Host: project.k8s.com" <-- The UI as expected
In the Spring logs I read
Tomcat started on port(s): 8080 (http) with context path '/api'
Which makes me think that the backend service is working correctly and in the ingress logs I see the requests being made. It is a simple backend with a controller with @RequestMapping("api/general/detail/") which I tested outside the cluster.
Am I correct? Is the backend service working correctly? Is there anything else to do than looking at the logs / output of the ingress yaml / k get all ?
CodePudding user response:
I'm not sure, but what I use for my project with Java backend:
- path: /api/()(.*)
pathType: ImplementationSpecific
backend:
service:
name: project-backend
port:
number: 8080
Also the problem can be with Java server. It can return 404 if you don't pass necessary params. (content-type or query param)
CodePudding user response:
The fourth rule in your ingress is path: /
with pathType: Prefix
so I would assume all requests to that host /, will match that rule, regardless of what comes after /
CodePudding user response:
According to your rules and the request (to the backend), the request should be handled by the 3rd rule (/api/general
). Since it has a 404 response, this would be a client side error by convention.
However I suggest you to first verify whether the particular request first hits ingress and then hit the backend correctly. You can first check ingress-nginx pod logs to identify whether the request is handled by the ingress nginx. If you find the logs, then check backend logs of your application. If you can find logs for the particular request in your backend logs too, there is nothing to at ingress/service level. All you need to do is check your backend implementation whether the requests will be served correctly for the path.