在一个经典的Kubernetes Nginx入口中,我知道通过应用注解nginx.ingress.kubernetes.io/rewrite-target: /$1,可以基于特定的正则表达式重写目标url但是这个注解在AWS ALB入口中不起作用,有没有人知道是否有可能用这种入口做重写工作?
nginx.ingress.kubernetes.io/rewrite-target: /$1
dwbf0jvd1#
好的,目前似乎不支持=〉https://github.com/kubernetes-sigs/aws-alb-ingress-controller/issues/835
yxyvkwin2#
添加操作注解:alb.ingress.kubernetes.io/actions.redirect-home: {“类型”:“重定向”,“重定向配置”:{“主机”:“abc.example.com“,“路径”:“/我的上下文/其他路径”,“端口”:“443”,“协议”:“HTTPS”,“查询”:“#{查询}",“状态代码”:“HTTP_301”}}'向操作添加路由:
- backend: service: name: redirect-home port: name: use-annotation path: /some-path pathType: ImplementationSpecific
这会将/some-path重定向到abc.example.com/mycontext/other-path谢谢
ojsjcaue3#
曾经我的需求是重定向从coffee.xyz.com到coffee.abc.com的流量,所以为此,我使用alb重定向注解。
coffee.xyz.com
coffee.abc.com
alb.ingress.kubernetes.io/actions.coffee-redirection: '{"Type":"redirect","RedirectConfig":{"Host":"coffee.xyz.com","Port":"443","Protocol":"HTTPS","Query":"#{query}","StatusCode":"HTTP_301"}}'
以下是同一问题的完整代码块。
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: annotations: alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig":{ "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}' alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:********************************************** alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80},{"HTTPS":443}]' alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/subnets: subnet-*******, subnet-********, subnet-**********,subnet-******** service.beta.kubernetes.io/aws-load-balancer-name: coffee-alb-staging kubernetes.io/ingress.class: alb alb.ingress.kubernetes.io/ssl-redirect: '443' alb.ingress.kubernetes.io/group.name: coffee-staging alb.ingress.kubernetes.io/actions.coffee-redirection: '{"Type":"redirect","RedirectConfig":{"Host":"coffee.xyz.com","Port":"443","Protocol":"HTTPS","Query":"#{query}","StatusCode":"HTTP_301"}}' name: coffee-alb-staging namespace: NameSpace spec: rules: - host: coffee.abc.com http: paths: - path: / pathType: Prefix backend: service: name: coffee-fe port: number: 80 - path: / pathType: Exact backend: service: name: coffee-redirection port: name: use-annotation
3条答案
按热度按时间dwbf0jvd1#
好的,目前似乎不支持=〉https://github.com/kubernetes-sigs/aws-alb-ingress-controller/issues/835
yxyvkwin2#
添加操作注解:
alb.ingress.kubernetes.io/actions.redirect-home: {“类型”:“重定向”,“重定向配置”:{“主机”:“abc.example.com“,“路径”:“/我的上下文/其他路径”,“端口”:“443”,“协议”:“HTTPS”,“查询”:“#{查询}",“状态代码”:“HTTP_301”}}'
向操作添加路由:
这会将/some-path重定向到abc.example.com/mycontext/other-path
谢谢
ojsjcaue3#
曾经我的需求是重定向从
coffee.xyz.com
到coffee.abc.com
的流量,所以为此,我使用alb重定向注解。以下是同一问题的完整代码块。