基于 ALB 入口控制器路径的路由

Posted

技术标签:

【中文标题】基于 ALB 入口控制器路径的路由【英文标题】:ALB ingress controller path based routing 【发布时间】:2021-10-30 23:59:28 【问题描述】:

我已经部署了基于路径的路由的 ALB 入口控制器,在部署 application-ingress.yaml 文件后,定义的路径在 AWS 控制台中按照我们的预期创建,并且目标组也很健康。

但它只工作 /*,其余路径(/app1,/app2)不工作,出现错误 404。请找到下面的入口 yaml 文件。

Let's say when I'm trying to access /app1 page https://my-domain-name/app1 getting error HTTP ERROR 404

Same way /app2 page https://my-domain-name/app2 getting error HTTP ERROR 404

And last one is /app3 page https://my-domain-name/app3 page is working as we expected
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-modulus-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/target-type: instance
    alb.ingress.kubernetes.io/healthcheck-protocol: HTTPS
    alb.ingress.kubernetes.io/backend-protocol: HTTPS
    alb.ingress.kubernetes.io/healthcheck-port: traffic-port
    alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
    alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
    alb.ingress.kubernetes.io/success-codes: '200'
    alb.ingress.kubernetes.io/healthy-threshold-count: '2'
    alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
    alb.ingress.kubernetes.io/listen-ports: '["HTTPS":443, "HTTP":80]'
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:eu-central-1:249889768:certificate/267887899-1569-4b78-c557-12678906533
    alb.ingress.kubernetes.io/subnets: subnet-01234567, subnet-7654321
    alb.ingress.kubernetes.io/security-groups: sg-0667f8a234579865
spec:
  rules:
     - http:
        paths:
          - path: /app1
            pathType: Prefix
            backend:
              service:
                name: app1-service
                port:
                  number: 30002
          - path: /app2
            pathType: Prefix
            backend:
              service:
                name: app2-service
                port:
                  number: 3030
           - path: /*
            pathType: Prefix
            backend:
              service:
                name: app3-service
                port:
                  number: 443

【问题讨论】:

【参考方案1】:

请删除通配符 *,然后检查它是否会开始工作

【讨论】:

删除 * 后它对我有用

以上是关于基于 ALB 入口控制器路径的路由的主要内容,如果未能解决你的问题,请参考以下文章

基于 AWS 应用程序负载均衡器 (ALB) 路径的路由未按预期运行

带有 ALB 入口控制器的 Terraform AWS Kubernetes EKS 资源不会创建负载均衡器

如何从 EKS 集群为 Django 提供静态文件?

ThinkPHP5 (路径优化,路由)

允许从 API Gateway 到私有 ALB 的请求

Django----路由控制