7

我正在尝试为似乎很常见的问题找到解决方案。

  1. 我有一个 k8s 集群 ip 服务,它公开两个端口:8088 和 60004
  2. 我想在 ALB 上公开这些相同的端口,而不是使用基于路径的路由

这适用于在 8088 端口上公开一项服务:

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress
  namespace: myns
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/healthcheck-path: /ping
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/tags: Environment=dev,Team=test
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 8088}]'
spec:
  rules:
    - host: myhost
      http:
        paths:
          - path: /*
            backend:
              serviceName: firstservice
              servicePort: 8088

如何使用 ONE ingress 为两种服务实现相同的目标?

提前致谢。

4

2 回答 2

11

最终,为了解决这个问题,我使用了 ALB 入口控制器组功能,该功能目前处于 alpha 状态:https ://github.com/kubernetes-sigs/aws-alb-ingress-controller/issues/914

这就是我的入口资源现在的样子:

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress_1
  namespace: myns
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/tags: Environment=dev,Team=test
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.name: mygroup
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 8088}]'
spec:
  rules:
    - host: <HOST>
      http:
        paths:
          - path: /*
            backend:
              serviceName: myservice
              servicePort: 8088
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myingress_2
  namespace: myns
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/tags: Environment=dev,Team=test
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.name: mygroup
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 60004}]'
spec:
  rules:
    - host: <HOST>
      http:
        paths:
          - path: /*
            backend:
              serviceName: myservice
              servicePort: 60004

关键在哪里

alb.ingress.kubernetes.io/group.name: mygroup

它将这两个入口资源连接起来。

因此,我最终得到以下结果:

  • k8s 中具有多个(两个)端口的服务公开了两个单独的入口资源,但它们都指向同一个 AWS ALB(因为相同的组名)
  • 在 AWS ALB 方面,我得到一个 ALB,暴露了两个端口:8088 和 60004,它们每个都指向同一个 k8s 服务,但同一个 pod 上的端口不同(如果需要,这很容易成为两个不同的 k8s 服务)
于 2019-10-14T15:49:20.453 回答
0

我试过这个,它对我有用;

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "ingress"
  namespace: "env"
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/certificate-arn: xxxxxx
    alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS-1-1-2017-01
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80},{"HTTP":443}]'
    alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: ssl-redirect
          servicePort: use-annotation
  - host: 123.example.com
    http:
      paths:
      - backend:
          serviceName: 1-server-tg
          servicePort: 80
  - host: 234.example.com
    http:
      paths:
      - backend:
          serviceName: 2-server-tg
          servicePort: 80
于 2021-02-04T07:57:31.893 回答