I'm running a Kubernetes cluster on Azure Kubernetes Service(Aks). Currently, I'm having a service called product-service and I have exposed it to the outside using Nginx Ingress. My current ingress configuration looks like below.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
spec:
rules:
- host: api.example.com
HTTP:
paths:
- path: /api/products
pathType: Prefix
backend:
service:
name: products-service
port:
number: 5000
My Problem here is whenever I hit api.example.com/api/products
it should return a list of products as a Json response. It's working fine. But when I hit this url api.example.com/api/products/{product_id}
the server should get the product id I pass and return the details of that specific product. But whenever I hit that route it returns 404 error. I was trying to find a proper rewrite for this case. But I hadn't any luck so far. Could someone explain a workaround to fix this problem?