如何在 AWS ALB 入口控制器中重写目标 URL?

问题描述 投票:0回答:4

在经典的 Kubernetes Nginx 入口中,我知道可以通过应用此注释来基于特定的正则表达式重写目标 url

nginx.ingress.kubernetes.io/rewrite-target: /$1

但是此注释在 AWS ALB 入口中不起作用。有谁知道是否可以用这种入口进行重写工作?

kubernetes url-rewriting kubernetes-ingress amazon-eks aws-application-load-balancer
4个回答

0
投票

我还在寻找当你有 AWS ALB 入口时如何重写路径的答案:(

这里的答案是关于重定向而不是重写路径


-1
投票

添加动作注释:

alb.ingress.kubernetes.io/actions.redirect-home: '{"Type":"redirect","RedirectConfig": {“主机”:“abc.example.com”,“路径”:“/mycontext/other-path”,“端口”:“443”,“协议”:“HTTPS”,“查询”:“#{查询}","StatusCode":"HTTP_301"}}'

将路线添加到操作:

      - backend:
          service:
            name: redirect-home
            port:
              name: use-annotation
        path: /some-path
        pathType: ImplementationSpecific

这会将 /some-path 重定向到 abc.example.com/mycontext/other-path

谢谢


-1
投票

有一次我的要求是重定向从

coffee.abc.com
coffee.xyz.com
的流量 因此,为此,我使用了 alb 重定向注释。

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
© www.soinside.com 2019 - 2024. All rights reserved.