21.6. 通过单个 AWS Load Balancer 提供多个入口资源
您可以通过单个 AWS Load Balancer 将流量路由到属于单个域的不同服务。每个 Ingress 资源提供域的不同端点。
21.6.1. 通过单个 AWS Load Balancer 创建多个入口资源
您可以使用 CLI 通过单个 AWS Load Balancer 将流量路由到多个入口资源。
先决条件
-
您可以访问 OpenShift CLI(
oc
)。
流程
创建一个
IngressClassParams
资源 YAML 文件,如sample-single-lb-params.yaml
,如下所示:apiVersion: elbv2.k8s.aws/v1beta1 1 kind: IngressClassParams metadata: name: single-lb-params 2 spec: group: name: single-lb 3
运行以下命令来创建
IngressClassParams
资源:$ oc create -f sample-single-lb-params.yaml
创建
IngressClass
资源 YAML 文件,如sample-single-lb-class.yaml
,如下所示:apiVersion: networking.k8s.io/v1 1 kind: IngressClass metadata: name: single-lb 2 spec: controller: ingress.k8s.aws/alb 3 parameters: apiGroup: elbv2.k8s.aws 4 kind: IngressClassParams 5 name: single-lb-params 6
运行以下命令来创建
IngressClass
资源:$ oc create -f sample-single-lb-class.yaml
创建
AWSLoadBalancerController
资源 YAML 文件,如sample-single-lb.yaml
,如下所示:apiVersion: networking.olm.openshift.io/v1 kind: AWSLoadBalancerController metadata: name: cluster spec: subnetTagging: Auto ingressClass: single-lb 1
- 1
- 定义
IngressClass
资源的名称。
运行以下命令来创建
AWSLoadBalancerController
资源:$ oc create -f sample-single-lb.yaml
创建
Ingress
资源 YAML 文件,如sample-multiple-ingress.yaml
,如下所示:apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-1 1 annotations: alb.ingress.kubernetes.io/scheme: internet-facing 2 alb.ingress.kubernetes.io/group.order: "1" 3 alb.ingress.kubernetes.io/target-type: instance 4 spec: ingressClassName: single-lb 5 rules: - host: example.com 6 http: paths: - path: /blog 7 pathType: Prefix backend: service: name: example-1 8 port: number: 80 9 --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-2 annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/group.order: "2" alb.ingress.kubernetes.io/target-type: instance spec: ingressClassName: single-lb rules: - host: example.com http: paths: - path: /store pathType: Prefix backend: service: name: example-2 port: number: 80 --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-3 annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/group.order: "3" alb.ingress.kubernetes.io/target-type: instance spec: ingressClassName: single-lb rules: - host: example.com http: paths: - path: / pathType: Prefix backend: service: name: example-3 port: number: 80
运行以下命令来创建
Ingress
资源:$ oc create -f sample-multiple-ingress.yaml