Skip to content

Commit 7be6600

Browse files
authoredJan 29, 2025··
Merge pull request #297 from lukapetrovic-git/main
Added option to configure KubeletConfiguration
2 parents e3cfef0 + e78e62f commit 7be6600

File tree

7 files changed

+54
-5
lines changed

7 files changed

+54
-5
lines changed
 

‎README.md

+10
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ rke2_wait_for_all_pods_to_be_ready: false
325325
# Enable debug mode (rke2-service)
326326
rke2_debug: false
327327

328+
# (Optional) Customize kubelet config using KubeletConfiguration - https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/
329+
# rke2_kubelet_config:
330+
# imageGCHighThresholdPercent: 80
331+
# imageGCLowThresholdPercent: 70
332+
# Note that you also need to add the following to kubelet args:
333+
# rke2_kubelet_arg:
334+
# - "--config=/etc/rancher/rke2/kubelet-config.yaml"
335+
rke2_kubelet_config: {}
336+
328337
# (Optional) Customize default kubelet arguments
329338
# rke2_kubelet_arg:
330339
# - "--system-reserved=cpu=100m,memory=100Mi"
@@ -346,6 +355,7 @@ rke2_service_cidr:
346355

347356
# Enable SELinux for rke2
348357
rke2_selinux: false
358+
349359
```
350360
351361
## Inventory file example

‎defaults/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ rke2_wait_for_all_pods_to_be_ready: false
287287
# Enable debug mode (rke2-service)
288288
rke2_debug: false
289289

290+
# (Optional) Customize kubelet config using KubeletConfiguration - https://kubernetes.io/docs/reference/config-api/kubelet-config.v1beta1/
291+
# rke2_kubelet_config:
292+
# imageGCHighThresholdPercent: 80
293+
# imageGCLowThresholdPercent: 70
294+
# Note that you also need to add the following to kubelet args:
295+
# rke2_kubelet_arg:
296+
# - "--config=/etc/rancher/rke2/kubelet-config.yaml"
297+
rke2_kubelet_config: {}
298+
290299
# (Optional) Customize default kubelet arguments
291300
# rke2_kubelet_arg:
292301
# - "--system-reserved=cpu=100m,memory=100Mi"

‎tasks/first_server.yml

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
mode: 0600
2222
notify: "Config file changed"
2323

24+
- name: Copy kubelet config
25+
ansible.builtin.template:
26+
src: templates/kubelet-config.yaml.j2
27+
dest: /etc/rancher/rke2/kubelet-config.yaml
28+
owner: root
29+
group: root
30+
mode: 0600
31+
when: rke2_kubelet_config | length > 0
32+
notify: "Config file changed"
33+
2434
- name: Copy Containerd Registry Configuration file
2535
ansible.builtin.template:
2636
src: "{{ rke2_custom_registry_path }}"

‎tasks/main.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: Install Keepalived when HA mode is enabled
43
ansible.builtin.include_tasks: keepalived.yml
54
when:
@@ -31,7 +30,6 @@
3130
- rke2_ha_mode_kubevip | bool
3231
- not rke2_ha_mode_keepalived | bool
3332

34-
3533
- name: Copy kube-vip manifests to the masternode
3634
ansible.builtin.include_tasks: kubevip.yml
3735
when:

‎tasks/remaining_nodes.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
32
- name: Create the RKE2 config dir
43
ansible.builtin.file:
54
state: directory
@@ -27,6 +26,16 @@
2726
mode: 0600
2827
notify: "Config file changed"
2928

29+
- name: Copy kubelet config
30+
ansible.builtin.template:
31+
src: templates/kubelet-config.yaml.j2
32+
dest: /etc/rancher/rke2/kubelet-config.yaml
33+
owner: root
34+
group: root
35+
mode: 0600
36+
when: rke2_kubelet_config | length > 0
37+
notify: "Config file changed"
38+
3039
- name: Copy Containerd Registry Configuration file
3140
ansible.builtin.template:
3241
src: "{{ rke2_custom_registry_path }}"
@@ -85,8 +94,7 @@
8594
executable: /bin/bash
8695
changed_when: false
8796
register: all_ready_nodes
88-
until:
89-
"groups[rke2_cluster_group_name] | length == all_ready_nodes.stdout | int"
97+
until: "groups[rke2_cluster_group_name] | length == all_ready_nodes.stdout | int"
9098
retries: 100
9199
delay: 15
92100
when:

‎tasks/standalone.yml

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
mode: 0600
1818
notify: "Config file changed"
1919

20+
- name: Copy kubelet config
21+
ansible.builtin.template:
22+
src: templates/kubelet-config.yaml.j2
23+
dest: /etc/rancher/rke2/kubelet-config.yaml
24+
owner: root
25+
group: root
26+
mode: 0600
27+
when: rke2_kubelet_config | length > 0
28+
notify: "Config file changed"
29+
2030
- name: Copy Containerd Registry Configuration file
2131
ansible.builtin.template:
2232
src: "{{ rke2_custom_registry_path }}"

‎templates/kubelet-config.yaml.j2

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
apiVersion: kubelet.config.k8s.io/v1beta1
3+
kind: KubeletConfiguration
4+
{{ rke2_kubelet_config | to_nice_yaml(indent=2) }}

0 commit comments

Comments
 (0)