Unable to access path based routing getting 404 error

Viewed 301

I have configured the nginx-ingress controller with path-based routing. Below is my ingress.yaml file.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
 name: voting-app-ingress
 annotations:
   nginx.ingress.kubernetes.io/rewrite-target: /$2
   kubernetes.io/ingress.class: nginx
spec:
 rules:
 - host: voteapp.com
   http:
    paths:
    - backend:
        serviceName: vote
        servicePort: vote-http
    path: /vote(/|$)(.*)
    - backend:
        serviceName: result
        servicePort: result-http
    path: /result(/|$)(.*)

I can access the application successfully, but when I click anything within the application it routes to 404 page not found. http://voteapp.com/vote/ http://voteapp.com/result/

kubectl get ing
NAME                 CLASS    HOSTS        ADDRESS          PORTS   AGE
voting-app-ingress   <none>   voteapp.com  192.168.99.100   80      40s

But the same thing works fine when I use the host-based routing.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: voting-app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: voteapp.com
    http:
      paths:
      - backend:
          serviceName: vote
          servicePort: vote-http
  - host: resultapp.com
    http:
      paths:
      - backend:
          serviceName: result
          servicePort: result-http

.

kubectl get ing
NAME                 CLASS    HOSTS                       ADDRESS          PORTS   AGE
voting-app-ingress   <none>   voteapp.com,resultapp.com   192.168.99.100   80      40s

Kubernetes version - v1.18.2 Any suggestions where I am possibly going wrong?

0 Answers
Related