Skip to content

Commit e36372f

Browse files
author
Rahul Sharma
committed
fix loadbalancer update and add documentation
1 parent e16988c commit e36372f

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

cloud/annotations/annotations.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const (
3535
AnnLinodeNodeIPSharingUpdated = "node.k8s.linode.com/ip-sharing-updated"
3636

3737
NodeBalancerBackendIPv4Range = "service.beta.kubernetes.io/linode-loadbalancer-backend-ipv4-range"
38-
NodeBalancerBackendIPv6Range = "service.beta.kubernetes.io/linode-loadbalancer-backend-ipv6-range"
3938

4039
NodeBalancerBackendVPCName = "service.beta.kubernetes.io/linode-loadbalancer-backend-vpc-name"
4140
NodeBalancerBackendSubnetName = "service.beta.kubernetes.io/linode-loadbalancer-backend-subnet-name"

cloud/linode/loadbalancers.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,14 @@ func (l *loadbalancers) updateNodeBalancer(
384384
// Add all of the Nodes to the config
385385
newNBNodes := make([]linodego.NodeBalancerConfigRebuildNodeOptions, 0, len(nodes))
386386
subnetID := 0
387-
if nb.GetCreateOptions().VPCs != nil {
388-
subnetID = nb.GetCreateOptions().VPCs[0].SubnetID
387+
_, ok := service.GetAnnotations()[annotations.NodeBalancerBackendIPv4Range]
388+
if ok {
389+
id, err := l.getSubnetIDForSVC(ctx, service)
390+
if err != nil {
391+
sentry.CaptureError(ctx, err)
392+
return fmt.Errorf("Error getting subnet ID for service %s: %v", service.Name, err)
393+
}
394+
subnetID = id
389395
}
390396
for _, node := range nodes {
391397
newNodeOpts := l.buildNodeBalancerNodeConfigRebuildOptions(node, port.NodePort, subnetID)
@@ -774,6 +780,9 @@ func (l *loadbalancers) addTLSCert(ctx context.Context, service *v1.Service, nbC
774780
return nil
775781
}
776782

783+
// getSubnetIDForSVC returns the subnet ID for the service's VPC and subnet.
784+
// By default, first VPCName and SubnetName are used to calculate subnet id for the service.
785+
// If the service has annotations specifying VPCName and SubnetName, they are used instead.
777786
func (l *loadbalancers) getSubnetIDForSVC(ctx context.Context, service *v1.Service) (int, error) {
778787
if Options.VPCNames == "" {
779788
return 0, fmt.Errorf("CCM not configured with VPC, cannot create NodeBalancer with specified annotation")

docs/configuration/annotations.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ For implementation details, see:
3232
| `tags` | string | | A comma separated list of tags to be applied to the NodeBalancer instance |
3333
| `firewall-id` | string | | An existing Cloud Firewall ID to be attached to the NodeBalancer instance. See [Firewall Setup](firewall.md) |
3434
| `firewall-acl` | string | | The Firewall rules to be applied to the NodeBalancer. See [Firewall Configuration](#firewall-configuration) |
35+
| `backend-ipv4-range` | string | | The IPv4 range from VPC subnet to be applied to the NodeBalancer backend. See [Nodebalancer VPC Configuration](#nodebalancer-vpc-configuration) |
36+
| `backend-vpc-name` | string | | VPC which is connected to the NodeBalancer backend. See [Nodebalancer VPC Configuration](#nodebalancer-vpc-configuration) |
37+
| `backend-subnet-name` | string | | Subnet within VPC which is connected to the NodeBalancer backend. See [Nodebalancer VPC Configuration](#nodebalancer-vpc-configuration) |
3538

3639
### Port Specific Configuration
3740

@@ -104,6 +107,15 @@ metadata:
104107
}
105108
```
106109
110+
### Nodebalancer VPC Configuration
111+
```yaml
112+
metadata:
113+
annotations:
114+
service.beta.kubernetes.io/linode-loadbalancer-backend-ipv4-range: "10.100.0.0/30"
115+
service.beta.kubernetes.io/linode-loadbalancer-vpc-name: "vpc1"
116+
service.beta.kubernetes.io/linode-loadbalancer-subnet-name: "subnet1"
117+
```
118+
107119
For more examples and detailed configuration options, see:
108120
- [LoadBalancer Configuration](loadbalancer.md)
109121
- [Firewall Configuration](firewall.md)

docs/configuration/loadbalancer.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ metadata:
120120

121121
## BGP-based IP Sharing Implementation
122122

123-
BGP-based IP sharing provides a more cost-effective solution for multiple LoadBalancer services. For detailed setup instructions, see [Cilium BGP Documentation](https://docs.cilium.io/en/stable/network/bgp-control-plane/).
123+
BGP-based IP sharing provides a more cost-effective solution for multiple LoadBalancer services. For detailed setup instructions, see [Cilium BGP Documentation](https://docs.cilium.io/en/stable/network/bgp-control-plane/bgp-control-plane/).
124124

125125
### Prerequisites
126-
- [Cilium CNI](https://docs.cilium.io/en/stable/network/bgp-control-plane/) with BGP control plane enabled
126+
- [Cilium CNI](https://docs.cilium.io/en/stable/network/bgp-control-plane/bgp-control-plane/) with BGP control plane enabled
127127
- Additional IP provisioning enabled on your account (contact [Linode Support](https://www.linode.com/support/))
128128
- Nodes labeled for BGP peering
129129

@@ -150,6 +150,27 @@ kubectl label node my-node cilium-bgp-peering=true
150150

151151
For more details, see [Environment Variables](environment.md#network-configuration).
152152

153+
## Configuring NodeBalancers directly with VPC
154+
NodeBalancers can be configured to have VPC specific ips configured as backend nodes. It requires:
155+
1. VPC with a subnet and Linodes in VPC
156+
2. Each NodeBalancer created within that VPC needs a free /30 or bigger subnet from the subnet to which Linodes are connected
157+
158+
Specify NodeBalancer backend ipv4 range when creating service:
159+
```yaml
160+
metadata:
161+
annotations:
162+
service.beta.kubernetes.io/linode-loadbalancer-backend-ipv4-range: "10.100.0.0/30"
163+
```
164+
165+
By default, CCM uses first VPC and Subnet name configured with it to attach NodeBalancers to that VPC subnet. To overwrite those, use:
166+
```yaml
167+
metadata:
168+
annotations:
169+
service.beta.kubernetes.io/linode-loadbalancer-backend-ipv4-range: "10.100.0.4/30"
170+
service.beta.kubernetes.io/linode-loadbalancer-vpc-name: "vpc1"
171+
service.beta.kubernetes.io/linode-loadbalancer-subnet-name: "subnet1"
172+
```
173+
153174
## Advanced Configuration
154175

155176
### Using Existing NodeBalancers
@@ -201,6 +222,6 @@ metadata:
201222
- [Environment Variables](environment.md)
202223
- [Route Configuration](routes.md)
203224
- [Linode NodeBalancer Documentation](https://www.linode.com/docs/products/networking/nodebalancers/)
204-
- [Cilium BGP Documentation](https://docs.cilium.io/en/stable/network/bgp-control-plane/)
225+
- [Cilium BGP Documentation](https://docs.cilium.io/en/stable/network/bgp-control-plane/bgp-control-plane/)
205226
- [Basic Service Examples](../examples/basic.md)
206227
- [Advanced Configuration Examples](../examples/advanced.md)

0 commit comments

Comments
 (0)