CodexBloom - Programming Q&A Platform

Kubernetes Ingress Not Routing Traffic to Services Based on Path - 404 Errors

đź‘€ Views: 74 đź’¬ Answers: 1 đź“… Created: 2025-07-02
kubernetes ingress nginx yaml

I recently switched to I'm running a Kubernetes cluster with version 1.23 and I've set up an Ingress resource to route traffic to two different services based on the request path, but I'm getting 404 errors when trying to access the routes. My Ingress configuration looks like this: ```yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: my-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: /$2 spec: rules: - host: myapp.example.com http: paths: - path: /service1(/|$)(.*) pathType: Prefix backend: service: name: service1 port: number: 80 - path: /service2(/|$)(.*) pathType: Prefix backend: service: name: service2 port: number: 80 ``` Both `service1` and `service2` are running and I can access them directly via their ClusterIP services. However, when I try to access `http://myapp.example.com/service1` or `http://myapp.example.com/service2`, I always get a 404 Not Found response. I have verified that the Ingress controller is running, and I've checked the logs for any errors, but there are no relevant messages. I've also confirmed that the DNS for `myapp.example.com` is correctly pointing to the Ingress controller’s external IP. To troubleshoot, I've tried modifying the paths in the Ingress resource, but the scenario continues. I also attempted to remove the rewrite-target annotation, thinking that it might be interfering, but that didn’t help either. Could anyone provide insights into what might be misconfigured in my Ingress setup or suggest further troubleshooting steps? This is my first time working with Yaml LTS.