Skip to content

Commit

Permalink
add auto_calculation for system_reserved resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Payback159 committed Jan 22, 2024
1 parent 89d42a7 commit 91a1645
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions inventory/sample/group_vars/k8s_cluster/k8s-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ default_kubelet_config_dir: "{{ kube_config_dir }}/dynamic_kubelet_dir"
## The following two items need to be set when system_reserved is true
# system_reserved_cgroups_for_service_slice: system.slice
# system_reserved_cgroups: "/{{ system_reserved_cgroups_for_service_slice }}"
# If systemd_reserved_auto_calculate is true,
# system_[master]_memory_reserved and system_[master]_cpu_reserved will be calculated
# based on the number of CPUs and memory size of the host
# cpu_reserved is calculated as 1% of the number of CPUs + 80m
# memory_reserved is calculated as 5% of the memory size + 330Mi
#system_reserved_auto_calculate: false
# else you can set the values manually
# Reservation for node hosts
# system_memory_reserved: 512Mi
# system_cpu_reserved: 500m
# system_ephemeral_storage_reserved: 2Gi
Expand Down
5 changes: 5 additions & 0 deletions roles/kubernetes/node/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ kube_master_cpu_reserved: 200m

# Set to true to reserve resources for system daemons
system_reserved: false
# If true, system_[master]_memory_reserved and system_[master]_cpu_reserved will be calculated
# based on the number of CPUs and memory size of the host
# cpu_reserved is calculated as 1% of the number of CPUs + 80m
# memory_reserved is calculated as 5% of the memory size + 330Mi
system_reserved_auto_calculate: false
system_reserved_cgroups_for_service_slice: system.slice
system_reserved_cgroups: "/{{ system_reserved_cgroups_for_service_slice }}"
system_memory_reserved: 512Mi
Expand Down
29 changes: 29 additions & 0 deletions roles/kubernetes/node/tasks/kubelet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@
- kubelet
- kubeadm

- name: Gather facts about the node
setup:
filter: ansible_memtotal_mb,ansible_processor_vcpus
tags:
- kubelet
- kubeadm

- name: Check if system_reserved_auto_calculate is set
set_fact:
system_master_cpu_reserved: "{{ (ansible_processor_vcpus * 1000 * 0.01) | int + 80 }}m"
system_master_memory_reserved: "{{ (ansible_memtotal_mb * 0.05) | int + 330 }}Mi"
tags:
- kubelet
- kubeadm
when:
- system_reserved_auto_calculate == true
- is_kube_master == true

- name: Check if system_reserved_auto_calculate is set
set_fact:
system_cpu_reserved: "{{ (ansible_processor_vcpus * 1000 * 0.01) | int + 80 }}m"
system_memory_reserved: "{{ (ansible_memtotal_mb * 0.05) | int + 330 }}Mi"
tags:
- kubelet
- kubeadm
when:
- system_reserved_auto_calculate == true
- is_kube_master == false

- name: Write kubelet config file
template:
src: "kubelet-config.{{ kubeletConfig_api_version }}.yaml.j2"
Expand Down

0 comments on commit 91a1645

Please sign in to comment.