Creating an instance of AWS Load Balancer Controller

After installing the Operator, you can create an instance of the AWS Load Balancer Controller.

Creating an instance of the AWS Load Balancer Controller using AWS Load Balancer Operator

You can install only a single instance of the aws-load-balancer-controller in a cluster. You can create the AWS Load Balancer Controller by using CLI. The AWS Load Balancer(ALB) Operator reconciles only the resource with the name cluster.

Prerequisites

  • You have created the echoserver namespace.

  • You have access to the OpenShift CLI (oc).

Procedure

  1. Create an aws-load-balancer-controller resource YAML file, for example, sample-aws-lb.yaml, as follows:

    1. apiVersion: networking.olm.openshift.io/v1alpha1
    2. kind: AWSLoadBalancerController (1)
    3. metadata:
    4. name: cluster (2)
    5. spec:
    6. subnetTagging: Auto (3)
    7. additionalResourceTags: (4)
    8. example.org/cost-center: 5113232
    9. example.org/security-scope: staging
    10. ingressClass: cloud (5)
    11. config:
    12. replicas: 2 (6)
    13. enabledAddons: (7)
    14. - AWSWAFv2 (8)
    1Defines the aws-load-balancer-controller resource.
    2Defines the AWS Load Balancer Controller instance name. This instance name gets added as a suffix to all related resources.
    3Valid options are Auto and Manual. When the value is set to Auto, the Operator attempts to determine the subnets that belong to the cluster and tags them appropriately. The Operator cannot determine the role correctly if the internal subnet tags are not present on internal subnet. If you installed your cluster on user-provided infrastructure, you can manually tag the subnets with the appropriate role tags and set the subnet tagging policy to Manual.
    4Defines the tags used by the controller when it provisions AWS resources.
    5The default value for this field is alb. The Operator provisions an IngressClass resource with the same name if it does not exist.
    6Specifies the number of replicas of the controller.
    7Specifies add-ons for AWS load balancers, which get specified through annotations.
    8Enables the alb.ingress.kubernetes.io/wafv2-acl-arn annotation.
  2. Create a aws-load-balancer-controller resource by running the following command:

    1. $ oc create -f sample-aws-lb.yaml
  3. After the AWS Load Balancer Controller is running, create a deployment resource:

    1. apiVersion: apps/v1
    2. kind: Deployment (1)
    3. metadata:
    4. name: <echoserver> (2)
    5. namespace: echoserver
    6. spec:
    7. selector:
    8. matchLabels:
    9. app: echoserver
    10. replicas: 3 (3)
    11. template:
    12. metadata:
    13. labels:
    14. app: echoserver
    15. spec:
    16. containers:
    17. - image: openshift/origin-node
    18. command:
    19. - "/bin/socat"
    20. args:
    21. - TCP4-LISTEN:8080,reuseaddr,fork
    22. - EXEC:'/bin/bash -c \"printf \\\"HTTP/1.0 200 OK\r\n\r\n\\\"; sed -e \\\"/^\r/q\\\"\"'
    23. imagePullPolicy: Always
    24. name: echoserver
    25. ports:
    26. - containerPort: 8080
    1Defines the deployment resource.
    2Specifies the deployment name.
    3Specifies the number of replicas of the deployment.
  4. Create a service resource:

    1. apiVersion: v1
    2. kind: Service (1)
    3. metadata:
    4. name: <echoserver> (2)
    5. namespace: echoserver
    6. spec:
    7. ports:
    8. - port: 80
    9. targetPort: 8080
    10. protocol: TCP
    11. type: NodePort
    12. selector:
    13. app: echoserver
    1Defines the service resource.
    2Specifies the name of the service.
  5. Deploy an ALB-backed Ingress resource:

    1. apiVersion: networking.k8s.io/v1
    2. kind: Ingress (1)
    3. metadata:
    4. name: <echoserver> (2)
    5. namespace: echoserver
    6. annotations:
    7. alb.ingress.kubernetes.io/scheme: internet-facing
    8. alb.ingress.kubernetes.io/target-type: instance
    9. spec:
    10. ingressClassName: alb
    11. rules:
    12. - http:
    13. paths:
    14. - path: /
    15. pathType: Exact
    16. backend:
    17. service:
    18. name: <echoserver> (3)
    19. port:
    20. number: 80
    1Defines the ingress resource.
    2Specifies the name of the ingress resource.
    3Specifies the name of the service resource.

Verification

  • Verify the status of the Ingress resource to show the host of the provisioned AWS Load Balancer (ALB) by running the following command:

    1. $ HOST=$(oc get ingress -n echoserver echoserver --template='{{(index .status.loadBalancer.ingress 0).hostname}}')
  • Verify the status of the provisioned AWS Load Balancer (ALB) host by running the following command:

    1. $ curl $HOST