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

  1. Create an IngressClassParams resource YAML file, for example, sample-single-lb-params.yaml, as follows:

    1. apiVersion: elbv2.k8s.aws/v1beta1 (1)
    2. kind: IngressClassParams
    3. metadata:
    4. name: <single-lb-params> (2)
    5. spec:
    6. group:
    7. name: single-lb (3)
    1Defines the API group and version of the IngressClassParams resource.
    2Specifies the name of the IngressClassParams resource.
    3Specifies the name of the IngressGroup. All Ingresses of this class belong to this IngressGroup.
  2. Create an IngressClassParams resource by running the following command:

    1. $ oc create -f sample-single-lb-params.yaml
  3. Create an IngressClass resource YAML file, for example, sample-single-lb.yaml, as follows:

    1. apiVersion: networking.k8s.io/v1 (1)
    2. kind: IngressClass
    3. metadata:
    4. name: <single-lb> (2)
    5. spec:
    6. controller: ingress.k8s.aws/alb (3)
    7. parameters:
    8. apiGroup: elbv2.k8s.aws (4)
    9. kind: IngressClassParams (5)
    10. name: single-lb (6)
    1Defines the API group and the version of the IngressClass resource.
    2Specifies the name of the IngressClass.
    3Defines the controller name, common for all IngressClasses. The aws-load-balancer-controller reconciles the controller.
    4Defines the API group of the IngressClassParams resource.
    5Defines the resource type of the IngressClassParams resource.
    6Defines the name of the IngressClassParams resource.
  4. Create an IngressClass resource by running the following command:

    1. $ oc create -f sample-single-lb.yaml
  5. Create an Ingress resource YAML file, for example, sample-multiple-ingress.yaml, as follows:

    1. apiVersion: networking.k8s.io/v1 (1)
    2. kind: Ingress
    3. metadata:
    4. name: <example-1> (1)
    5. annotations:
    6. alb.ingress.kubernetes.io/scheme: internet-facing (2)
    7. alb.ingress.kubernetes.io/group.order: "1" (3)
    8. spec:
    9. ingressClass: alb (4)
    10. rules:
    11. - host: example.com (5)
    12. http:
    13. paths:
    14. - path: /blog (6)
    15. backend:
    16. service:
    17. name: <example-1> (7)
    18. port:
    19. number: 80 (8)
    20. kind: Ingress
    21. metadata:
    22. name: <example-2>
    23. annotations:
    24. alb.ingress.kubernetes.io/scheme: internet-facing
    25. alb.ingress.kubernetes.io/group.order: "2"
    26. spec:
    27. ingressClass: alb
    28. rules:
    29. - host: example.com
    30. http:
    31. paths:
    32. - path: /store
    33. backend:
    34. service:
    35. name: <example-2>
    36. port:
    37. number: 80
    38. kind: Ingress
    39. metadata:
    40. name: <example-3>
    41. annotations:
    42. alb.ingress.kubernetes.io/scheme: internet-facing
    43. alb.ingress.kubernetes.io/group.order: "3"
    44. spec:
    45. ingressClass: alb
    46. rules:
    47. - host: example.com
    48. http:
    49. paths:
    50. - path: /
    51. backend:
    52. service:
    53. name: <example-3>
    54. port:
    55. number: 80
    1Specifies the name of an ingress.
    2Indicates the load balancer to provision in the public subnet and makes it accessible over the internet.
    3Specifies the order in which the rules from the Ingresses are matched when the request is received at the load balancer.
    4Specifies the Ingress Class that belongs to this ingress.
    5Defines the name of a domain used for request routing.
    6Defines the path that must route to the service.
    7Defines the name of the service that serves the endpoint configured in the ingress.
    8Defines the port on the service that serves the endpoint.
  6. Create the Ingress resources by running the following command:

    1. $ oc create -f sample-multiple-ingress.yaml