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-class.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-params (6)
    1Defines the API group and version of the IngressClass resource.
    2Specifies the name of the IngressClass.
    3Defines the controller name. ingress.k8s.aws/alb denotes that all Ingresses of this class should be managed by the aws-load-balancer-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-class.yaml
  5. Create an AWSLoadBalancerController resource YAML file, for example, sample-single-lb.yaml, as follows:

    1. apiVersion: networking.olm.openshift.io/v1
    2. kind: AWSLoadBalancerController
    3. metadata:
    4. name: cluster
    5. spec:
    6. subnetTagging: Auto
    7. ingressClass: single-lb (1)
    1Defines the name of the IngressClass resource.
  6. Create an AWSLoadBalancerController resource by running the following command:

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

    1. apiVersion: networking.k8s.io/v1
    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. alb.ingress.kubernetes.io/target-type: instance (4)
    9. spec:
    10. ingressClassName: single-lb (5)
    11. rules:
    12. - host: example.com (6)
    13. http:
    14. paths:
    15. - path: /blog (7)
    16. pathType: Prefix
    17. backend:
    18. service:
    19. name: example-1 (8)
    20. port:
    21. number: 80 (9)
    22. ---
    23. apiVersion: networking.k8s.io/v1
    24. kind: Ingress
    25. metadata:
    26. name: example-2
    27. annotations:
    28. alb.ingress.kubernetes.io/scheme: internet-facing
    29. alb.ingress.kubernetes.io/group.order: "2"
    30. alb.ingress.kubernetes.io/target-type: instance
    31. spec:
    32. ingressClassName: single-lb
    33. rules:
    34. - host: example.com
    35. http:
    36. paths:
    37. - path: /store
    38. pathType: Prefix
    39. backend:
    40. service:
    41. name: example-2
    42. port:
    43. number: 80
    44. ---
    45. apiVersion: networking.k8s.io/v1
    46. kind: Ingress
    47. metadata:
    48. name: example-3
    49. annotations:
    50. alb.ingress.kubernetes.io/scheme: internet-facing
    51. alb.ingress.kubernetes.io/group.order: "3"
    52. alb.ingress.kubernetes.io/target-type: instance
    53. spec:
    54. ingressClassName: single-lb
    55. rules:
    56. - host: example.com
    57. http:
    58. paths:
    59. - path: /
    60. pathType: Prefix
    61. backend:
    62. service:
    63. name: example-3
    64. port:
    65. 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.
    4Indicates the load balancer will target OpenShift nodes to reach the service.
    5Specifies the Ingress Class that belongs to this ingress.
    6Defines the name of a domain used for request routing.
    7Defines the path that must route to the service.
    8Defines the name of the service that serves the endpoint configured in the ingress.
    9Defines the port on the service that serves the endpoint.
  8. Create the Ingress resources by running the following command:

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