我正在尝试解决似乎很常见的问题的解决方案。
这适用于在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
如何使用一个入口实现两种服务的相同目的?
谢谢。
答案 0 :(得分:1)
最终,为了解决此问题,我使用了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
连接这两个入口资源。
因此,我最终得到以下结果:
答案 1 :(得分: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