When creating an ingress controller for multiple backend services all serving on '/' there's no way to rewrite the target URI.
@joseppla Can you provide a small example to make sure we're on the same page?
Thanks in advanced.
Sure,
ingress ex.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: monitoring-ingress
namespace: monitoring
annotations:
alb.ingress.kubernetes.io/scheme: internal
alb.ingress.kubernetes.io/subnets: subnet-1,subnet-2
alb.ingress.kubernetes.io/security-groups: sg-XXXXXXX
alb.ingress.kubernetes.io/healthcheck-path: /
kubernetes.io/ingress.class: "alb"
labels:
app: monitoring
spec:
rules:
if I apply this ingress rule, the requests to 'domain/scope' are redirected to weave-scope-app searching for the '/scope' URI on the service, this URI doesn't exists and the service answers with an error, on Kubernetes standard ingress there're few anotations for modifying this requests:
app-root | Redirect requests without a path (i.e., for /) to this location. (nginx, haproxy, trafficserver)
rewrite-target | Replace matched Ingress path with this value. (nginx, trafficserver)
add-base-url | Add
preserve-host | Whether to pass the client request host (true) or the origin hostname (false) in the HTTP Host field. (trafficserver)
ex.
kubernetes.io/rewrite-target: '/'
Maybe I'm doing something wrong but the ingress seems to redirect to the correct service but the service log's showing a request to a non existent URI.
It will hit a non-existent uri. I think we just need to make sure that we serve from the non existent uri. However I am upvoting it as I faced the same issue and its not easy to server someone else url through another hack
We can use name based virtual hosting
This is because Application Load Balancers themselves do not support URL rewriting. As I understand it the ALB ingress controller is setting up an ALB with target groups pointing directly at the NodePorts exposed on the workers themselves, which then heads into the kube-proxy service fronting the pods. Because ALBs pass in the URL unmodified this is what leads to the behavior.
Most helpful comment
Sure,
ingress ex.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: monitoring-ingress
namespace: monitoring
annotations:
alb.ingress.kubernetes.io/scheme: internal
alb.ingress.kubernetes.io/subnets: subnet-1,subnet-2
alb.ingress.kubernetes.io/security-groups: sg-XXXXXXX
alb.ingress.kubernetes.io/healthcheck-path: /
kubernetes.io/ingress.class: "alb"
labels:
app: monitoring
spec:
rules:
http:
paths:
backend:
serviceName: prometheus
servicePort: 9090
backend:
serviceName: weave-scope-app
servicePort: 80
if I apply this ingress rule, the requests to 'domain/scope' are redirected to weave-scope-app searching for the '/scope' URI on the service, this URI doesn't exists and the service answers with an error, on Kubernetes standard ingress there're few anotations for modifying this requests:
app-root | Redirect requests without a path (i.e., for /) to this location. (nginx, haproxy, trafficserver) tag to HTML. (nginx)
rewrite-target | Replace matched Ingress path with this value. (nginx, trafficserver)
add-base-url | Add
preserve-host | Whether to pass the client request host (true) or the origin hostname (false) in the HTTP Host field. (trafficserver)
ex.
kubernetes.io/rewrite-target: '/'
Maybe I'm doing something wrong but the ingress seems to redirect to the correct service but the service log's showing a request to a non existent URI.