CodexBloom - Programming Q&A Platform

Kubernetes Ingress Not Routing Requests to Service Due to Path Matching guide in v1.22

👀 Views: 57 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-14
kubernetes ingress nginx path-matching yaml

I'm building a feature where I'm upgrading from an older version and I'm confused about I'm working on a personal project and I am trying to set up an Ingress resource in my Kubernetes cluster to route traffic to different services based on the path, but I'm running into issues with path matching. I have the following Ingress configuration: ```yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: my-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: /$2 spec: rules: - host: example.com http: paths: - path: /api/(.*) pathType: Prefix backend: service: name: api-service port: number: 80 - path: /static/(.*) pathType: Prefix backend: service: name: static-service port: number: 80 ``` When I access `http://example.com/api/test`, I expect it to route to `api-service`, but instead, I get a `404 Not Found` with the following behavior in the NGINX Ingress logs: ``` 2023/10/10 10:10:10 [behavior] 12345#12345: *1 open() "/usr/share/nginx/html/test" failed (2: No such file or directory), client: 192.168.1.1, server: example.com, request: "GET /api/test HTTP/1.1" 404 162 "-" "Mozilla/5.0" ``` I have tried changing the `pathType` to `Exact` but that didn't solve the scenario either. I also verified that the services are running and are accessible directly using their ClusterIP. My other Ingress rules are working fine, so I'm unsure why this specific configuration is failing. Any insights on why the path matching might not be working as expected? Any examples would be super helpful. This is for a CLI tool running on CentOS. Has anyone dealt with something similar? My team is using Yaml for this web app. What's the best practice here?