Ingress Controller Configuration for backend service with relative path
Vishal Mehra
vishal.m.mehra at gmail.com
Thu Jun 17 03:21:47 UTC 2021
What is the best way to route traffic to a backend web front service which
uses different relative paths within the web application.
As an example, take a standard Jaeger service kubectl create -f
https://tinyurl.com/yc52x6q5.
I would like to expose this service endpoint via an ingress controller, see
ingress configuration below
apiVersion: networking.k8s.io/v1kind: Ingressmetadata:
name: frontend-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/add-base-url: "true"spec:
rules:
- host:
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 4444
- path: /jaeger
pathType: Prefix
backend:
service:
name: jaeger-query
port:
number: 443
Using ingress endpoint https://<host public ip>/jaeger, I am able to
successfully invoke the backend service (jaeger-query), however the backend
service pages with the relative URLs (like /static and /api) are not
getting loaded/rendered on the browser as ingress controller does not have
a rule to route that traffic.
As a workaround, I added ingress rules for /static and /api to point to the
same backend service. configuration.
apiVersion: networking.k8s.io/v1kind: Ingressmetadata:
name: frontend-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/add-base-url: "true"spec:
rules:
- host:
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 4444
- path: /jaeger
pathType: Prefix
backend:
service:
name: jaeger-query
port:
number: 443
- path: /search
pathType: Prefix
backend:
service:
name: jaeger-query
port:
number: 443
- path: /static
pathType: Prefix
backend:
service:
name: jaeger-query
port:
number: 443
- path: /api
pathType: Prefix
backend:
service:
name: jaeger-query
port:
number: 443
Ideally, I would like one Ingress rule per backend service and the relative
paths like /static and /api to automatically adjust to /jaeger/static and
/jaeger/api.
Do you know how that can be achieved?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210616/757702ea/attachment.htm>
More information about the nginx
mailing list