Creating multiple ingresses
You can route the traffic to different services that are part of a single domain through a single AWS Load Balancer (ALB). Each Ingress resource provides different endpoints of the domain.
Creating multiple ingresses through a single AWS Load Balancer
You can route the traffic to multiple Ingresses through a single AWS Load Balancer (ALB) by using the CLI.
Prerequisites
- You have an access to the OpenShift CLI (
oc
).
Procedure
Create an
IngressClassParams
resource YAML file, for example,sample-single-lb-params.yaml
, as follows:apiVersion: elbv2.k8s.aws/v1beta1 (1)
kind: IngressClassParams
metadata:
name: <single-lb-params> (2)
spec:
group:
name: single-lb (3)
1 Defines the API group and version of the IngressClassParams
resource.2 Specifies the name of the IngressClassParams
resource.3 Specifies the name of the IngressGroup
. All Ingresses of this class belong to thisIngressGroup
.Create an
IngressClassParams
resource by running the following command:$ oc create -f sample-single-lb-params.yaml
Create an
IngressClass
resource YAML file, for example,sample-single-lb.yaml
, as follows: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 (6)
1 Defines the API group and the version of the IngressClass
resource.2 Specifies the name of the IngressClass
.3 Defines the controller name, common for all IngressClasses
. Theaws-load-balancer-controller
reconciles the controller.4 Defines the API group of the IngressClassParams
resource.5 Defines the resource type of the IngressClassParams
resource.6 Defines the name of the IngressClassParams
resource.Create an
IngressClass
resource by running the following command:$ oc create -f sample-single-lb.yaml
Create an
Ingress
resource YAML file, for example,sample-multiple-ingress.yaml
, as follows:apiVersion: networking.k8s.io/v1 (1)
kind: Ingress
metadata:
name: <example-1> (1)
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing (2)
alb.ingress.kubernetes.io/group.order: "1" (3)
spec:
ingressClass: alb (4)
rules:
- host: example.com (5)
http:
paths:
- path: /blog (6)
backend:
service:
name: <example-1> (7)
port:
number: 80 (8)
kind: Ingress
metadata:
name: <example-2>
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/group.order: "2"
spec:
ingressClass: alb
rules:
- host: example.com
http:
paths:
- path: /store
backend:
service:
name: <example-2>
port:
number: 80
kind: Ingress
metadata:
name: <example-3>
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/group.order: "3"
spec:
ingressClass: alb
rules:
- host: example.com
http:
paths:
- path: /
backend:
service:
name: <example-3>
port:
number: 80
1 Specifies the name of an ingress. 2 Indicates the load balancer to provision in the public subnet and makes it accessible over the internet. 3 Specifies the order in which the rules from the Ingresses are matched when the request is received at the load balancer. 4 Specifies the Ingress Class that belongs to this ingress. 5 Defines the name of a domain used for request routing. 6 Defines the path that must route to the service. 7 Defines the name of the service that serves the endpoint configured in the ingress. 8 Defines the port on the service that serves the endpoint. Create the
Ingress
resources by running the following command:$ oc create -f sample-multiple-ingress.yaml