From b4faabc0f1a76e49b1a6ce8dd8f7d4be5e016811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan-Luis=20de=20Sousa-Valadas=20Casta=C3=B1o?= Date: Thu, 2 Jan 2025 12:01:00 +0100 Subject: [PATCH] Allow to disable CPLB load balancer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is one of the remaining tasks of #5279. The intended use case for this is to allow to use the VIPs functionality while using some user provided load balancer such as HAProxy, nginx, etc... Also fixes some CPLB documentation mistakes spotted while fixing this. Signed-off-by: Juan-Luis de Sousa-Valadas CastaƱo --- docs/configuration.md | 10 ++++++---- pkg/apis/k0s/v1beta1/cplb.go | 7 +++++-- pkg/component/controller/cplb/cplb_linux.go | 3 ++- static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml | 7 +++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 9f32854b4765..bad8733568fb 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -318,10 +318,12 @@ Configuration options related to k0s's [control plane load balancing] feature Configuration options related to keepalived in [control plane load balancing] -| Element | Description | -| ---------------- | ----------------------------------------------------------------------------------------------------------- | -| `vrrpInstances` | Configuration options related to the VRRP. This is an array which allows to configure multiple virtual IPs. | -| `virtualServers` | Configuration options related LoadBalancing. This is an array which allows to configure multiple LBs. | +| Element | Description | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | +| `vrrpInstances` | Configuration options related to the VRRP. This is an array which allows to configure multiple virtual IPs. | +| `virtualServers` | Configuration options related LoadBalancing. This is an array which allows to configure multiple LBs. | +| `userSpaceProxyBindPort` | The port the userspace proxy will bind to. This port is for internal use only, but listens on every interface. Default: `6444` | +| `disableLoadBalancer` | Disables the load balancer. Default: `false` | ##### `spec.network.controlPlaneLoadBalancing.keepalived.vrrpInstances` diff --git a/pkg/apis/k0s/v1beta1/cplb.go b/pkg/apis/k0s/v1beta1/cplb.go index 4cbe55bf6a61..b36de59ba25a 100644 --- a/pkg/apis/k0s/v1beta1/cplb.go +++ b/pkg/apis/k0s/v1beta1/cplb.go @@ -68,13 +68,16 @@ type KeepalivedSpec struct { // which allows to configure multiple load balancers. VirtualServers VirtualServers `json:"virtualServers,omitempty"` // UserspaceProxyPort is the port where the userspace proxy will bind - // to. This port is only exposed on the localhost interface and is only - // used internally. Defaults to 6444. + // to. This port is only used internally, but listens on every interface. + // Defaults to 6444 // +kubebuilder:default=6444 // +kubebuilder:validation:Minimum=1 // +kubebuilder:validation:Maximum=65535 // +optional UserSpaceProxyPort int `json:"userSpaceProxyBindPort,omitempty"` + // DisableLoadBalancer disables the load balancer. + // +optional + DisableLoadBalancer bool `json:"disableLoadBalancer,omitempty"` } // VRRPInstances is a list of VRRPInstance diff --git a/pkg/component/controller/cplb/cplb_linux.go b/pkg/component/controller/cplb/cplb_linux.go index fd88df64ef58..6ab33317ebe8 100644 --- a/pkg/component/controller/cplb/cplb_linux.go +++ b/pkg/component/controller/cplb/cplb_linux.go @@ -100,7 +100,7 @@ func (k *Keepalived) Start(ctx context.Context) error { } } - if len(k.Config.VRRPInstances) > 0 || len(k.Config.VirtualServers) > 0 { + if !k.Config.DisableLoadBalancer && (len(k.Config.VRRPInstances) > 0 || len(k.Config.VirtualServers) > 0) { k.log.Info("Starting CPLB reconciler") updateCh := make(chan struct{}, 1) k.reconciler = NewCPLBReconciler(k.KubeConfigPath, updateCh) @@ -160,6 +160,7 @@ func (k *Keepalived) Start(ctx context.Context) error { } }() } + return k.supervisor.Supervise() } diff --git a/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml b/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml index d1d5f2ffd58f..13544d1e7a04 100644 --- a/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml +++ b/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml @@ -508,12 +508,15 @@ spec: Keepalived contains configuration options related to the "Keepalived" type of load balancing. properties: + disableLoadBalancer: + description: DisableLoadBalancer disables the load balancer. + type: boolean userSpaceProxyBindPort: default: 6444 description: |- UserspaceProxyPort is the port where the userspace proxy will bind - to. This port is only exposed on the localhost interface and is only - used internally. Defaults to 6444. + to. This port is only used internally, but listens on every interface. + Defaults to 6444 maximum: 65535 minimum: 1 type: integer