From 1edb1595598a9c2cbc4120a47eafd7ae2f273e9c Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Thu, 4 Jan 2024 07:50:32 -0500 Subject: [PATCH] feat: replace stale-containers systemd timer with kubelet-args Signed-off-by: Devin Buhl --- .../inventory/group_vars/master/main.yaml.j2 | 4 +++ .../inventory/group_vars/worker/main.yaml.j2 | 4 +++ .../playbooks/cluster-installation.yaml.j2 | 5 --- .../ansible/playbooks/cluster-nuke.yaml.j2 | 5 --- .../files/stale-containers.service.j2 | 6 ---- .../playbooks/files/stale-containers.timer.j2 | 11 ------ .../playbooks/tasks/stale_containers.yaml.j2 | 36 ------------------- 7 files changed, 8 insertions(+), 63 deletions(-) delete mode 100644 bootstrap/templates/ansible/playbooks/files/stale-containers.service.j2 delete mode 100644 bootstrap/templates/ansible/playbooks/files/stale-containers.timer.j2 delete mode 100644 bootstrap/templates/ansible/playbooks/tasks/stale_containers.yaml.j2 diff --git a/bootstrap/templates/ansible/inventory/group_vars/master/main.yaml.j2 b/bootstrap/templates/ansible/inventory/group_vars/master/main.yaml.j2 index a2739b91..777bfdba 100644 --- a/bootstrap/templates/ansible/inventory/group_vars/master/main.yaml.j2 +++ b/bootstrap/templates/ansible/inventory/group_vars/master/main.yaml.j2 @@ -41,3 +41,7 @@ k3s_server: - "bind-address=0.0.0.0" # Required to monitor kube-scheduler with kube-prometheus-stack kube-apiserver-arg: - "anonymous-auth=true" # Required for HAProxy health-checks + # TODO: Move these options to a kubelet config file + kubelet-arg: + - "image-gc-high-threshold=55" + - "image-gc-low-threshold=50" diff --git a/bootstrap/templates/ansible/inventory/group_vars/worker/main.yaml.j2 b/bootstrap/templates/ansible/inventory/group_vars/worker/main.yaml.j2 index 238815c7..bfeb76c7 100644 --- a/bootstrap/templates/ansible/inventory/group_vars/worker/main.yaml.j2 +++ b/bootstrap/templates/ansible/inventory/group_vars/worker/main.yaml.j2 @@ -11,3 +11,7 @@ k3s_agent: node-ip: "{% raw %}{{ ansible_host }}{% endraw %}" {% endif %} pause-image: registry.k8s.io/pause:3.9 + # TODO: Move these options to a kubelet config file + kubelet-arg: + - "image-gc-high-threshold=55" + - "image-gc-low-threshold=50" diff --git a/bootstrap/templates/ansible/playbooks/cluster-installation.yaml.j2 b/bootstrap/templates/ansible/playbooks/cluster-installation.yaml.j2 index df08d332..3b457337 100644 --- a/bootstrap/templates/ansible/playbooks/cluster-installation.yaml.j2 +++ b/bootstrap/templates/ansible/playbooks/cluster-installation.yaml.j2 @@ -68,8 +68,3 @@ - name: Cruft when: k3s_primary_control_node ansible.builtin.include_tasks: tasks/cruft.yaml - - - name: Stale Containers - ansible.builtin.include_tasks: tasks/stale_containers.yaml - vars: - stale_containers_state: enabled diff --git a/bootstrap/templates/ansible/playbooks/cluster-nuke.yaml.j2 b/bootstrap/templates/ansible/playbooks/cluster-nuke.yaml.j2 index 972574e8..912dc066 100644 --- a/bootstrap/templates/ansible/playbooks/cluster-nuke.yaml.j2 +++ b/bootstrap/templates/ansible/playbooks/cluster-nuke.yaml.j2 @@ -90,11 +90,6 @@ state: absent loop: ["kubectl", "crictl", "ctr"] - - name: Stale Containers - ansible.builtin.include_tasks: tasks/stale_containers.yaml - vars: - stale_containers_state: disabled - - name: Reboot ansible.builtin.reboot: msg: Rebooting nodes diff --git a/bootstrap/templates/ansible/playbooks/files/stale-containers.service.j2 b/bootstrap/templates/ansible/playbooks/files/stale-containers.service.j2 deleted file mode 100644 index 5136df2f..00000000 --- a/bootstrap/templates/ansible/playbooks/files/stale-containers.service.j2 +++ /dev/null @@ -1,6 +0,0 @@ -[Unit] -Description=Stale containers - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/k3s crictl rmi --prune diff --git a/bootstrap/templates/ansible/playbooks/files/stale-containers.timer.j2 b/bootstrap/templates/ansible/playbooks/files/stale-containers.timer.j2 deleted file mode 100644 index 731885a1..00000000 --- a/bootstrap/templates/ansible/playbooks/files/stale-containers.timer.j2 +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Stale containers - -[Timer] -OnCalendar=weekly -AccuracySec=1h -Persistent=true -RandomizedDelaySec=6000 - -[Install] -WantedBy=timers.target diff --git a/bootstrap/templates/ansible/playbooks/tasks/stale_containers.yaml.j2 b/bootstrap/templates/ansible/playbooks/tasks/stale_containers.yaml.j2 deleted file mode 100644 index 9857d6bc..00000000 --- a/bootstrap/templates/ansible/playbooks/tasks/stale_containers.yaml.j2 +++ /dev/null @@ -1,36 +0,0 @@ ---- -# https://github.com/k3s-io/k3s/issues/1900 -- name: Enabled Stale containers - when: stale_containers_state == "enabled" - block: - - name: Stale containers | Create systemd unit - ansible.builtin.copy: - src: files/stale-containers.service - dest: /etc/systemd/system/stale-containers.service - owner: root - group: root - mode: "0644" - - - name: Stale containers | Create systemd timer - ansible.builtin.copy: - src: files/stale-containers.timer - dest: /etc/systemd/system/stale-containers.timer - owner: root - group: root - mode: "0644" - - - name: Stale containers | Start the systemd timer - ansible.builtin.systemd: - name: stale-containers.timer - enabled: true - daemon_reload: true - masked: false - state: started - -- name: Disable Stale containers - when: stale_containers_state == "disabled" - block: - - name: Stale containers | Mask the systemd timer - ansible.builtin.systemd: - name: stale-containers.timer - masked: true