I'm trying to use rewrite target from kubernetes with gcloud
but it doesn't seem to be respected. My code is the following. Maybe there's something I'm not seen:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.global-static-ip-name: projectip
spec:
rules:
- host: mycustomdomain.com
http:
paths:
- path: /*
backend:
serviceName: frontend
servicePort: 80
- path: /api/*
backend:
serviceName: backend
servicePort: 80
When I do curl mycustomdomain.com/api/something
my backend is always receiving backend/api/something
instead of backend/something
. I'm really out of ideas and I could use some help.
The term rewrite-target
is misleading: it is about the path of the incoming request.
This might work: use one ingress with rewrite-target: /
and path: /
for the frontend only, and one ingress with rewrite-target: /api
and path: /
for the backend only.
I am assuming you are using the kubernetes ingress-nginx.
Looking at your ingress manifest, it seems like the rewrite annotation is wrong.
According to the documentation it should be: nginx.ingress.kubernetes.io/rewrite-target
Here's the link to th documentation:
https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/annotations.md#rewrite