Set loadBalancerSourceRanges and loadBalancerClass on the gateway and leafnode Services #11
Labels
No labels
accessibility
bug
dependencies
documentation
duplicate
enhancement
go
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mikluko/nats-operator#11
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
ServiceTemplateacceptstypeandannotations.Add
loadBalancerSourceRangesandloadBalancerClassto it.Then
gateway.serviceandleafnodes.servicecan state which clients a load balancer accepts and which implementation serves it.Problem
A
NatsClusterwithgateway.service.typeset to LoadBalancer gets a load balancer that accepts what the platform accepts by default.The observation comes from EKS Auto Mode with Kubernetes 1.36 and nats-operator 0.1.1.
An internal load balancer created this way accepted connections from VPCs peered with the Kubernetes cluster's VPC.
That default matters most for a gateway without TLS.
The install page says that under
--allow-gateway-without-tls"any peer that reaches the gateway port joins the supercluster".For such a gateway the network is the only admission, and the template cannot narrow it.
An annotation does not close the gap on every platform.
The EKS Auto Mode load balancer documentation directs you from the
service.beta.kubernetes.io/load-balancer-source-rangesannotation tospec.loadBalancerSourceRanges.The same page directs you from the
service.beta.kubernetes.io/aws-load-balancer-typeannotation tospec.loadBalancerClass.Proposed fields
The table lists the two fields to add to
ServiceTemplateinapi/cluster/v1beta1/natscluster_types.go.loadBalancerSourceRangesspec.loadBalancerSourceRangestypeis LoadBalancer.loadBalancerClassspec.loadBalancerClasstypeis LoadBalancer. Refused when it changes.Kubernetes rejects a change to
spec.loadBalancerClass.The API describes the field with "Once set, it can not be changed".
A transition rule on the
NatsClusterreports that refusal when you apply the manifest.A gateway that uses both fields looks like this:
Controller changes
The cluster controller renders and updates each Service in separate places, and both need the fields.
gatewayServiceininternal/natscluster/objects.goandleafnodesServiceininternal/natscluster/leafnodes.gocopy the two fields from the template into the Service.applySharedininternal/natscluster/controller.goandapplyLeafnodesininternal/natscluster/leafnodes.goupdate an existing Service field by field. Each copies the two fields too. Without that, an edit to the template never reaches a Service that exists.