Ingress routing not working when path is specified

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: mlservicesrouting
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:

  • http:
    paths:
    • backend:
      serviceName: flask-demo
      servicePort: 8080

The above configuration works with Python Plotly based Docker image. However, as soon as I enable the path /bond_scoring, the URL no longer works. The below config does not work.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: mlservicesrouting
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:

  • http:
    paths:
    • path: /bond_scoring
      backend:
      serviceName: flask-demo
      servicePort: 8080

What may I be doing wrong here? Other objects are below -

bond-predict-service.yml

apiVersion: v1
kind: Service
metadata:
name: flask-demo
labels:
app: flask-demo
spec:
ports:

  • port: 8080
    name: http
    targetPort: 8080
    selector:
    app: flask-demo

bond-predict-deployment.yml

apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: flask-demo
labels:
app: flask-demo
spec:
replicas: 1
selector:
matchLabels:
app: flask-demo
template:
metadata:
labels:
app: flask-demo
spec:
containers:
- name: flask-demo
image: varunkh70/bond_scoring
command: [“python3”, “app.py”]

The errors I get(when I add path /bond_scoring) are below -

Typically, this happens when your rewrite rule and target pods endpoint doesn’t match.

Is your pod expecting incomings at / or /bond_score? I’m guessing the later and your rewrite setting is cutting the /bond_score off.

Check the logs in the pod if its actually what’s happening.

Also, this page will help.

https://kubernetes.github.io/ingress-nginx/examples/rewrite/

Good luck