Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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

This comment has been minimized.

Copy link

goatmale commented Oct 4, 2019

Shouldn't the find logic use -e instead of -f? -f only checks for files and not directories.
http://tldp.org/LDP/abs/html/fto.html

@goatmale

This comment has been minimized.

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
You can’t perform that action at this time.