i have tomcat backend service running on kubernetes cluster try to rewrite using ingress with path /blob/api/v1/test-backend > /api/v1/test-backend so
the configuration now is running so can hit to xx.somedomain.com/blob/api/v1/test-backend and i want change to xx.somedomain.com/api/v1/test-backend with rewrites
my basic ingress
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-blob
namespace: blob-test
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: 50m
spec:
tls:
- hosts:
- xx.somedomain.com
secretName: cert-key
rules:
- host: xx.somedomain.com
http:
paths:
- path: /blob/
backend:
serviceName: blob-service
servicePort: 8080
- path: /
backend:
serviceName: web-service
servicePort: 80
and this is yaml for rewrite /blob/
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-blob
namespace: blob-test
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: 50m
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
tls:
- hosts:
- xx.somedomain.com
secretName: cert-key
rules:
- host: xx.somedomain.com
http:
paths:
- path: /blob/api/v1/some-backend
backend:
serviceName: blob-service
servicePort: 8080
when i test with api tester like talend is got 405 error
2
Answers
Try adding annotation like this
nginx.ingress.kubernetes.io/rewrite-target: "/$1"
Try this
For example, the ingress definition above will result in the following rewrites:
Refer : https://kubernetes.github.io/ingress-nginx/examples/rewrite/