feat: Support for deploying LB to multiple regions using region property on LoadBalancerConfiguration#4606
Conversation
|
|
Welcome @aleksanderaleksic! |
|
Hi @aleksanderaleksic. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aleksanderaleksic The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
a4ff571 to
8c54c7f
Compare
…lancerConfiguration` Signed-off-by: Aleksander Aleksic <aleksander.aleksic@nordicsemi.no>
8c54c7f to
2708e16
Compare
|
Hi. I wish you would have reached out to discuss this, prior to writing all this code :(. We are unlikely to accept this contribution as AWS offers CDN capabilities already (like CloudFront). What is your use-case? |
|
Hi @zac-nixon. To be honest I did not realize that we could use Cloudfront to get similar results so thanks for enlightening me about that. We have our workloads based in Also we dont want to deploy a EKS cluster in ASIA as of now, so we accept the latency between the edge ALBs and the instances in I hope this gives you a better understanding of why we want to de able to manage ALBs from a different region. Given that the aws-load-balancer-controller does not support multiple deployments in a single cluster and its bound to a single region, we where not able to achieve the same results as with the suggested approach in any other way. |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Description
Motivation: Support deploying edge ALBs in AWS regions closer to end users, enabling TLS termination at the edge to reduce latency. For example, a cluster running in
us-east-1can now deploy an ALB inap-northeast-1via the Gateway API, terminating TLS in Tokyo rather than routing encrypted traffic back to the US.What this PR does
Adds multi-region support to the AWS Load Balancer Controller's Gateway API implementation. A new optional
regionfield onLoadBalancerConfigurationallows users to specify an AWS region for the ALB/NLB, and the controller handles all cross-region resource management automatically.Key changes:
LoadBalancerConfigurationAPI (apis/gateway/v1beta1/loadbalancerconfig_types.go)RegionandVpcIDfields toLoadBalancerConfigurationSpec, allowing users to target a specific AWS region and VPC for the load balancer.ReconcileContext/ Cloud Provider (pkg/gateway/cloud_provider.go)ReconcileContextencapsulates region-specific AWS clients (ELBV2, EC2, ACM) and resolvers (subnets, VPC info, security groups, cert discovery, tagging manager, TG ARN mapper).ReconcileContextis always passed toBuild()— for the default region it wraps the existing clients/resolvers; for non-default regions all fields are region-scoped.IsCrossRegion() boolon the context lets downstream code branch on cross-region without comparing VPC IDs or regions directly.GetReconcileContextauto-discovers the VPC in the target region (viavpcId,vpcSelector, or first subnet) and caches the result.Gateway Controller (
controllers/gateway/gateway_controller.go)ReconcileContextfromCloudProviderand passes it through to the model builder and stack deployer.reconcileContext.IsCrossRegion()to select the region-scoped stack deployer and backend SG provider.Model Builder (
pkg/gateway/model/base_model_builder.go)Build()takes a requiredReconcileContextInterfaceparameter (no variadic/optional). All effective clients and resolvers come from the RC unconditionally.ReconcileContextInterfaceexposesIsCrossRegion()— used to disable backend SG allocation and clear the backend SG token onTargetGroupBindingresources for cross-region gateways (cross-region SG references are not supported by AWS).Region-aware AWS clients (
pkg/aws/region.go)NewCloudForRegion,NewEC2ClientForRegion,NewELBV2ForRegion— factory functions for creating region-scoped AWS service clients without EC2 metadata.regionStubCloud— minimalCloudimplementation for ELBV2-only operations (webhooks, ARN validation).TGB Webhooks (
webhooks/elbv2/targetgroup_helper.go,targetgroupbinding_mutator.go,targetgroupbinding_validator.go)ELBV2ClientProvidertype andresolveELBV2ForTGBhelper extract the region from a target group ARN and return the correct regional ELBV2 client.DescribeTargetGroupscalls, preventingValidationErrorwhen validating cross-region TG ARNs.TGB Reconciler (
pkg/targetgroupbinding/targets_manager.go,resource_manager.go)cachedTargetsManager.resolveELBV2()dynamically selects the correct ELBV2 client based on target group ARN region forRegisterTargets,DeregisterTargets, andDescribeTargetHealth.generateOverrideAzFnnow handles cross-region VPCs (not just cross-account) — when the TGB's VPC differs from the controller's VPC andDescribeVpcsreturnsInvalidVpcID.NotFound, target AZs are overridden to "all".Security Group Synthesizer (
pkg/deploy/ec2/security_group_synthesizer.go)Documentation (
docs/guide/gateway/loadbalancerconfig.md,docs/guide/gateway/spec.md)regionandvpcIDfields with usage examples.Tests
webhooks/elbv2/targetgroup_helper_test.go—regionFromTGARNandresolveELBV2ForTGB(18 cases)pkg/targetgroupbinding/targets_manager_resolve_test.go—cachedTargetsManager.resolveELBV2(7 cases)pkg/aws/region_test.go—regionStubCloudinterface compliance and getters (12 cases)pkg/gateway/cloud_provider_test.go—ReconcileContextgetters,IsCrossRegion(),GetReconcileContextdefault path,resolveVPCForRegion,resolveVPCFromSelector,resolveVPCFromFirstSubnet(21 cases)pkg/targetgroupbinding/resource_manager_test.go— cross-region VPC override AZ test casepkg/gateway/model/model_build_target_group_binding_network_test.go— nil backend SG token (cross-region) caseExample usage
Checklist
README.md, or thedocsdirectory)BONUS POINTS checklist