Skip to content

Instantly share code, notes, and snippets.

@reaperes
Created March 13, 2019 03:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save reaperes/34ed7b07344ccc61b9570c46a3b4e564 to your computer and use it in GitHub Desktop.
Save reaperes/34ed7b07344ccc61b9570c46a3b4e564 to your computer and use it in GitHub Desktop.
# It locates on /etc/systemd/system/
[Unit]
Description=Cleaning unnecessary cadvisor system resources. See issue https://github.com/kubernetes/kubernetes/issues/64137.
[Service]
Slice=cadvisor-gc.slice
ExecStart=/opt/cadvisor-gc/cadvisor-gc.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
# It locates on /opt/cadvisor-gc/
count=0
increaseCount() {
count=$((count + 1))
}
for i in $(ls /sys/fs/cgroup/systemd/system.slice | grep "^run-r"); do
pod=$(systemctl list-units --type scope --state running $i | cat | sed -n 's/\(.*\)Kubernetes transient mount for \/var\/lib\/kubelet\/pods\/\(.*\)\/volumes\(.*\)/\2/p')
if [ ! -f "/var/lib/kubelet/pods/'$pod'" ]; then
echo -n "Try to stop '$i' systemd scope... "
systemctl stop $i
echo "Stopped."
increaseCount
fi
done
echo -e "==========\nTotal ${count} systemd scope stopped."
# It locates on /etc/systemd/system/
[Unit]
Description=Limited resources Slice
DefaultDependencies=no
Before=slices.target
[Slice]
CPUQuota=5%
MemoryLimit=0.1G
# It locates on /etc/systemd/system/
[Unit]
Description=Run cadvisor-gc every day
[Timer]
Unit=cadvisor-gc.service
OnCalendar=*-*-* 16:00:00
[Install]
WantedBy=timers.target
@goatmale
Copy link

goatmale commented Oct 7, 2019

Also, I believe the single quotes around $pod break the validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment