Questo contenuto non è disponibile nella lingua selezionata.
Chapter 19. AWS Load Balancer Operator
19.1. AWS Load Balancer Operator in OpenShift Container Platform Copia collegamentoCollegamento copiato negli appunti!
The AWS Load Balancer (ALB) Operator deploys and manages an instance of the
aws-load-balancer-controller
19.1.1. AWS Load Balancer Operator considerations Copia collegamentoCollegamento copiato negli appunti!
Review the following limitations before installing and using the AWS Load Balancer Operator.
- The IP traffic mode only works on AWS Elastic Kubernetes Service (EKS). The AWS Load Balancer Operator disables the IP traffic mode for the AWS Load Balancer Controller. As a result of disabling the IP traffic mode, the AWS Load Balancer Controller cannot use the pod readiness gate.
-
The AWS Load Balancer Operator adds command-line flags such as and
--disable-ingress-class-annotationto the AWS Load Balancer Controller. Therefore, the AWS Load Balancer Operator does not allow using the--disable-ingress-group-name-annotationandkubernetes.io/ingress.classannotations in thealb.ingress.kubernetes.io/group.nameresource.Ingress
19.1.2. AWS Load Balancer Operator Copia collegamentoCollegamento copiato negli appunti!
The AWS Load Balancer Operator can tag the public subnets if the
kubernetes.io/role/elb
- The ID of the virtual private cloud (VPC) on which the cluster hosting the Operator is deployed in.
- Public and private subnets of the discovered VPC.
Prerequisites
- You must have the AWS credentials secret. The credentials are used to provide subnet tagging and VPC discovery.
Procedure
You can deploy the AWS Load Balancer Operator on demand from the OperatorHub, by creating a
object:Subscription$ oc -n aws-load-balancer-operator get sub aws-load-balancer-operator --template='{{.status.installplan.name}}{{"\n"}}'Example output
install-zlfbtCheck the status of an install plan. The status of an install plan must be
:Complete$ oc -n aws-load-balancer-operator get ip <install_plan_name> --template='{{.status.phase}}{{"\n"}}'Example output
CompleteUse the
command to view theoc getstatus:Deployment$ oc get -n aws-load-balancer-operator deployment/aws-load-balancer-operator-controller-managerExample output
NAME READY UP-TO-DATE AVAILABLE AGE aws-load-balancer-operator-controller-manager 1/1 1 1 23h
19.1.3. AWS Load Balancer Operator logs Copia collegamentoCollegamento copiato negli appunti!
Use the
oc logs
Procedure
View the logs of the AWS Load Balancer Operator:
$ oc logs -n aws-load-balancer-operator deployment/aws-load-balancer-operator-controller-manager -c manager
19.2. Understanding AWS Load Balancer Operator Copia collegamentoCollegamento copiato negli appunti!
The AWS Load Balancer (ALB) Operator deploys and manages an instance of the
aws-load-balancer-controller
19.2.1. Installing the AWS Load Balancer Operator Copia collegamentoCollegamento copiato negli appunti!
You can install the AWS Load Balancer Operator from the OperatorHub by using the OpenShift Container Platform web console.
Prerequisites
-
You have logged in to the OpenShift Container Platform web console as a user with permissions.
cluster-admin - Your cluster is configured with AWS as the platform type and cloud provider.
Procedure
-
Navigate to Operators
OperatorHub in the OpenShift Container Platform web console. - Select the AWS Load Balancer Operator. You can use the Filter by keyword text box or use the filter list to search for the AWS Load Balancer Operator from the list of Operators.
-
Select the namespace.
aws-load-balancer-operator - Follow the instructions to prepare the Operator for installation.
- On the AWS Load Balancer Operator page, click Install.
On the Install Operator page, select the following options:
- Update the channel as stable-v0.1.
- Installation mode as A specific namespace on the cluster.
-
Installed Namespace as . If the
aws-load-balancer-operatornamespace does not exist, it gets created during the Operator installation.aws-load-balancer-operator - Select Update approval as Automatic or Manual. By default, the Update approval is set to Automatic. If you select automatic updates, the Operator Lifecycle Manager (OLM) automatically upgrades the running instance of your Operator without any intervention. If you select manual updates, the OLM creates an update request. As a cluster administrator, you must then manually approve that update request to update the Operator updated to the new version.
- Click Install.
Verification
- Verify that the AWS Load Balancer Operator shows the Status as Succeeded on the Installed Operators dashboard.
19.3. Creating an instance of AWS Load Balancer Controller Copia collegamentoCollegamento copiato negli appunti!
After installing the Operator, you can create an instance of the AWS Load Balancer Controller.
19.3.1. Creating an instance of the AWS Load Balancer Controller using AWS Load Balancer Operator Copia collegamentoCollegamento copiato negli appunti!
You can install only a single instance of the
aws-load-balancer-controller
cluster
Prerequisites
-
You have created the namespace.
echoserver -
You have access to the OpenShift CLI ().
oc
Procedure
Create an
resource YAML file, for example,aws-load-balancer-controller, as follows:sample-aws-lb.yamlapiVersion: networking.olm.openshift.io/v1alpha1 kind: AWSLoadBalancerController1 metadata: name: cluster2 spec: subnetTagging: Auto3 additionalResourceTags:4 example.org/cost-center: 5113232 example.org/security-scope: staging ingressClass: alb5 config: replicas: 26 enabledAddons:7 - AWSWAFv28 - 1
- Defines the
aws-load-balancer-controllerresource. - 2
- Defines the AWS Load Balancer Controller instance name. This instance name gets added as a suffix to all related resources.
- 3
- Valid options are
AutoandManual. When the value is set toAuto, 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 toManual. - 4
- Defines the tags used by the controller when it provisions AWS resources.
- 5
- The default value for this field is
alb. The Operator provisions anIngressClassresource with the same name if it does not exist. - 6
- Specifies the number of replicas of the controller.
- 7
- Specifies add-ons for AWS load balancers, which get specified through annotations.
- 8
- Enables the
alb.ingress.kubernetes.io/wafv2-acl-arnannotation.
Create a
resource by running the following command:aws-load-balancer-controller$ oc create -f sample-aws-lb.yamlAfter the AWS Load Balancer Controller is running, create a
resource:deploymentapiVersion: apps/v1 kind: Deployment1 metadata: name: <echoserver>2 namespace: echoserver spec: selector: matchLabels: app: echoserver replicas: 33 template: metadata: labels: app: echoserver spec: containers: - image: openshift/origin-node args: - TCP4-LISTEN:8080,reuseaddr,fork - EXEC:'/bin/bash -c \"printf \\\"HTTP/1.0 200 OK\r\n\r\n\\\"; sed -e \\\"/^\r/q\\\"\"' imagePullPolicy: Always name: echoserver ports: - containerPort: 8080Create a
resource:serviceapiVersion: v1 kind: Service1 metadata: name: <echoserver>2 namespace: echoserver spec: ports: - port: 80 targetPort: 8080 protocol: TCP type: NodePort selector: app: echoserverDeploy an ALB-backed
resource:IngressapiVersion: networking.k8s.io/v1 kind: Ingress1 metadata: name: <echoserver>2 namespace: echoserver annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: instance spec: ingressClassName: alb rules: - http: paths: - path: / pathType: Exact backend: service: name: <echoserver>3 port: number: 80
Verification
Verify the status of the
resource to show the host of the provisioned AWS Load Balancer (ALB) by running the following command:Ingress$ HOST=$(kubectl get ingress -n echoserver echoserver -o json | jq -r '.status.loadBalancer.ingress[0].hostname')Verify the status of the provisioned AWS Load Balancer (ALB) host by running the following command:
$ curl $HOST
19.4. Creating multiple ingresses Copia collegamentoCollegamento copiato negli appunti!
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.
19.4.1. Creating multiple ingresses through a single AWS Load Balancer Copia collegamentoCollegamento copiato negli appunti!
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
resource YAML file, for example,IngressClassParams, as follows:sample-single-lb-params.yamlapiVersion: elbv2.k8s.aws/v1beta11 kind: IngressClassParams metadata: name: single-lb-params2 spec: group: name: single-lb3 Create an
resource by running the following command:IngressClassParams$ oc create -f sample-single-lb-params.yamlCreate an
resource YAML file, for example,IngressClass, as follows:sample-single-lb-class.yamlapiVersion: networking.k8s.io/v11 kind: IngressClass metadata: name: single-lb2 spec: controller: ingress.k8s.aws/alb3 parameters: apiGroup: elbv2.k8s.aws4 kind: IngressClassParams5 name: single-lb-params6 - 1
- Defines the API group and version of the
IngressClassresource. - 2
- Specifies the name of the
IngressClass. - 3
- Defines the controller name.
ingress.k8s.aws/albdenotes that all Ingresses of this class should be managed by theaws-load-balancer-controller. - 4
- Defines the API group of the
IngressClassParamsresource. - 5
- Defines the resource type of the
IngressClassParamsresource. - 6
- Defines the name of the
IngressClassParamsresource.
Create an
resource by running the following command:IngressClass$ oc create -f sample-single-lb-class.yamlCreate an
resource YAML file, for example,AWSLoadBalancerController, as follows:sample-single-lb.yamlapiVersion: networking.olm.openshift.io/v1 kind: AWSLoadBalancerController metadata: name: cluster spec: subnetTagging: Auto ingressClass: single-lb1 - 1
- Defines the name of the
IngressClassresource.
Create an
resource by running the following command:AWSLoadBalancerController$ oc create -f sample-single-lb.yamlCreate an
resource YAML file, for example,Ingress, as follows:sample-multiple-ingress.yamlapiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-11 annotations: alb.ingress.kubernetes.io/scheme: internet-facing2 alb.ingress.kubernetes.io/group.order: "1"3 alb.ingress.kubernetes.io/target-type: instance4 spec: ingressClassName: single-lb5 rules: - host: example.com6 http: paths: - path: /blog7 pathType: Prefix backend: service: name: example-18 port: number: 809 --- 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- 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
- Indicates the load balancer will target OpenShift nodes to reach the service.
- 5
- Specifies the Ingress Class that belongs to this ingress.
- 6
- Defines the name of a domain used for request routing.
- 7
- Defines the path that must route to the service.
- 8
- Defines the name of the service that serves the endpoint configured in the ingress.
- 9
- Defines the port on the service that serves the endpoint.
Create the
resources by running the following command:Ingress$ oc create -f sample-multiple-ingress.yaml
19.5. Adding TLS termination Copia collegamentoCollegamento copiato negli appunti!
You can add TLS termination on the AWS Load Balancer.
19.5.1. Adding TLS termination on the AWS Load Balancer Copia collegamentoCollegamento copiato negli appunti!
You can route the traffic for the domain to pods of a service and add TLS termination on the AWS Load Balancer.
Prerequisites
-
You have an access to the OpenShift CLI ().
oc
Procedure
Install the Operator and create an instance of the
resource:aws-load-balancer-controllerapiVersion: networking.k8s.io/v1 kind: AWSLoadBalancerController group: networking.olm.openshift.io/v1alpha11 metadata: name: cluster spec: subnetTagging: Auto ingressClass: tls-termination2 - 1 2
- Defines the name of an
ingressClassresource reconciled by the AWS Load Balancer Controller. ThisingressClassresource gets created if it is not present. You can add additionalingressClassvalues. The controller reconciles theingressClassvalues if thespec.controlleris set toingress.k8s.aws/alb.
Create an
resource:IngressapiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: <example>1 annotations: alb.ingress.kubernetes.io/scheme: internet-facing2 alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-west-2:xxxxx3 spec: ingressClassName: tls-termination4 rules: - host: <example.com>5 http: paths: - path: / pathType: Exact backend: service: name: <example-service>6 port: number: 80- 1
- Specifies the name of an ingress.
- 2
- The controller provisions the load balancer for this
Ingressresource in a public subnet so that the load balancer is reachable over the internet. - 3
- The Amazon Resource Name of the certificate that you attach to the load balancer.
- 4
- Defines the ingress class name.
- 5
- Defines the domain for traffic routing.
- 6
- Defines the service for traffic routing.