Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#3437 from jerryhe1999/feature-alb-…
Browse files Browse the repository at this point in the history
…subnets

Feature alb subnets
  • Loading branch information
k8s-ci-robot authored Nov 2, 2023
2 parents 6ecfc62 + e172a9f commit 70b2799
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/deploy/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,4 @@ They are a set of kye=value pairs that describe AWS load balance controller feat
| 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. |
| SubnetsClusterTagCheck | string | true | Enable or disable the check for `kubernetes.io/cluster/${cluster-name}` during subnet auto-discovery |
| NLBHealthCheckAdvancedConfiguration | string | true | Enable or disable advanced health check configuration for NLB, for example health check timeout |
| ALBSingleSubnet | string | false | If enabled, controller will allow using only 1 subnet for provisioning ALB, which need to get whitelisted by ELB in advance |
3 changes: 2 additions & 1 deletion docs/deploy/subnet_discovery.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Subnet auto-discovery
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.
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,
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.
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
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
order by the subnet IDs.
Expand Down
1 change: 1 addition & 0 deletions helm/aws-load-balancer-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ controllerConfig:
# EnableIPTargetType: true
# SubnetsClusterTagCheck: true
# NLBHealthCheckAdvancedConfig: true
# ALBSingleSubnet: false

# objectSelector for webhook
objectSelector:
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/feature_gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
SubnetsClusterTagCheck Feature = "SubnetsClusterTagCheck"
NLBHealthCheckAdvancedConfig Feature = "NLBHealthCheckAdvancedConfig"
NLBSecurityGroup Feature = "NLBSecurityGroup"
ALBSingleSubnet Feature = "ALBSingleSubnet"
)

type FeatureGates interface {
Expand Down Expand Up @@ -58,6 +59,7 @@ func NewFeatureGates() FeatureGates {
SubnetsClusterTagCheck: true,
NLBHealthCheckAdvancedConfig: true,
NLBSecurityGroup: true,
ALBSingleSubnet: false,
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/ingress/model_build_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(ctx context.Cont
networking.WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
networking.WithSubnetsResolveLBScheme(scheme),
networking.WithSubnetsClusterTagCheck(t.featureGates.Enabled(config.SubnetsClusterTagCheck)),
networking.WithALBSingleSubnet(t.featureGates.Enabled(config.ALBSingleSubnet)),
)
if err != nil {
return nil, err
Expand All @@ -233,6 +234,7 @@ func (t *defaultModelBuildTask) buildLoadBalancerSubnetMappings(ctx context.Cont
chosenSubnets, err := t.subnetsResolver.ResolveViaNameOrIDSlice(ctx, chosenSubnetNameOrIDs,
networking.WithSubnetsResolveLBType(elbv2model.LoadBalancerTypeApplication),
networking.WithSubnetsResolveLBScheme(scheme),
networking.WithALBSingleSubnet(t.featureGates.Enabled(config.ALBSingleSubnet)),
)
if err != nil {
return nil, err
Expand Down
11 changes: 10 additions & 1 deletion pkg/networking/subnet_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type SubnetsResolveOptions struct {
AvailableIPAddressCount int64
// whether to check the cluster tag
SubnetsClusterTagCheck bool
// whether to allow using only 1 subnet for provisioning ALB, default to false
ALBSingleSubnet bool
}

// ApplyOptions applies slice of SubnetsResolveOption.
Expand Down Expand Up @@ -95,6 +97,13 @@ func WithSubnetsClusterTagCheck(SubnetsClusterTagCheck bool) SubnetsResolveOptio
}
}

// WithALBSingleSubnet generate an option that configures ALBSingleSubnet
func WithALBSingleSubnet(ALBSingleSubnet bool) SubnetsResolveOption {
return func(opts *SubnetsResolveOptions) {
opts.ALBSingleSubnet = ALBSingleSubnet
}
}

// SubnetsResolver is responsible for resolve EC2 Subnets for Load Balancers.
type SubnetsResolver interface {
// ResolveViaDiscovery resolve subnets by auto discover matching subnets.
Expand Down Expand Up @@ -364,7 +373,7 @@ func (r *defaultSubnetsResolver) validateSubnetsMinimalCount(subnets []*ec2sdk.S
// computeSubnetsMinimalCount returns the minimal count requirement for subnets.
func (r *defaultSubnetsResolver) computeSubnetsMinimalCount(subnetLocale subnetLocaleType, resolveOpts SubnetsResolveOptions) int {
minimalCount := 1
if resolveOpts.LBType == elbv2model.LoadBalancerTypeApplication && subnetLocale == subnetLocaleTypeAvailabilityZone {
if resolveOpts.LBType == elbv2model.LoadBalancerTypeApplication && subnetLocale == subnetLocaleTypeAvailabilityZone && !resolveOpts.ALBSingleSubnet {
minimalCount = 2
}
return minimalCount
Expand Down

0 comments on commit 70b2799

Please sign in to comment.