Skip to content

Commit

Permalink
add loadbalancer address allocator
Browse files Browse the repository at this point in the history
This adds a simple controller that will watch for services of type LoadBalancer
and try to allocated addresses from the specified IPv4 and/or IPv6 ranges.
It's assumed that kube-router (or another network controller) will announce the addresses.

As the controller uses leases for leader election and updates the service status new
RBAC permissions are required.
  • Loading branch information
whooo committed Jul 23, 2023
1 parent cbdcf31 commit c3a6ae6
Show file tree
Hide file tree
Showing 14 changed files with 1,338 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ linters:
issues:
exclude-rules:
# Excluding single digits from magic number detector because it produces too many obvious results (like klog)
- text: "Magic number: [0-9]{1},"
- text: "Magic number: [0-9]{1,2},"
linters:
- gomnd
# Exclude file masks from magic number detector because these numbers are obvious
Expand Down
14 changes: 14 additions & 0 deletions daemonset/generic-kuberouter-all-features-advertise-routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update

---
kind: ClusterRoleBinding
Expand Down
14 changes: 14 additions & 0 deletions daemonset/generic-kuberouter-all-features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
14 changes: 14 additions & 0 deletions daemonset/generic-kuberouter-only-advertise-routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update

---
kind: ClusterRoleBinding
Expand Down
14 changes: 14 additions & 0 deletions daemonset/generic-kuberouter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update

---
kind: ClusterRoleBinding
Expand Down
14 changes: 14 additions & 0 deletions daemonset/kubeadm-kuberouter-all-features-dsr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
14 changes: 14 additions & 0 deletions daemonset/kubeadm-kuberouter-all-features-hostport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
14 changes: 14 additions & 0 deletions daemonset/kubeadm-kuberouter-all-features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
14 changes: 14 additions & 0 deletions daemonset/kubeadm-kuberouter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ rules:
- get
- list
- watch
- apiGroups:
- "coordination.k8s.io"
resources:
- leases
verbs:
- get
- create
- update
- apiGroups:
- ""
resources:
- services/status
verbs:
- update
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
3 changes: 3 additions & 0 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Usage of kube-router:
--ipvs-permit-all Enables rule to accept all incoming traffic to service VIP's on the node. (default true)
--ipvs-sync-period duration The delay between ipvs config synchronizations (e.g. '5s', '1m', '2h22m'). Must be greater than 0. (default 5m0s)
--kubeconfig string Path to kubeconfig file with authorization information (the master location is set by the master flag).
--loadbalancer-default-class Handle loadbalancer services without a class (default true)
--loadbalancer-ip-range strings CIDR values from which loadbalancer services addresses are assigned
--masquerade-all SNAT all traffic to cluster IP/node port.
--master string The address of the Kubernetes API server (overrides any value in kubeconfig).
--metrics-path string Prometheus metrics path (default "/metrics")
Expand All @@ -113,6 +115,7 @@ Usage of kube-router:
--router-id string BGP router-id. Must be specified in a ipv6 only cluster, "generate" can be specified to generate the router id.
--routes-sync-period duration The delay between route updates and advertisements (e.g. '5s', '1m', '2h22m'). Must be greater than 0. (default 5m0s)
--run-firewall Enables Network Policy -- sets up iptables to provide ingress firewall for pods. (default true)
--run-loadbalancer Enable loadbalancer address allocator (default true)
--run-router Enables Pod Networking -- Advertises and learns the routes to Pods via iBGP. (default true)
--run-service-proxy Enables Service Proxy -- sets up IPVS for Kubernetes Services. (default true)
--runtime-endpoint string Path to CRI compatible container runtime socket (used for DSR mode). Currently known working with containerd.
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/kube-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"syscall"
"time"

"github.com/cloudnativelabs/kube-router/v2/pkg/controllers/lballoc"
"github.com/cloudnativelabs/kube-router/v2/pkg/controllers/netpol"
"github.com/cloudnativelabs/kube-router/v2/pkg/controllers/proxy"
"github.com/cloudnativelabs/kube-router/v2/pkg/controllers/routing"
Expand Down Expand Up @@ -204,6 +205,19 @@ func (kr *KubeRouter) Run() error {
go npc.Run(healthChan, stopCh, &wg)
}

if kr.Config.RunLoadBalancer {
klog.V(0).Info("running loadbalancer")
lbc, err := lballoc.NewLoadBalancerController(kr.Client, kr.Config, svcInformer)
if err != nil {
return errors.New("Failed to create loadbalancer controller: " + err.Error())
}

svcInformer.AddEventHandler(lbc)

wg.Add(1)
go lbc.Run(healthChan, stopCh, &wg)
}

// Handle SIGINT and SIGTERM
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
Expand Down
Loading

0 comments on commit c3a6ae6

Please sign in to comment.