Skip to content

Commit 9d7831c

Browse files
authored
Merge pull request #4290 from twz123/keepalived-enabled
Introduce controlPlaneLoadBalancing.enabled
2 parents 408ce03 + 739dbac commit 9d7831c

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

cmd/controller/controller.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,14 @@ func (c *command) start(ctx context.Context) error {
228228
nodeComponents.Add(ctx, controllerLeaseCounter)
229229
}
230230

231-
enableCPLB := !c.SingleNode && !slices.Contains(c.DisableComponents, constant.CPLBComponentName)
232-
if enableCPLB {
231+
if cplb := nodeConfig.Spec.Network.ControlPlaneLoadBalancing; cplb != nil && cplb.Enabled {
232+
if c.SingleNode {
233+
return errors.New("control plane load balancing cannot be used in a single-node cluster")
234+
}
235+
233236
nodeComponents.Add(ctx, &controller.Keepalived{
234237
K0sVars: c.K0sVars,
235-
Config: nodeConfig.Spec.Network.ControlPlaneLoadBalancing,
238+
Config: cplb,
236239
DetailedLogging: c.Debug,
237240
})
238241
}

docs/configuration.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,10 @@ node-local load balancing.
304304
305305
Configuration options related to k0s's [control plane load balancing] feature
306306

307-
| Element | Description |
308-
| --------------- | ---------------------------------------------------------------------------------------------------------- |
309-
| `vrrpInstances` | Configuration options related to the VRRP. This is an array which allows to configure multiple virtual IPs |
307+
| Element | Description |
308+
| --------------- | ----------------------------------------------------------------------------------------------------------- |
309+
| `enabled` | Indicates if control plane load balancing should be enabled. Default: `false`. |
310+
| `vrrpInstances` | Configuration options related to the VRRP. This is an array which allows to configure multiple virtual IPs. |
310311

311312
[control plane load balancing]: cplb.md
312313

@@ -316,7 +317,7 @@ Configuration options required for using VRRP to configure VIPs in control plane
316317

317318
| Element | Description |
318319
| ----------------- | ----------------------------------------------------------------------------------------------------------------- |
319-
| `name` | The name of the VRRP instance. If omitted it generates a predictive name shared across all nodes. |
320+
| `name` | The name of the VRRP instance. If omitted it generates a predictive name shared across all nodes. |
320321
| `virtualIPs` | A list of the CIDRs handled by the VRRP instance. |
321322
| `interface` | The interface used by each VRRPInstance. If undefined k0s will try to auto detect it based on the default gateway |
322323
| `virtualRouterId` | Virtual router ID for the instance. Default: `51` |

docs/cplb.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ spec:
5555
externalAddress: <External address> # This isn't a requirement, but it's a common use case.
5656
network:
5757
controlPlaneLoadBalancing:
58+
enabled: true
5859
vrrpInstances:
5960
- virtualIPs: ["<External address IP>/<external address IP netmask"]
6061
authPass: <password>
@@ -72,6 +73,7 @@ spec:
7273
externalAddress: <External address> # This isn't a requirement, but it's a common use case.
7374
network:
7475
controlPlaneLoadBalancing:
76+
enabled: true
7577
vrrpInstances:
7678
- virtualIPs: ["<External address IP>/<external address IP netmask>"]
7779
authPass: <password>
@@ -143,6 +145,7 @@ spec:
143145
externalAddress: 192.168.122.200
144146
network:
145147
controlPlaneLoadBalancing:
148+
enabled: true
146149
vrrpInstances:
147150
- virtualIPs: ["192.168.122.200/24"]
148151
authPass: Example
@@ -274,9 +277,9 @@ All three worker nodes are ready:
274277
```console
275278
$ kubectl get nodes
276279
NAME STATUS ROLES AGE VERSION
277-
worker-0.k0s.lab Ready <none> 8m51s v1.29.2+k0s
278-
worker-1.k0s.lab Ready <none> 8m51s v1.29.2+k0s
279-
worker-2.k0s.lab Ready <none> 8m51s v1.29.2+k0s
280+
worker-0.k0s.lab Ready <none> 8m51s v{{{ extra.k8s_version }}}+k0s
281+
worker-1.k0s.lab Ready <none> 8m51s v{{{ extra.k8s_version }}}+k0s
282+
worker-2.k0s.lab Ready <none> 8m51s v{{{ extra.k8s_version }}}+k0s
280283
```
281284

282285
Each controller node has a dummy interface with the VIP and /32 netmask,
@@ -323,7 +326,7 @@ And the cluster will be working normally:
323326
```console
324327
$ kubectl get nodes
325328
NAME STATUS ROLES AGE VERSION
326-
worker-0.k0s.lab Ready <none> 8m51s v1.29.2+k0s
327-
worker-1.k0s.lab Ready <none> 8m51s v1.29.2+k0s
328-
worker-2.k0s.lab Ready <none> 8m51s v1.29.2+k0s
329-
```
329+
worker-0.k0s.lab Ready <none> 8m51s v{{{ extra.k8s_version }}}+k0s
330+
worker-1.k0s.lab Ready <none> 8m51s v{{{ extra.k8s_version }}}+k0s
331+
worker-2.k0s.lab Ready <none> 8m51s v{{{ extra.k8s_version }}}+k0s
332+
```

inttest/cplb/cplb_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ spec:
3737
externalAddress: %s
3838
network:
3939
controlPlaneLoadBalancing:
40+
enabled: true
4041
vrrpInstances:
4142
- virtualIPs: ["%s/24"]
4243
authPass: "123456"

pkg/apis/k0s/v1beta1/cplb.go

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ const defaultAdvertInterval = 1
2929
// ControlPlaneLoadBalancingSpec defines the configuration options related to k0s's
3030
// keepalived feature.
3131
type ControlPlaneLoadBalancingSpec struct {
32+
// Indicates if control plane load balancing should be enabled.
33+
// Default: false
34+
// +optional
35+
Enabled bool `json:"enabled,omitempty"`
36+
37+
// Configuration options related to the VRRP. This is an array which allows
38+
// to configure multiple virtual IPs.
3239
VRRPInstances VRRPInstances `json:"vrrpInstances,omitempty"`
3340
}
3441

pkg/constant/constant.go

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ const (
110110
CoreDNSComponentname = "coredns"
111111
CsrApproverComponentName = "csr-approver"
112112
HelmComponentName = "helm"
113-
CPLBComponentName = "cplb"
114113
KonnectivityServerComponentName = "konnectivity-server"
115114
KubeControllerManagerComponentName = "kube-controller-manager"
116115
KubeProxyComponentName = "kube-proxy"

static/manifests/v1beta1/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,15 @@ spec:
367367
ControlPlaneLoadBalancing defines the configuration options related to k0s's
368368
control plane load balancing feature.
369369
properties:
370+
enabled:
371+
description: |-
372+
Indicates if control plane load balancing should be enabled.
373+
Default: false
374+
type: boolean
370375
vrrpInstances:
371-
description: VRRPInstances is a list of VRRPInstance
376+
description: |-
377+
Configuration options related to the VRRP. This is an array which allows
378+
to configure multiple virtual IPs.
372379
items:
373380
description: VRRPInstance defines the configuration options
374381
for a VRRP instance.

0 commit comments

Comments
 (0)