While working with minikube ingress, I have to write nginx.ingress.kubernetes.io/rewrite-target: /$1
. I have been trying hard to understand why we need this annotation and how to use it.
I know that the doc says the following:
In some scenarios the exposed URL in the backend service differs from the specified path in the Ingress rule. Without a rewrite any request will return 404. Set the annotation nginx.ingress.kubernetes.io/rewrite-target to the path expected by the service.
But I am not able to get the exact point of what exactly the exposed URL in the backend service differs from the specified path in the Ingress rule
means. I am not able to get the idea clearly.
Further, upon trying to execute ingress file with services:
code 1:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: example-namespace
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: myexample.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
code 2:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: example-namespace
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myexample.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
code 3:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: example-namespace
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: myexample.com
http:
paths:
- path: /index
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
what exactly is the difference between each pair of the above 3 code snippets with respect to rewrite-target and path mentioned above?
PS: I'm new to minikube and trying to figure out the exact way things work. Please help.