You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide demonstrates using a MetalLB service to expose the K3s API externally on an HA K3s cluster with three control-plane nodes.
14
+
This guide demonstrates using a MetalLB service to expose the RKE2/K3s API externally on an HA cluster with three control-plane nodes.
15
15
To achieve this, a Kubernetes Service of type `LoadBalancer` and Endpoints will be manually created. The Endpoints keep the IPs of all control plane nodes available in the cluster.
16
16
For the Endpoint to be continuously synchronized with the events occurring in the cluster (adding/removing a node or a node goes offline), the https://github.com/suse-edge/endpoint-copier-operator[Endpoint Copier Operator] will be deployed. The operator monitors the events happening in the default `kubernetes` Endpoint and updates the managed one automatically to keep them in sync.
17
17
Since the managed Service is of type `LoadBalancer`, `MetalLB` assigns it a static `ExternalIP`. This `ExternalIP` will be used to communicate with the API Server.
18
18
19
19
== Prerequisites
20
20
21
-
* Three hosts to deploy K3s on top.
21
+
* Three hosts to deploy RKE2/K3s on top.
22
22
** Ensure the hosts have different host names.
23
23
** For testing, these could be virtual machines
24
-
* At least 2 available IPs in the network (one for the Traefik and one for the managed service).
24
+
* At least 2 available IPs in the network (one for the Traefik/Nginx and one for the managed service).
25
25
* Helm
26
26
27
-
== Installing K3s
27
+
== Installing RKE2/K3s
28
28
29
29
[NOTE]
30
30
====
31
-
If you do not want a fresh cluster but want to use an existing one, skip this step and proceed to the next one.
31
+
If you do not want to use a fresh cluster but want to use an existing one, skip this step and proceed to the next one.
32
32
====
33
33
34
34
First, a free IP in the network must be reserved that will be used later for `ExternalIP` of the managed Service.
35
35
36
-
SSH to the first host and install `K3s` in cluster mode as:
36
+
SSH to the first host and install the wanted distribution in cluster mode.
This step is valid only if you intend to use an existing K3s cluster.
94
+
This step is valid only if you intend to use an existing RKE2/K3s cluster.
74
95
====
75
96
76
-
To use an existing K3s cluster, the `servicelb` LB should be disabled and also `tls-san` flags modified.
97
+
To use an existing cluster the `tls-san` flags should be modified and also, `servicelb` LB should be disabled for K3s.
77
98
78
-
To change the K3s flags, `/etc/systemd/system/k3s.service` should be modified on all the VMs in the cluster.
99
+
To change the flags for RKE2 or K3s servers, you need to modify either the `/etc/systemd/system/rke2.service` or `/etc/systemd/system/k3s.service` file on all the VMs in the cluster, depending on the distribution.
79
100
80
101
The flags should be inserted in the `ExecStart`. For example:
The command above will deploy three different resources in the cluster:
190
+
The command above will deploy the `endpoint-copier-operator` operator Deployment with two replicas. One will be the leader and the other will take over the leader role if needed.
191
+
192
+
Now, the `kubernetes-vip` Service should be deployed, which will be reconciled by the operator and an Endpoint with the configured ports and IP will be created.
193
+
194
+
For RKE2:
195
+
[,bash]
196
+
----
197
+
cat <<-EOF | kubectl apply -f -
198
+
apiVersion: v1
199
+
kind: Service
200
+
metadata:
201
+
name: kubernetes-vip
202
+
namespace: default
203
+
spec:
204
+
ports:
205
+
- name: rke2-api
206
+
port: 9345
207
+
protocol: TCP
208
+
targetPort: 9345
209
+
- name: k8s-api
210
+
port: 6443
211
+
protocol: TCP
212
+
targetPort: 6443
213
+
type: LoadBalancer
214
+
EOF
215
+
----
216
+
217
+
For K3s:
218
+
[,bash]
219
+
----
220
+
cat <<-EOF | kubectl apply -f -
221
+
apiVersion: v1
222
+
kind: Service
223
+
metadata:
224
+
name: kubernetes-vip
225
+
namespace: default
226
+
spec:
227
+
internalTrafficPolicy: Cluster
228
+
ipFamilies:
229
+
- IPv4
230
+
ipFamilyPolicy: SingleStack
231
+
ports:
232
+
- name: https
233
+
port: 443
234
+
protocol: TCP
235
+
targetPort: 6443
236
+
sessionAffinity: None
237
+
type: LoadBalancer
238
+
EOF
239
+
----
158
240
159
-
. The `endpoint-copier-operator` operator Deployment with two replicas. One will be the leader and the other will take over the leader role if needed.
160
-
. A Kubernetes service called `kubernetes-vip` in the `default` namespace that will be a copy of the `kubernetes` Service but from type `LoadBalancer`.
161
-
. An Endpoint resource called `kubernetes-vip` in the `default` namespace that will be a copy of the `kubernetes` Endpoint.
162
241
163
242
Verify that the `kubernetes-vip` Service has the correct IP address:
164
243
@@ -204,6 +283,27 @@ watch kubectl get endpoints
204
283
205
284
Now execute the commands below on the second and third nodes.
206
285
286
+
For RKE2:
287
+
[,bash]
288
+
----
289
+
# Export the VIP_SERVICE_IP in the VM
290
+
# Replace with the actual IP
291
+
export VIP_SERVICE_IP=<ip>
292
+
293
+
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="server" sh -
0 commit comments