Aws-load-balancer-controller: Add support for rewrite-target

Created on 14 Jul 2017  路  5Comments  路  Source: kubernetes-sigs/aws-load-balancer-controller

When creating an ingress controller for multiple backend services all serving on '/' there's no way to rewrite the target URI.

triagunresolved

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:

  • host: k8s-monitoring.domain.com
    http:
    paths:

    • path: /

      backend:

      serviceName: prometheus

      servicePort: 9090

    • path: /scope

      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)
rewrite-target | Replace matched Ingress path with this value. (nginx, trafficserver)
add-base-url | Add tag to HTML. (nginx)
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.

All 5 comments

@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:

  • host: k8s-monitoring.domain.com
    http:
    paths:

    • path: /

      backend:

      serviceName: prometheus

      servicePort: 9090

    • path: /scope

      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)
rewrite-target | Replace matched Ingress path with this value. (nginx, trafficserver)
add-base-url | Add tag to HTML. (nginx)
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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amalagaura picture amalagaura  路  4Comments

khacminh picture khacminh  路  3Comments

rdubya16 picture rdubya16  路  4Comments

rootd00d picture rootd00d  路  4Comments

brylex418 picture brylex418  路  4Comments