Skip to content

Commit 70b2799

Browse files
authored
Merge pull request #3437 from jerryhe1999/feature-alb-subnets
Feature alb subnets
2 parents 6ecfc62 + e172a9f commit 70b2799

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

docs/deploy/configurations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,4 @@ They are a set of kye=value pairs that describe AWS load balance controller feat
172172
| EnableRGTAPI | string | false | If enabled, the tagging manager will describe resource tags via RGT APIs, otherwise via ELB APIs. In order to enable RGT API, `tag:GetResources` is needed in controller IAM policy. |
173173
| SubnetsClusterTagCheck | string | true | Enable or disable the check for `kubernetes.io/cluster/${cluster-name}` during subnet auto-discovery |
174174
| NLBHealthCheckAdvancedConfiguration | string | true | Enable or disable advanced health check configuration for NLB, for example health check timeout |
175+
| ALBSingleSubnet | string | false | If enabled, controller will allow using only 1 subnet for provisioning ALB, which need to get whitelisted by ELB in advance |

docs/deploy/subnet_discovery.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Subnet auto-discovery
2-
By default, the AWS Load Balancer Controller (LBC) auto-discovers network subnets that it can create AWS Network Load Balancers (NLB) and AWS Application Load Balancers (ALB) in. ALBs require at least two subnets across Availability Zones. NLBs require one subnet.
2+
By default, the AWS Load Balancer Controller (LBC) auto-discovers network subnets that it can create AWS Network Load Balancers (NLB) and AWS Application Load Balancers (ALB) in. ALBs require at least two subnets across Availability Zones by default,
3+
set [Feature Gate ALBSingleSubnet](https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/configurations/#feature-gates) to "true" allows using only 1 subnet for provisioning ALB. NLBs require one subnet.
34
The subnets must be tagged appropriately for auto-discovery to work. The controller chooses one subnet from each Availability Zone. During auto-discovery, the controller
45
considers subnets with at least eight available IP addresses. In the case of multiple qualified tagged subnets in an Availability Zone, the controller chooses the first one in lexicographical
56
order by the subnet IDs.

helm/aws-load-balancer-controller/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ controllerConfig:
321321
# EnableIPTargetType: true
322322
# SubnetsClusterTagCheck: true
323323
# NLBHealthCheckAdvancedConfig: true
324+
# ALBSingleSubnet: false
324325

325326
# objectSelector for webhook
326327
objectSelector:

pkg/config/feature_gates.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
SubnetsClusterTagCheck Feature = "SubnetsClusterTagCheck"
2222
NLBHealthCheckAdvancedConfig Feature = "NLBHealthCheckAdvancedConfig"
2323
NLBSecurityGroup Feature = "NLBSecurityGroup"
24+
ALBSingleSubnet Feature = "ALBSingleSubnet"
2425
)
2526

2627
type FeatureGates interface {
@@ -58,6 +59,7 @@ func NewFeatureGates() FeatureGates {
5859
SubnetsClusterTagCheck: true,
5960
NLBHealthCheckAdvancedConfig: true,
6061
NLBSecurityGroup: true,
62+
ALBSingleSubnet: false,
6163
},
6264
}
6365
}

pkg/ingress/model_build_load_balancer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(ctx context.Cont
215215
networking.WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
216216
networking.WithSubnetsResolveLBScheme(scheme),
217217
networking.WithSubnetsClusterTagCheck(t.featureGates.Enabled(config.SubnetsClusterTagCheck)),
218+
networking.WithALBSingleSubnet(t.featureGates.Enabled(config.ALBSingleSubnet)),
218219
)
219220
if err != nil {
220221
return nil, err
@@ -233,6 +234,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(ctx context.Cont
233234
chosenSubnets, err := t.subnetsResolver.ResolveViaNameOrIDSlice(ctx, chosenSubnetNameOrIDs,
234235
networking.WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
235236
networking.WithSubnetsResolveLBScheme(scheme),
237+
networking.WithALBSingleSubnet(t.featureGates.Enabled(config.ALBSingleSubnet)),
236238
)
237239
if err != nil {
238240
return nil, err

pkg/networking/subnet_resolver.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type SubnetsResolveOptions struct {
4848
AvailableIPAddressCount int64
4949
// whether to check the cluster tag
5050
SubnetsClusterTagCheck bool
51+
// whether to allow using only 1 subnet for provisioning ALB, default to false
52+
ALBSingleSubnet bool
5153
}
5254

5355
// ApplyOptions applies slice of SubnetsResolveOption.
@@ -95,6 +97,13 @@ func WithSubnetsClusterTagCheck(SubnetsClusterTagCheck bool) SubnetsResolveOptio
9597
}
9698
}
9799

100+
// WithALBSingleSubnet generate an option that configures ALBSingleSubnet
101+
func WithALBSingleSubnet(ALBSingleSubnet bool) SubnetsResolveOption {
102+
return func(opts *SubnetsResolveOptions) {
103+
opts.ALBSingleSubnet = ALBSingleSubnet
104+
}
105+
}
106+
98107
// SubnetsResolver is responsible for resolve EC2 Subnets for Load Balancers.
99108
type SubnetsResolver interface {
100109
// ResolveViaDiscovery resolve subnets by auto discover matching subnets.
@@ -364,7 +373,7 @@ func (r *defaultSubnetsResolver) validateSubnetsMinimalCount(subnets []*ec2sdk.S
364373
// computeSubnetsMinimalCount returns the minimal count requirement for subnets.
365374
func (r *defaultSubnetsResolver) computeSubnetsMinimalCount(subnetLocale subnetLocaleType, resolveOpts SubnetsResolveOptions) int {
366375
minimalCount := 1
367-
if resolveOpts.LBType == elbv2model.LoadBalancerTypeApplication && subnetLocale == subnetLocaleTypeAvailabilityZone {
376+
if resolveOpts.LBType == elbv2model.LoadBalancerTypeApplication && subnetLocale == subnetLocaleTypeAvailabilityZone && !resolveOpts.ALBSingleSubnet {
368377
minimalCount = 2
369378
}
370379
return minimalCount

0 commit comments

Comments
 (0)