Score:0

Kubernetes Nginx Ingress url rewrite for dynamic id in url

at flag

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?

in flag
Hi Pasindu Prabhashitha welcome to S.F. Your question does not contain any debugging steps you have already taken, meaning there are almost infinite reasons why that would not work. What logging have you already examined and what debugging have you already done on your own? Don't put new information in the comments, instead [edit your question](https://serverfault.com/posts/1128978/edit) and include those details there. Good luck
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.